EECS 314 additional information for the exam. > > I have a question regarding the reservation of stack space in the prologue > of a function. I am unsure when to allocate space on the stack and when not > to. I was looking over the practice materials posted on the web site, > specifically the practice test for the Wednesday Feb 14th exam and the > actual Wednesday Feb 14th exam itself. > > My difficulty is with problem number four on both of the tests. I can't seem > to understand the difference in stack space allocation between the two. The > function on the practice test and the function on the final itself seem to > be perfectly analogous (both recursive), and yet the solution for one > allocates stack space for the arguments, while the other one does not. You can always use any register to solve a problem. * If you decide to you registers $s0-$s7 then you must restore them back to the original condition you found them for the caller. * If you decide to use $t0-$t9 then by convention you are "not" required to restore them. Why choose one over the other? Performance. * A solution with $s register and saved on the stack would also be correct but it would be slower in time and use up more memory. If you can live without a $s register, then always use a $t register. Temporary $t registers are faster overall because you don't need to spend time saving them on the stack. You use them first until you run out of $t registers, then if all your t registers are being used you must spill over to $s registers. Saved $s registers are used if you need to have the value "after" calling another function. The penality of using $s register is extra time and storage putting it on the stack. For example: addi $t0,$0,3 jal functionx add $t0,$t0,$v0 #$t0 does "not" contain 3 because of functionx but addi $s0,$0,3 jal functionx #by convention functionx will guarentee the same value add $s0,$s0,$v0 #$s0 does contain 3 > At first I thought that perhaps one of the solutions was incorrect, but then > I realized that someone would have caught it by now. I think it's more > likely that I am just misunderstanding something. Is there any way that you > could explain briefly why the one function needs to allocate stack space for > its arguments and the other one doesn't? I'm not sure what I'm overlooking. > Given a large function (>28 variables) or calling another function (>8 variables), you will quickly run out of registers and then it becomes a shuffling game because you can't do arithmetic unless it is in a register and you can't use the register unless you save the old value and load another value. > One last question. I thought that it might be true that, in the case of > problem 4 on the Feb 14 practice test, it would not hurt to allocate the > arguments to the stack, even though it might not be necessary. Is this true > as a general principle? In the case of pass by value arguments, can you just > always allocate the arguments to the stack and not worry about it? > Again, it is a performance issue. Semantically it would be the same and correct but inefficient.