Subtopic Notes

4.2 Assembly Language

4. Processor Fundamentals

Machine code

Binary written code that uses the processor’s basic machine operations

Assembly language:

  • Low-level programming language
  • Instructions made of an opcode and operand
  • Each assembly language instruction (source code) translates into exactly one machine code instruction (object code)
  • Symbolic Addressing
    • Mnemonics denotes operation codes e.g. LDM, STO
    • Labels may be used for addresses
  • Absolute addressing: A fixed address in memory

Assembler

  • Software that translates low-level assembly language into machine code
  • Substitutes all labels and mnemonics with their corresponding binary values
  • The binary values are predefined by the assembler
  • One Pass Assembler
    • Translates the mnemonic source code to machine code in a single pass
    • Unable to process code that includes forward referencing
  • Two Pass Assembler
    • First Pass
      • Symbol table is made to map symbolic addresses and labels to specific memory locations
      • Errors are flagged when detected
    • Second Pass
      • Symbolic addresses are replaced by absolute addresses
      • Jumps and forward referencing instructions are resolved
      • Complete source code translated to machine code
      • Errors are reported if exists
      • Object code generated

Assembly Language Instructions

OpcodeOperandExplanation
Modes of Addressing
LDM#nImmediate addressing. Load the number n to ACC
LDD<address>Direct addressing. Load the contents of the location at the given address to ACC
LDI<address>Indirect addressing. The address to be used is at the given address. Load the contents of this second address to ACC.
LDX<address>Indexed addressing. Form the address from <address> + the contents of the index register. Copy the contents of this calculated address to ACC
LDR#nImmediate addressing. Load the number n to IX
Data movement
MOV<register>Move the contents of the accumulator to the given register (IX)
STO<address>Store the contents of ACC at the given address
Arithmetic operations
ADD<address>Add the contents of the given address to the ACC
ADD#n/Bn/&nAdd the number n to the ACC
SUB<address>Subtract the contents of the given address from the ACC
SUB#n/Bn/&nSubtract the number n from the ACC
INC<register>Add 1 to the contents of the register (ACC or IX)
DEC<register>Subtract 1 from the contents of the register (ACC or IX)
Unconditional and conditional instructions (jumps)
JMP<address>Jump to the given address
JPE<address>Following a compare instruction, jump to <address> if the compare was True
JPN<address>Following a compare instruction, jump to <address> if the compare was False
Compare instructions
CMP<address>Compare the contents of ACC with the contents of <address>
CMP#nCompare the contents of ACC with number n
CMI<address>Indirect addressing. The address to be used is at the given address. Compare the contents of ACC with the contents of this second address
Input and output of data
INKey in a character and store its ASCII value in ACC
OUTOutput to the screen the character whose ASCII value is stored in ACC
Terminate
ENDReturn control to the operating system

All questions will assume there is only one general purpose register available
(Accumulator)
ACC denotes Accumulator
IX denotes Index Register
<address> can be an absolute or symbolic address
# denotes a denary number, e.g. #123
B denotes a binary number, e.g. B0101010
& denotes a hexadecimal number, e.g. &4A

LabelOpcodeOperandExplanation
<label>:<opcode><operand>Labels an instruction
<label>:<data>Gives a symbolic address <label> to the memory location with contents <data>