Assembly Language Multiplication

From TRCCompSci - AQA Computer Science
Revision as of 10:02, 14 January 2019 by Admin (talk | contribs)
Jump to: navigation, search
1      INP R0,2
2      INP R1,2
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:  OUT R2,4
10     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 also output the answer of the multiplication.

Line 10 will halt.