1. Put a value (say 6) into R0, Put a value (say 5) into R1. This program will put the sum of R0 and R1 into R3. You will have to manually put 2 numbers into the registers and make sure to reset the PC. (program counter, or our statement ptr)
ADD R3 R0 R1
2. Put a value manually into memory location 10 and 11. This program will add these 2 numbers and put the answer into memory location 12
*** See if you can change this program to subtract 2 numbers.
*** See if you can change this program to add 3 numbers you put into memory locations 10,11, and 12. Store your answer in Memory loc. 13
3. BRANCHING:: What if you wanted to add this sequence: 1 + 2 + 3 + 4 + 5 + ..........
This assembly language program will do this. Reset our program counter. Put a 1 in R0, and make sure you have 0 in R1, R2, and R3. Enter and execute this program
ADD R1 R1 R0 ADD R3 R2 R1 MOVE R2 R3 BRANCH 0
This program will never stop. You must halt it, but look what it does. See if you can make a change so it adds 2 + 4 + 6 + 8..... (no change in the program,, just to a register initial value)
CHALLENGE: See if you can have it find fibonacci numbers- 1,1,2,3,5,8,13...... find the next by adding the previous 2 numbers.. start at 1,1 (1+1=2, 2+1=3, 3+2=5, 5+3=8...)
Control the loop. Try this program. Put 0 into the registers. Reset the PC. Put a 1 into memory location 10. Put a 5 onto memory location 11, Put a 7 into memory location 12. Now enter this program into memory locations 0-9. Make sure you have selected INST on the View As box in main memory:
Load R0 10 Load R1 11 Load R2 12 Add R3 R2 R2 Store 12 R3 SUB R1 R1 R0 BZERO 8 BRANCH 2 STORE 15 R3 HALT
This program will double 7 (the value you put into loc 12) 5 times (the value in loc 11) See if you can get this to work.
See if you can get it to double 4 ten times.. ie 4,8,16,32..... answer is 4096
CHALLENGE:
1. Average the numbers stored in memory locations 10, 11, and 12
|