Difference between revisions of "Assembly Language Multiplication"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with " INP R0,2 INP R1,2 MOV R2,#0 LOOP: ADD R2,R2,R0 SUB R1,R1,#1 CMP R1,#0 BGT LOOP B END END: OUT R2,4 HALT")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
      INP R0,2
+
1      MOV R0, #2
      INP R1,2
+
2      MOV R1, #4
      MOV R2,#0
+
3      MOV R2,#0
  LOOP: ADD R2,R2,R0
+
  4 LOOP:ADD R2,R2,R0
      SUB R1,R1,#1
+
5      SUB R1,R1,#1
      CMP R1,#0
+
6      CMP R1,#0
      BGT LOOP
+
7      BGT LOOP
      B END
+
8      B END
  END: OUT R2,4
+
  9 END: HALT
      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.

Latest revision as of 13: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.