[an error occurred while processing this directive] The Computer Inside Out: Assembler [an error occurred while processing this directive]

Assembler

This section provides an overview of a basic assembler language, as well as the way a microprocessor works in a software perspective. If you find that this overview is not enough to satisfy your curiosity, consider looking at Structured Computer Organization written by Andrew S. Tanenbaum. This book is used at Thomas Jefferson High School for Science and Technology for the Computer Architecture course as well as at various universities.

Before going into the details of assembler, you need to understand certain concepts. We have divided these concepts into sections, so that if you feel that you have a complete understanding of the topic, you can go on to the next one.

Assembler

The assembler language is especially tailored towards a certain processor. Each assembler command maps to a certain opcode. Unfortunately, a fully fledged assembly language is entirely beyond the scope of this web-site. We will present a much more simplified assembler, which is somewhat similar to the x86 assembler. We have also written a Java applet that will execute assembler instructions that are discussed in this section.

Before explaining the assembler language, it is first important to understand the following:

Now that you are armed with these concepts, we can go on teaching you our assembly language. One of the many things that you can do with a microprocessor is move things around. In our assembly language this instruction will be called "mov." When you use the mov instruction, you first need to specify the destination (i.e. where to move data to), and then the source (i.e. where to move the data from). Thus, a valid instruction would be "mov b, a" (notice the comma that separates the destination and the source), which would move the data stored in register a into register b. The destination can either be a register or memory, while the source can be either memory, register, or pure number. When referring to a memory address, you will need to put brackets ([ ]) around the number of the memory address. Pure numbers do not need any special formatting.

Other instructions very similar to mov are available in our language. These are add, sub, and, or, xor. All of these follow the format of mov. Their purpose should be obvious. There are three more instructions that are contained in our set. "not" only takes one argument, and will store the boolean NOT of the value contained in the specified register or memory address. The other two refer to the stack. "push" and "pop" will push and pop things on and off of the stack. They each take one argument. push takes a register, memory address, or pure number that will be put on top of the stack. pop takes a register or memory address into which the top value of the stack will be stored.

In case you still are not sure as to how to use some of these instructions, we present here all the instructions supported by our emulator.

The emulator is below. You can enter one command at a time. You will see the results of your operation in one of the three colored boxes (depending upon the nature of the operation). This emulator should help you understand topics discussed earlier. For further investigation, look into one of the x86 assembler tutorials.

To start you off, we present a simple set of instructions which will multiply a number by 20. What you see in parentheses are comments that should help you understand how this program works.

mov a, 5 (put the original number into a)
push b (save b by pushing it onto the stack, in case it contained some useful value)
mov b, a (make a copy of a and put it into b)
shl a, 4 (shift a 4 bits to the left, which is the same as multiplying by 16, or 2^4)
shl b, 2 (shift b 2 bits to the left, which is the same as multiplying by 4, or 2^2)
add a, b (add b into a, which makes a equal to 5*16+5*4, which is 5*20)
pop b (restore b from the stack to its original value)


Note: You will need a Java 1.1 compliant browser, such as IE 4.0+, and Netscape 4.5+.

[an error occurred while processing this directive]