Read the following arm code knowing that a , b and c are variable. Write an c++
ID: 3699272 • Letter: R
Question
Read the following arm code knowing that a, b and c are variable. Write an c++ code that describes this arm code.
Note: in the statement use save variables: a in R1, b in R2, and c in R3. In addition, a, b, c variable are represented as word in the memory.
LDR R1, =a
LDR R1, [R1]
LDR R2, =b
LDR R2, [R2]
MOV R3, R2, LSL#1
MUL R2, R3, R2
CMP R1, #0
MVNLT R2, R2
ADDLT R2, R2, #1
LDR R3, =c
STR R1, [R3]
SWI 0x11
LDR R1, =a
LDR R1, [R1]
LDR R2, =b
LDR R2, [R2]
MOV R3, R2, LSL#1
MUL R2, R3, R2
CMP R1, #0
MVNLT R2, R2
ADDLT R2, R2, #1
LDR R3, =c
STR R1, [R3]
SWI 0x11
Explanation / Answer
Here is the corresponding C++ code
/***************/
#include <iostream>
using namespace std;
int main()
{
int a,b,c; //initialise the variables
//a in R1, b in R2, c in R3 register
b=(b<<1)*b; //operations on b
if(a<0) //comparison with a
{
b=~b;
b=b+1;
}
c=a;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.