Difference between revisions of "Assembly Language Logical Shift"
Line 1: | Line 1: | ||
− | This example uses a Logical Shift to perform multiplication. | + | This example uses a Logical Shift to perform multiplication. A Logical Shift Left will shift the binary pattern and add a zero at the least significant place value. For example the binary for 4 is '00100' a logical shift to the left of one place will give '01000' which is now 8. A logical shift to the left will multiply by 2. A logical shift of 2 places on '00100' will give '10000' which is 16. |
+ | |||
+ | ==Multiplication example== | ||
INP R0,2 | INP R0,2 |
Revision as of 11:51, 15 January 2019
This example uses a Logical Shift to perform multiplication. A Logical Shift Left will shift the binary pattern and add a zero at the least significant place value. For example the binary for 4 is '00100' a logical shift to the left of one place will give '01000' which is now 8. A logical shift to the left will multiply by 2. A logical shift of 2 places on '00100' will give '10000' which is 16.
Multiplication example
INP R0,2 INP R1,2 MOV R2, R1 MOV R3, R0 LOOP: LSL R3,R3,#1 SUB R2,R2,#2 CMP R2,#1 BGT LOOP BLT END ADD R3,R3,R0 END: OUT R3,4 HALT