We have 4 normal registers, r0, r1, r2, r3, whose initial values are all zeros, and one spe- cial register, sp, which stores stack pointer. Be careful, we cannot change the value in sp register. This CPU has 5 kinds of instructions, MOV, ADD, CMP, JMP, JLE, whose formats are specified as follows.
: Any register, r0, r1, r2, r3
: A memory address. For example, [sp+8]. Be careful, there is no space between ‘[’ and ‘]’.
: A constant value
MOV , will copy the value stored in the latter to the former
MOV ,
MOV ,
MOV ,
MOV ,
ADD , will add the value stored in the latter to the former
ADD ,
ADD ,
ADD ,
ADD ,
CMP ,
CMP ,
CMP ,
CMP ,
JMP
JLE
Please fill in the following assembly code which is a translation of the following c code using these introduced instructions and store variable “a” in r0, variable “b” in r1.
c code :
int main() {
int a, b;
a=1;
b=2;
b = a+b+1;
}
assembly code :
MOV r0, 1
MOV r1, 2
/* something missing */
ADD r1, 1
Input
There is no input.
Output
Please print the complete assembly code and use minimal instructions.