Seven instructions in the basic computer read or write a word in memory. They are the instructions through which a program loads data, calculates with it and stores the result, and in which it changes the order in which instructions run.

The Seven Instructions

Table 3.3 lists them. AND, ADD and LDA bring an operand from memory into the accumulator, STA sends the accumulator to memory, BUN and BSA change the flow of the program, and ISZ is used to count loops.

Table 3.3: Memory-reference instructions

Symbol Opcode Operation Control function
AND 000 AC ← AC and M[AR] D0T5
ADD 001 AC ← AC + M[AR], E ← Cout D1T5
LDA 010 AC ← M[AR] D2T5
STA 011 M[AR] ← AC D3T4
BUN 100 PC ← AR D4T4
BSA 101 M[AR] ← PC, PC ← AR + 1 D5T5
ISZ 110 M[AR] ← M[AR] + 1, skip if zero D6T6

Definition: Effective address. The address of the operand actually used by an instruction, after any indirect addressing has been resolved.

Data and Branch Instructions

For AND, ADD and LDA, the operand is first read into DR at T4, and the operation is performed at T5. For STA the transfer is made at T4 itself. BUN (branch unconditionally) places the effective address in the PC, so the next instruction is taken from there. BSA (branch and save return address) stores the PC at the effective address and branches to the next location, which is how a subroutine is entered. For example, if BSA 100 is stored at address 20, the PC holds 21 after the fetch. The value 21 is saved at address 100 and the program continues at address 101. The subroutine ends with an indirect BUN 100, which reloads the PC with 21 and returns to the main program. ISZ (increment and skip if zero) increases a memory word by one and skips the next instruction if the result is zero.

Example 3.4: Executing ISZ

Problem: Memory location 20 holds the value FFFE (hexadecimal, 16 bits). Show the result of executing ISZ 20 three times.

Solution:

  1. First execution: FFFE + 1 = FFFF, which is not zero, so the next instruction is not skipped.
  2. Second execution: FFFF + 1 = 0000 (the carry is lost), which is zero, so the next instruction is skipped.
  3. Third execution: 0000 + 1 = 0001, which is not zero, so there is no skip.

Result: Location 20 holds 0001 and the skip happened once, at the second execution.

v = 0xFFFE
for k in (1, 2, 3):
    v = (v + 1) & 0xFFFF
    print(k, format(v, "04X"), "skip" if v == 0 else "no skip")

Output

1 FFFF no skip
2 0000 skip
3 0001 no skip

Common mistakes

  • Writing the BUN operation as PC ← PC + AR. It is PC ← AR.
  • Believing that STA reads the memory word first. STA only writes.
  • Forgetting that ISZ skips when the result is zero, not when it is non-zero.

Key takeaways

  • Opcodes 000 to 110 are AND, ADD, LDA, STA, BUN, BSA and ISZ.
  • LDA and ADD read the operand into DR first.
  • BSA saves the return address, so it is used for subroutines.
  • ISZ is used for loop counting.

Practice questions

  1. What does LDA do?
  2. What does BSA store?
  3. When does ISZ skip the next instruction?

Answers to the practice questions

  1. It loads the word at the effective address into the accumulator.
  2. The return address, that is the PC, at the effective address.
  3. When the incremented value is zero.

Sources

  • Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit III