Assembly Language Multiplication

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
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.