20.3k views
5 votes
Write in ARM assembly Language. Write a series of instructions that will multiply two integers under the assumption that the second operand is less than or equal to #7 (i.e. requires no more than 3 bits to represent) using only MOV, TST, ADDNE, and LSL operations. Store the operands in R1 and R2 and the result in R0. Since there is no easy way to get user input, work with example values for your operands, e.g. #26 and #5. Modify your program to accept a 16 bit second operand. Use additional registers as needed.

User Suenda
by
8.4k points

1 Answer

0 votes

Final answer:

The series of instructions in ARM assembly language to multiply two integers, where the second operand is less than or equal to #7, using only MOV, TST, ADDNE, and LSL operations.

Step-by-step explanation:

The series of instructions in ARM assembly language to multiply two integers, where the second operand is less than or equal to #7, using only MOV, TST, ADDNE, and LSL operations are:

  1. MOV R0, #0 ; Initialize R0 to 0
  2. LSL R2, R2 #2 ; Multiply R2 by 4 to adjust for the 3-bit representation
  3. MOV R3, #0 ; Initialize R3 to 0
  4. MOV R4, #0 ; Initialize R4 to 0
  5. TST R2, #4 ; Check if R2 has its most significant bit set
  6. ADDNE R0, R1, R0 ; Add R1 to R0 if the most significant bit of R2 is set
  7. ADDNE R3, R1, R3 ; Add R1 to R3 if the most significant bit of R2 is set
  8. LSR R1, R1, #1 ; Right-shift R1 by one bit
  9. LSR R2, R2, #1 ; Right-shift R2 by one bit
  10. ADDNE R4, R1, R4 ; Add R1 to R4 if the most significant bit of R2 is set
  11. LSL R1, R1, #1 ; Left-shift R1 by one bit
  12. BNE .-8 ; Loop back if R2 is not equal to 0

In this example, we are multiplying 26 and 5. The result will be stored in R0.

User Jonatan Anauati
by
7.8k points