function/subroutine calls

I am fairly new to assembly. This is specific to the SPARC processors.

1). What is a register window exactly? I am imagining it is something like a snapshot of a set of registers - am I close?.

2). What does "save %sp, -96, %sp" do? My prof says to take it on faith that it is always the first line of main. Does it always have to be 96 bytes for every function? How about ret and restore?

Basically I am trying to understand how function calls should be made. I think the save operation creates space on the stack for the variables of a function but the documentation says it also advances the register window pointer. Also is save always necesary?

Any answers are greatly appreciated and I will rate the answer if it is helpfull.
[770 byte] By [GeoHoffman49431] at [2007-11-19 19:55:24]
# 1 Re: function/subroutine calls
I believe (not sure) the register window pointer is called stack frame pointer, and on IA32, a function frame is known to be the stack range from ESP to EBP (in case the stack pointer ESP is saved to EBP, before substracting the size of local variables).
Bornish at 2007-11-10 3:55:32 >
# 2 Re: function/subroutine calls
i dont know about ur processor
but i have done some prog. in assembly in x86 and ATMEL AVR 8515
in these processors the func. and subroutine is called by
jump or rjump command
inside the func. or subroutine the control is again rejumped till the condition.
try this


rjump kanul //this is func. call
---
--
--
some statements
---
---

kanul : --
--
some statements
---
cmp --,-- //condition check
jne kanul //for next iteration
kanul.chugh at 2007-11-10 3:56:32 >
# 3 Re: function/subroutine calls
This is what I was told to do when I want to call a subroutine:

func:

save %sp,-96,%sp

...Function body

ret
restore

I guess that ret is a synthetic instruction that is the same as jumpl and it jumps to 8 bytes (2 instructions) after the call instruction (because nop always follows a call instruction). I did some experimentation on what happens to the registers when the above function call occurs. This is what I believe. Before I call a subroutine I can put parameters into registers %i0 - %i5. Then I call the subroutine. Inside the subroutine those parameters are accessed as %o0 - %o5 because they get flipped (or rather a bit in the psr changes how they are addressed). Any return values from the function go in the output registers %o0 - %o5. Then after ret and restore are called we return to the calling segment of code. At this point the return valueshave again been flipped and can be retrieved from the %i0 - %i5 registers. The global registers if they were changed by the subroutine remain changed. The local registers and the output registers, if they were changed by the called routine, are reverted back to whatever values they had before calling the routine. Is this correct? So that means the call to save must be saving the local and output registers (or else how would they be restored after the function returns).
GeoHoffman49431 at 2007-11-10 3:57:28 >