Machine Language Computer Simulator
Assembly Language Assignment Put the 2 numbers you want added into memory location 7 and 8. This code will add them together and store the result in loc #9
Basic Add code:
Load r0 7
Load r1 8
Add r2 r0 r1
Store 9 r2
Halt
Challenge:
add 3 numbers, the one stored in memory location 6, 7, and 8.
Store answer in location 9
Branching Example: Add all the numbers between 1 and ???
Put a 1 in location 10 and a 0 in locations 11 and 12.
Location 10 will be the amount you count by
Location 11 will be the total sum
Location 12 will be the next number to add:
LOAD R3 10
LOAD R0 11
LOAD R1 12
ADD R2 R0 R1
STORE 11 R2
ADD R1 R1 R3
STORE 12 R1
BRANCH 1
Teaching the computer to multiply
Put 1 in location 31, used for decrementing
Put one number to multiply in location 30
Put the other number to multiply in location 29
Enter the folowing code:
Load r0 29
Add r2 r0 r2
Load r0 30
Load r1 31
Sub r3 r0 r1
Bzero 10
Store 30 r3
Load r0 29
Add r2 r0 r2
Branch 2
Store 28 r2
Halt
XC Assignment: Teach the computer to divide:
Put the larger number in 29 and the smaller in 30. Only use ones that divide in evenly.