Cmpe 110
HomeWork 4 Floating Point and MIPS TAL
Due: Monday, Oct. 27, 2003
This assignment will test your ability in Floating point conversion and MIPS ISA.
Floating point conversion
1.) Convert A = 1,985.2 to fixed-point binary. Use as many bits as needed for the integer portion, and use 30 bits for the significand. Do-not round.(1 point)
2.) Express number A from ex 1) in IEEE-754 single-precision floating-point format, using the appropriate rounding method. Show all work. (2 points)
MIPS Coding and Decoding
Consider the C code below.
Assume the address for A[0] is stored $s0, address for B[0] is stored in $s1, and address for flag is stored in $s2;
Also assume these arrays were declared earlier as integer arrays (with a size of 100). Assume integers to be 4-bytes.
int counter = 100;
int x;
for ( x = 0; x < 100; x++)
B[x] = 1 - x;
if (flag ==1){
while(counter != 0){
counter--;
A[counter] = B[counter] + counter;
}
}
else {
while(counter != 0){
counter--;
A[counter] = B[counter] - 2 * counter;
}
}
3.) Convert this snippet of C code into MIPS TAL (meaning no pseudoinstructions). (3 points)
4.) Consider the MIPS instruction code below. Assume $s0 is the base address for 3 needed integer variables. See problem 5, for how these variables look in memory.
lw $t0, 0($s0);
lw $t1, 4($s0);
lw $t3, 8($s0);
loop: add $t1, $t1, $t0;
addi $t1, $t1, 1 ;
sll $t2, $t0, 1;
sub $t0, $t2, $t1;
slt $t4, $t0, $t3;
bne $zero, $t4, outofloop;
j loop;
outofloop:
Convert this MIPS TAL to C code. Comment each line with instructions used to create the C statement on that line. (3 points)
5.) Consider the MIPS code above. Now consider the 2 memory blocks below. Higher addresses go up, each block is 4 bytes or 1 word.
Use the numbers in the memory blocks, in the program above. And find the answers to the question below.
address Block 1 Block2
| $s0 + 12 | ???????? | ????? |
| $s0 + 8 | -120 | -500 |
| $s0 + 4 | 3 | 2 |
| $s0 ---> | 5 | 9 |
How many times will the program loop for each given block of memory? (1/2 point each)