if statement translation
Using ARM assembly language, initialize the variables a, b, and c to consecutive integers starting at 1. Create your code so that a is in R0, b is in R1, and c is in R2.
Build the following if statements, using the ARM Cortex-M0 instructions, in sequence in your code. Please put both if statement implementations in one file.
Send me your .s file for grading.
if a == 1
b = b * 4 + 2
if a <= b
b = c + 4
return b // make sure the return value ends up in R0
Solution ::
MOV R0, #1; R0 is a Assigning the value 1 to
R0(c)
MOV R1, #2; R1 is b Assigning the value 2 to
R1(c)
MOV R3, #3; R2 is c Assigning the value 3 to
R2(c)
CMP R0, #1 Comparing the values of R0(a) and 1
BEQ isEqual Checking if R0 is equal to 1
MLA R0, R0, #4, #2 Multiply R0(a) and 4 and add it to 2, store the value in R0(a)
CMP R0, R1 Comparing R0(a) and R1(b)
BLE.R0 Checking if R0<=R1
ADD R1, R2, #4 Adding R2(c) and 4, storing the value in R1(b)
MOV R0, R1 I am assigning the value of R1(b) to R1(a), so that value gets returned in R0
RET R0
Thank you::::
Get Answers For Free
Most questions answered within 1 hours.