Ok I have done the fibonacci number iteratively but now I want to do it recursively. I am using CPUSims 3.6.9 16-bit (4 bit opcode).

;getN
;get a value, n, from user
store n ;store the accumulator value to storage n
subtract n1 ;acc=acc-1
store n ;update n
push ;push acc to stack
push ;push acc to stack
;fib
;initial value is 0 and 1
;then as n decrease the fib(n) increases
store result ;store acc to storage result
store prevPrev ;store acc=prev to prevPrev
push ;push acc to stack
store prev ;store result to prev
subtract n1 ;acc=acc-1
store n ;update n at storage n
call fib ;call the fib function recursively
;main subprogram
;pop the top value from stack
;outputs the value
;end the program
main:   pop ;pop out the top value from the stack to acc
write ;output the acc
stop ;stop the program
;subprogram for printing fib(0)
write ;output the acc value/fib(0)
stop ;stop the program
;subprogram for printing fib(1)
write ;output the acc value/fib(1)
stop ;stop the program
;storage begin
n:  .data 2 0 ;storage n value to find the fibonacci value of
prev:   .data 2 1 ;storage for fib(n-1)
prevPrev:.data 2 0 ;storage for fib(n-2)
result: .data 2 0 ;storage for fib(n)
n1: .data 2 1 ;storage for sentinal value 1
;storage end

The above code is done iteratively. I know call and return would work but how?

## All 6 Replies

This: CPUSims 3.6.9 doesn't tell anything.
CPUSims is CPU organization simulator. It doesn't simulate a certain
processor. It's made for simulating different processors.

What kind of processor is supposed to run the code?

This: CPUSims 3.6.9 is running the code. Our tutor has never said anything about what kind of processor is running the code. IF a processor is running the code , so how can I find out?

You should see it as the title of the window.
I loaded Wombat2.cpu and my window title is "Wombat2".

The assembly looks like wombat1 assembly, except that wombat1 doesn't have "push", "pop" and "call". wombat5 seems to have them (2,3 and 4 don't).
Then there is also wombat6 with shifts and logical instructions (and, or, xor, not) added.

About recursive fibonacci, see rubberman's first posting here

Oh so that's what it means. This thread was for assignment 3 and the previous that I posted was assignment 2. So in assignment we were given a Wombat1 machine and from there we added push and pop for Wombat2. Then in this assignment we were suppose to implement call and return instructions.