Homework Assignment 6 CS 429 Unique Numbers: 52873, 52875, 52880, 52885 Fall, 2012 Given: October 15, 2012 Due: October 31, 2012 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 41; 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)? To turn your homework in, use the command (where your file is names "fib.lisp"). turnin --submit beltagy hw6 fib.lisp 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) 'sum-1-to-n) 'shrunk-sum-1-to-n)) ; 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 (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 (pos 4096) stack_top ))