There are four categories of instructions: instructions that transfer date from memory to the registers or from the registers to memory; instructions that transfer data between registers; instructions that operate on data in the registers; and instructions that branch or jump. For example, to complete the task of moving a variable named VAR1 into a register, and VAR2 into another register, adding them together, and saving the result in Var1 if no overflow occurred or saving 0 in Var1 if an overflow did occur we could use the following instructions:
LDAA VAR1 ; load var1 into acc a
LDAB VAR2 ; load var2 into acc b
ABA ; add acc b to a, result in acc a
BVS OVERFLOW ; Branch if overflow occurred
STAA VAR1 ; Store result of add into var1
BRA DONE
OVERFLOW: LDAA #0 ; if V then load a zero into acc a
STAA VAR1 ; store zero into var1
DONE: continue with code
An assembler will convert the above mnemonics (easy for humans to
remember) into opcodes and data in a format which would look like just a
bunch of ones and zeros to humans (but computers sure like it) Each line
above will become one or two bytes of information in the assembled object
file. We call a file of mnemonics which the programmer writes the source
file.
Four addressing modes are exemplified above. The first two instructions
both use the direct addressing mode. When a assembler assembles the above,
it should know where in memory VAR1 and VAR2 reside (it should know because
you should tell it earlier in the program). The assembler will substitute
the memory address in place of the name so that the load instruction may
directly access an area of memory. Secondly the load instruction found on
the same line as the OVERFLOW label uses the immediate addressing mode
where the data is not in RAM but will be assembled immediately into the
program code, that is, the value of zero is placed immediately after the
opcode for ldaa into the program code. Thirdly the ABA instruction
exemplifies the inherent addressing mode. All information about where to
find its operand is inherently contained in the opcode itself. And
finally, the fourth addressing mode may be found in both branch
instructions. The programmer wrote branch to a label, and this will become
the relative addressing mode. The assembler will see the branch to a label
type of instruction, figure out how far away the label is, and encode that
distance as an offset to be placed directly into the object file. For
example, the BRA DONE instruction will assemble as one byte for the opcode
for BRA and one byte for the relative offset of how far it is to get to the
label "DONE". During execution, when the program counter gets to
BRA DONE, the one byte offset will be added into the PC so that the next
instruction to be executed will be at the label "DONE:". This
addressing mode is called relative because the offset was calculated as a
value relative to the current position in memory, not as a Direct value to
replace the PC with. Branch instructions always produce relative addresses
(one byte long) to be added to the current PC, but JMP instructions will
always produce direct addresses (two bytes long) to replace the current PC
with.
ieeecs@hal.elee.calpoly.edu Back to Table of Contents