Upload
er-pradip-patel
View
3
Download
0
Embed Size (px)
DESCRIPTION
HOMEWORK
Citation preview
EE488 Computer Architecture Homework
Week 4: Compiler Basics – ALU Instructions Review
Compilers must convert high level code, created by the programmer using languages such as C, C++ or java, into instructions that the processor understands. The compiler typically reads multiple lines and applies powerful algorithms to try to optimize and convert the code while also using many pre-defined rules for how to convert certain types of code. When we compile we use the NPU compiler rules to make the process easy and helps to get the best understanding of how the compiler process works. In the following homework questions remember to use the rules discussed in class – and listed in the lecture notes. Assume MIPS 32-bit processor. Remember you can use the variable name for the register assignment – any temporary register should start with the compiler named t0 to t9. First come-first serve and registers can be re-used.
1. The c-code below is converted to the assembly code which is also shown. Show the 32-bit HEX machine code for the instructions. ( i.e. 0x00324520)
int a, b, c;uint d, e;
c-code MIPS converted codea=b+c; -> add r5, r6, r7d=e+12; -> addu r15, r16, 17
Assembly code Machine code (in HEX)add r5,r6,r7addu r15,r16,17
2. Show how the MIPS/DLX compiler would convert the following c-code. a=(b+c)-(d+e)+100;
Show assembly codelabels Assembly code
3. Show how the MIPS/DLX compiler would convert the following c-code.
a=b >> 5;c=d << 3;
Show assembly codelabels Assembly code
EE488 Computer Architecture Homework
4. Show how the MIPS/DLX compiler would convert the following c-code.
a=(b+c)-(d+e)+100;
Show assembly codelabels Assembly code
5. Show how the MIPS/DLX compiler would convert the following c-code. Remember you can use the variable name for the register assignment – any temporary register should start with the compiler named t0 to t9. First come-first serve and registers can be re-used. Assume “arr” base is in register s6.
a=arr[7]-10;
Show assembly codelabels Assembly code
6. Show how the MIPS/DLX compiler would convert the following c-code.
a=(b+c)-(d+e)&100;
Show assembly codelabels Assembly code
7. Show how the MIPS/DLX compiler would convert the following c-code. Assume “arr” base is in s5.
a=arr[3]+d;
Show assembly codelabels Assembly code
EE488 Computer Architecture Homework
8. Show how the MIPS/DLX compiler would convert the following c-code. Assume “arr1” base is in s5 and “arr2” base is in s7.
arr2[10]=arr1[5]+arr1[4];
Show assembly codelabels Assembly code
9. Show how the MIPS/DLX compiler would convert the following c-code to assembly code.
if( a < b ){ a++; b++;}
labels Assembly code
10. Show how the MIPS/DLX compiler would convert the following c-code to assembly code.
if( a == 5 ){ $b=(c+e)-1;}
Labels Assembly code