Out: Saturday, 22 January
Due: Friday, 28 January, 11:59 pm
Turnin: Gradescope - Please turn in as a pdf file
Have a look at the following program, written in C. The first two lines simply provide the compiler with the types of functions printInt and fib and do not cause any assembler code to be emitted. (We have to declare the types of functions in C before any calls to them.) The function fib() is included in this file, but after the call to it. The function printInt is implemented only in assembler, so there is no C function with that name.
Here's the assembler code produced by compiling the C program above using the CSE 410 tools. In CSE410, the assembly implementation of printInt() is automatically appended to the assembler produced by the compiler before assembling to machine code, and another assembly language function, prologue(), is prepended. When run, execution actually starts in prologue.
The assembler code is formatted so you can print this assignment and write your answers to question in the blank spaces provided. Please turn in as a pdf file.
In case you're interested, the C program is available to you at klaatu:/courses/cse410/22wi/hw3/h3-fib.c. On klaatu, you can copy it to your current working directory with:
$ cp /courses/cse410/22wi/hw3-fib.c .You can compile it to RISC-V assembler with:
$CtoAsm hw3-fib.cThat will produce file hw3-fib.asm.
You can also copy the assembler code file, which is at klaatu:/courses/cse410/22wi/hw3/hw3-fib.asm. You can run the simulator on that code if you'd like.
The assembler code in the assignment was created by asking the compiler to turn off all optimizations when compiling. That causes it to produce the most easily understood code, which is generated basically by it looking at one source line at a time.
At the other extreme, the compiler is capable of compiling by looking at all the code available to it and finding optimizations. Below is the result of compiling the same program with optimizations on. In case you're interested, here's what it produces. It's pretty incredible what the compiler manages to do. (Remember that the compiler code must be sure that what it produces "always works" -- always gets the same result as the unoptimized code.)