Sunday, March 13, 2011

How to be Hardcore: Part 2

Alright, so far you (hopefully) understand the basics of registers and the CPU, along with CPU instructions and interrupts. Today I'm going to talk about memory, and how to set up an assembler that uses AT&T syntax, since AT&T syntax the native syntax of GCC. So, lets get started with memory.


You can think of memory in a computer a thin tube that goes up. If we were to place a jelly bean in the tube at the bottom, it gets pushed up. If we were to add another jelly bean, the bean that we put in first get pushed up, and the new bean takes its place. If we keep adding more beans, the beans that were put in before it get moved up. Lets say we want to take beans out. Only the last bean that we put in will be able to be removed, so if we want a bean that is higher up, we need to take out all the beans before it. This is known as Last In First Out (LIFO). The opposite of LIFO is Last In Last Out (LILO). Memory on computers uses LIFO. So, now just think of the beans in terms of computers. The beans would be bits of data, and the tube would be the stack, a representation of memory.

Memory is addressed using hexadecimal addresses. For example, 0x080484d3 on a 32 bit system. Different memory addresses (like house numbers on the same street) have a different hex address.

tl;dr: Memory works Last In First Out, and stores pieces of data. The Stack!

Installing an Assembler

An assembler takes the assembly code you supply it, and turns it into something the computer can run (object code). We're going to be using MASM on Windows, and 'as' on Linux. In order to download MASM, just get it from here. If you're going to be writing assembly, I don't think I should have to tell you how to install it ;), but you can look here for more information if you need it. One downside is that MASM uses Intel syntax and 'as' uses AT&T syntax. So, the code structure will be a little different for both, and some interrupts will  be different due to operating system differences.

tl;dr: Install MASM if you're on Windows. You're already set if you're using Linux.

That's it for now! Hopefully you have a better understanding of memory, and now have a working assembler. Next time, we learn syntax and write a simple "Hello World!" program.


  1. oh looks difficult but thank you for the tip :)

  2. Don't worry if you don't get it right now :) it will all come together once we start the ACTUAL programming haha

  3. Yes, it is also over my head at them moment, but I won't give up!


Please leave a comment