You are on page 1of 2

EEC70: Computer Structures and Assembly Language Programming Quiz I Problem 1.

HLL to Assembly Language

Fall 2012

Below are four pieces of C code and four pieces of MIPS code. In the blank provided next to each piece of C code, enter the letter corresponding to the MIPS code that accurately performs EXACTLY the same function as the C Code. Each piece of MIPS code matches to exactly one and only one piece of C code. There are no repeats. There are no none of the above answers. Assume that, at the beginning of each piece of C code, the integer variable i contains as its value a non-negative integer. Also assume that both arrays are integer arrays of size 20 (so there will be no addressing problems in any of the code). Let the following be true of the registers prior to execution of the MIPS code: $t0 contains the value of the integer variable i in the corresponding C code $s0 contains the address of A[0] $s1 contains the address of B[0] C code:
1. __ C____ do{ A[i]=B[i]+i; i++; } while (i<10); 2. __B_____ while (i<10){ A[i]=B[i]; A[i]+=i; } 3. ___D___ if(i<10){ A[i]=B[i]; A[i]+=i; i++; } 4. ___A ___ for(;i<=9;i++){ A[i]=B[i]+i; }

MIPS code:
A. Begin: slti beq sll add lw add add sw addi j Fin: C. Begin: sll add lw add add sw addi slti beq j Fin: $t1, $t0, 10 $t1, $0, Fin $t1, $t0, 2 $t2, $s1, $t1 $t3, 0($t2) $t3, $t3, $t0 $t2, $s0, $t1 $t3, 0($t2) $t0, $t0, 1 Begin B. Begin: slti beq sll add lw add add sw j Fin: D. Begin: slti beq sll add lw add add sw addi Fin: $t1, $t0, 10 $t1, $0, Fin $t1, $t0, 2 $t2, $s1, $t1 $t3, 0($t2) $t3, $t3, $t0 $t2, $s0, $t1 $t3, 0($t2) Begin

$t1,$t0, 2 $t2, $s1, $t1 $t3, 0($t2) $t3, $t3, $t0 $t2, $s0, $t1 $t3, 0($t2) $t0, $t0, 1 $t1, $t0, 10 $t1, $0, Fin Begin

$t1, $t1, $t1, $t2, $t3, $t3, $t2, $t3, $t0,

$t0, 10 $0, Fin $t0, 2 $s1, $t1 0($t2) $t3, $t0 $s0, $t1 0($t2) $t0, 1

Problem 2. TAL and Machine Code

EEC70: Computer Structures and Assembly Language Programming

Fall 2012

Translate the following MIPS assembly code into binary machine code, putting your result in the table below. If a MIPS assembly instruction must first be translated to TAL, show the translation by marking up the code. In the first column of the table give each machine instruction its corresponding ID, I1 thru I5. If MIPS assembly instruction Ii is represented using two TAL instructions, give the equivalent TAL instructions and label them with IDs, Ii.1 and Ii.2. Assume that the starting address of the code is 0x00400000. # ID __start: li add beq sw End:
ID 3 1 3 0 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 1 0 9 8 7 6 5 4 3 2 1 0

$t6, 0xffffff00 $t0, $t0, $t1 $t0, $t6, End $t0, 20($a0)

# I1; Code stored at address 0x00400000 # I2 # I3 # I4

I11 I12 I2 I3 I4

0 0 0 0 1

0 0 0 0 0

1 1 0 0 1

1 1 0 1 0

1 0 0 0 1

1 1 0 0 1

0 0 0 0 0

0 1 1 1 0

0 1 0 0 1

0 1 0 0 0

0 0 0 0 0

0 0 0 0 0

1 1 1 1 1

1 1 0 1 0

1 1 0 1 0

0 0 1 0 0

1 1 0 0 0

1 1 1 0 0

1 1 0 0 0

1 1 0 0 0

1 1 0 0 0

1 1 0 0 0

1 1 0 0 0

1 1 0 0 0

1 0 0 0 0

1 0 0 0 0

1 0 1 0 0

1 0 0 0 1

1 0 0 0 0

1 0 0 0 1

1 0 0 0 0

1 0 0 1 0

li $t6, 0xffffff00 => lui $t6, 0xffff Ori $t6, 0xff00

You might also like