Difference between revisions of "Assembly Language Multiplication"
Line 1: | Line 1: | ||
− | 1 | + | 1 MOV R0, #2 |
− | 2 | + | 2 MOV R1, #4 |
3 MOV R2,#0 | 3 MOV R2,#0 | ||
4 LOOP:ADD R2,R2,R0 | 4 LOOP:ADD R2,R2,R0 | ||
Line 7: | Line 7: | ||
7 BGT LOOP | 7 BGT LOOP | ||
8 B END | 8 B END | ||
− | 9 END: | + | 9 END: HALT |
− | |||
Line 1 & 2 will get the two numbers to multiply. | Line 1 & 2 will get the two numbers to multiply. | ||
Line 24: | Line 23: | ||
Line 8 will only be reached if the branch greater than above is false. This line just branches to the end. | Line 8 will only be reached if the branch greater than above is false. This line just branches to the end. | ||
− | Line 9 is the end label and | + | Line 9 is the end label and will halt. |
− | |||
− |
Latest revision as of 12:13, 21 January 2020
1 MOV R0, #2 2 MOV R1, #4 3 MOV R2,#0 4 LOOP:ADD R2,R2,R0 5 SUB R1,R1,#1 6 CMP R1,#0 7 BGT LOOP 8 B END 9 END: HALT
Line 1 & 2 will get the two numbers to multiply.
Line 3 will make sure register 2 is already set to zero.
Line 4 contains the label to branch back to, it will also add the second number to the value already in register 2
Line 5 will minus 1 from the second number, so we know how many times to run the loop.
Line 6 compares the value in register 1 with zero.
Line 7 if the compare result is greater than, we branch to the loop label.
Line 8 will only be reached if the branch greater than above is false. This line just branches to the end.
Line 9 is the end label and will halt.