[ Prev ] [ Index ] [ Next ]

Assembler Language P2

Building off of Assembler Language, we now must rewrite the second problem but in a way that conforms to calling/callee standards. In particular:

Rewrite this program (program #1 from last Labwork Assignment) to conform with the calling/callee standards as presented in call. Write a calling program that invokes your program that conforms to the standards as well

Write a MIPS program using a loop that multiplies two positive numbes by using repeated addition. For example, to multiply 3 x 6, the program would add 3 six times, or 3+3+3+3+3+3.

All you need to know is that when we run a subroutine, aka a function, in assembly we must be sure to store the state before we start muddling around with the registers and then restore the state. Think of it like when you're a kid and your mom gets pissed at you for making a huge mess in your room and forces you to clean it all up. I.e., your room was in a clean state, you got it messy in order to have fun, and now you gotta put it all back. Same deal with our assembly subroutines. Doing this is adhearing to good calling/callee standards.

Anyways, here's wonderwall the pdf with my solution (which got a 100 so no worries):
./lab8.pdf

I do want to note that I didn't exactly follow calling/callee standards in my opinion. I ended up taking a recursive approach via using the stack pointer. Also, I merely kept passing arguments instead of worrying about managing 'local variables' (as you might think of them) that would need to be reset as per the standard.

I hope my code is self documenting but let me show you what I was doing but in C. Hopefully it'll paint a better picture:

int multiply(int numToAdd, int timesToAdd)
{
	if (timesToAdd <= 0) return 0;
	return numToAdd + multiply(numToAdd, timesToAdd - 1);
}

I didn't bother to test this code but I think it gets the message across.