Writing assembly language programs

Opcodes and operands

Each assembly language statement is split into an opcode and an operand. The opcode is the instruction that is executed by the CPU and the operand is the data or memory location used to execute that instruction.

Assembly language opcode mnemonics and instructionsMeaning/use
INP (Input)Inputs a value, then stores the value in the accumulator
OUT (Output)Outputs the accumulator contents
STA (Store)Transfers a number from the accumulator to RAM
LDA (Load)Transfers a number from RAM to the accumulator
ADD (Add)Adds accumulator contents to the contents at a RAM address
SUB (Subtract)Subtracts accumulator contents from the contents at a RAM address
BRA (Branch)When looping, jumps to the RAM memory address
HLT (Halt/Stop/End)Stops the processor
DAT (Data definition)Variable definition

An operand (written using hexadecimal notation) provides the data itself, or the location where the data to be processed is stored. Some instructions do not require an operand and some may require more than one operand.

The table below is a small assembly language program with a description of the opcode and operand components during execution.

Original assembly languageOpcodeOperandDescription
INPINPInput value and store in the accumulator
STA 1CSTA1CStore the number at memory address 1C
INPINPInput value and store in the accumulator
ADD 1CADD1CAdd this number to the number stored at memory address 1C
OUTOUTOutput the result
HLTHLTStop the program
Move on to Test
next