208k views
3 votes
1. Write a procedure called Power that will calculate integer powers of integer numbers. In other words, it will calculate xy given that both x and y are integers. 2. Write a program that will call Power to calculate xy on two numbers stored in appropriate registers. The answer should be placed in an appropriate register. 3. Comment your code appropriately and turn it in with evidence you ran the code (such as a readable screenshot). Also remember to comment on your usage of ARM Assembly Language simulators, what worked and what didn’t. Did you find one not listed that worked well?

1 Answer

3 votes

Final answer:

The part 1,2,3 of the question is answered below:

Power: MOV R2, R0 ; store the base number
MOV R3, R1 ; store the exponent
MOV R4, #1 ; initialize the result to 1

Loop: CMP R3, #0 ; check if exponent is 0
BEQ Done ; if so, exit the loop

MUL R4, R4, R2 ; multiply result by base
SUB R3, R3, #1 ; decrement exponent
B Loop ; repeat the loop

Done: MOV R0, R4 ; move the result to the appropriate register
BX LR ; return from the procedure.

Step-by-step explanation:

To calculate integer powers of integer numbers, you can write a procedure in ARM Assembly Language.

Here's the answer:

Power: MOV R2, R0 ; store the base number
MOV R3, R1 ; store the exponent
MOV R4, #1 ; initialize the result to 1

Loop: CMP R3, #0 ; check if exponent is 0
BEQ Done ; if so, exit the loop

MUL R4, R4, R2 ; multiply result by base
SUB R3, R3, #1 ; decrement exponent
B Loop ; repeat the loop

Done: MOV R0, R4 ; move the result to the appropriate register
BX LR ; return from the procedure.
User BarryBostwick
by
8.1k points