Homework Assignment 7 CS 429 Unique Numbers: 52915, 52920, 52935, 52940, 52945, 52960, 52965 Fall, 2014 Given: October 20, 2014 Due: November 3, 2014 Note: 2014-10-27, ~10 am: Made minor changes: 1. Changed "41" to "31" in the comment below the "fib2" C-code. 2. Changed TOS to 8192 everywhere -- makes no difference, but now consistent. 3. Fixed names of symbol tables to be consistent with problem being considered. 4. Added the label "main" to the program so EIP initialization works. Convert the Fibonacci program below into Y86 assembler for the class Y86 specification. On the class homework webpage, see the Laboratory 2 discussion for information about how to run our Y86 simulator. int fib_rec (int fx, int fx_1, int remaining) { if (remaining == 0) return fx; return fib_rec( fx + fx_1, fx, remaining - 1 ); } int fib2 (int x) { if (x < 0) return 0; if (x <= 1) return x; return fib_rec( 1, 0, x - 1 ); } Using the command "gcc -O2 -m32 -fno-inline -S " compile the program above. Then, starting with assembler X86 assembler code produced by "gcc", produce input suitable for the class Y86 assember. Get this code to run and produce the correct answer for Fibonacci of 31; your answer should be left in the %eax register. What is the largest input for which this routine produces the correct answer (when running on our Y86 simulated computer)? For the Fibonacci code, the following should permit the code to be assembled and run. (! fib-code '( ; Your solution code. )) ; Program OK? (y86-prog (@ fib-code)) (! location 0) (! symbol-table (hons-shrink-alist (y86-symbol-table (@ fib-code) (@ location) 'symbol-table) 'shrunk-symbol-table)) ; The function Y86-ASM assembles a program into a memory image. (!! init-mem (hons-shrink-alist (y86-asm (@ fib-code) (@ location) (@ symbol-table) 'fib-iterative) 'shrunk-fib-iterative)) ; Initialize the Y86 state, note we need initial values for various ; registers. Here, we clear the registers (not really necessary) and ; the memory (m86-clear-regs x86-32) ; Clear registers (m86-clear-mem x86-32 8192) ; Clear memory location 0 to 8192 (! init-pc (cdr (hons-get 'main (@ symbol-table)))) (! y86-status nil) ; Initial value for the Y86 status register (init-y86-state (@ y86-status) ; Y86 status (@ init-pc) ; Initial program counter nil ; Initial registers, if NIL, then all zeros nil ; Initial flags, if NIL, then all zeros (@ init-mem) ; Initial memory x86-32 ) ; Lines that can be typed that just shows the Y86 machine status and ; some of the memory after single stepping. ; (y86-step x86-32) (m32-get-regs-and-flags x86-32) ; (rmb 4 (rgfi *mr-esp* x86-32) x86-32) ; Step ISA 10,000 steps or to HALT. (time$ (y86 x86-32 10000)) (m32-get-regs-and-flags x86-32) Below is a template you may wish to follow for your coding of this homework assignment. (! fib-code '(fib_setup main (irmovl stack_top %esp) (irmovl stack_top %ebp) (irmovl 31 %edx) ; %edx <- 31 -- This is < x >. (pushl %edx) (call fib2) (halt) fib_rec ;; fib_rec fib2 ;; Setup code ;; return (ret) end-of-code ;; Stack (pos 8192) stack_top ))