Stacks of Assembly
This morning, before I got to continuing my revision for my upcoming Systems Analysis exam I thought that I would write another quick blog post. This time (again under request), I'm posting about the stack in assembly. I thought that I'd make a short animated gif in order to demonstrate it more clearly, but I under estimate the amount of time that it took to make and ended up working on it all morning...!
Anyway, here's the animated gif that I created. I also uploaded it to youtube if you'd prefer to watch it there instead.
I omitted the base pointer in order to simplify the animation. I also omitted many of the setup and cleanup commands, because including them would have taken literally all day, and they would also have made the stack really large and hard to read.
Here's the code that was demonstrated in the animation:
#include <iostream>
using namespace std;
void swap(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}
void main(int, char**) {
int number1 = 10;
int number2 = 20;
cout << "number1=" << number1 << ", number2=" << number2 << endl;
// The animation starts here...
swap(number1, number2);
// ...and ends here.
cout << "number1=" << number1 << ", b=" << number2 << endl;
system("PAUSE");
}
If you spot any mistakes, please let me know! I'll fix them as soon as I can.
This animation was made thanks to the following software:
- Ascidia
- Gifsicle
- Atom
- column-select package for atom
If you're interested, you can find the source files for the animation here (Yes, there's a mistake in frame 5 but it didn't make it through to the final product).