705 - CS135602_Lab03 Scoreboard

Time

2015/03/18 08:20:00 2015/03/18 10:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10453 Lab03_problem

10453 - Lab03_problem   

Description

We have 4 normal registers, r0, r1, r2, r3, whose initial values are all zeros. This CPU has 7 kinds of instructions, MOV, ADD, SUB, CMP, JMP, JLE, JG, whose formats are specified as follows.

: Any register, r1, r2, r3, r4

: positive integer


MOV , copy the constant to the register

MOV , copy the value stored in the register 2 to the register 1


ADD , add the constant to the register

         , add the value stored in the register 2 to the register 1


SUB , minus the constant value to the register

        , minus the value stored in the register 2 to the register 1


CMP ,  

JLE  if the value stored in the register is less than or equal to the constant, jump to the label


CMP ,  

JLE  if the value stored in the register 1 is less than or equal to the value stored in the register 2, jump to the label


CMP ,  

JG  if the value stored in the register is bigger than the constant, jump to the label


CMP ,  

JG  if the value stored in the register 1 is bigger than the value stored in the register 2, jump to the label


JMP jump to the label


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, variable "c" in r2, variable "d" in r3.

We will give you some hints and one "something missing" means one instruction.

c code :

int main(){

int a, b, c, d;

a=17;

b=2;

c=a;

while(c<=10){

d=c;

while(d>1){

d-=b;

}

c--;

}

}


assembly code :

MOV r0, 17

MOV r1, 2

MOV r2, r0

/* something missing */

L5 :

MOV r3, r2

JMP L3

L4 :

/* something missing */

L3 :

CMP r3, 1

/* something missing */

/* something missing */

L2 :

/* something missing */

JLE L5

 

Input

There is no input.

Output

Please print the complete assembly code and use minimal instructions.

Sample Input  Download

Sample Output  Download

Tags




Discuss