A program does three kinds of work. It moves data from place to place, calculates on it, and decides what to do next. The instruction set of a processor has a group of instructions for each of these jobs.
Data Transfer Instructions
These instructions move data between registers, memory and the input-output units without changing it. Common ones are LD (load from memory), ST (store to memory), MOV (move between registers), XCH (exchange), IN and OUT (input and output), and PUSH and POP for the stack.
Data Manipulation Instructions
Data manipulation instructions perform operations on data, and are of three kinds. Arithmetic instructions include increment, decrement, add, subtract, multiply, divide and negate. Logical and bit manipulation instructions include clear, complement, AND, OR and XOR. Shift instructions include logical shifts, arithmetic shifts and rotates, to the left or the right.
Definition: Status register. A register whose bits, called flags, record conditions produced by the last operation, such as carry, sign, zero and overflow.
Program Control Instructions
Normally the PC is incremented after each instruction. A program control instruction changes it, so the next instruction comes from a different address. Branch and jump instructions do this, with or without a condition. A conditional branch tests a flag of the status register. The flags are carry (C), sign (S), zero (Z) and overflow (V). A subroutine is entered with CALL, which saves the return address, and left with RET.
Conditional branches use the flags. BZ branches when Z = 1, BNZ when Z = 0, BC when C = 1, BP when the result is positive and BM when it is negative. A compare instruction subtracts two values only to set the flags, without keeping the difference, and a test instruction performs an AND for the same purpose.
Table 3.8: Data and program control instructions
| Group | Examples | Purpose |
|---|---|---|
| Data transfer | LD, ST, MOV, PUSH, POP | Move data |
| Arithmetic | ADD, SUB, INC, DEC | Calculate |
| Logical | AND, OR, XOR, CLR, COM | Bit operations |
| Shift | SHL, SHR, ROL, ROR | Move bits within a word |
| Program control | BR, JMP, CALL, RET, BZ | Change the sequence |
Example 3.9: Flags after a comparison
Problem: The 8-bit numbers A = 01010000 (80) and B = 01010000 (80) are compared by subtraction. State the flags.
Solution:
- A - B = 00000000.
- The result is zero, so Z = 1.
- The leftmost bit of the result is 0, so S = 0.
- There is no borrow and no overflow, so C = 0 and V = 0.
Result: Z = 1, S = 0, C = 0 and V = 0, so a BZ (branch if zero) instruction would branch.
Common mistakes
- Believing that data transfer instructions change the data.
- Using an arithmetic shift for unsigned numbers where a logical shift is needed.
- Forgetting that CALL saves the return address and RET restores it.
Key takeaways
- Data transfer moves; manipulation changes; program control redirects.
- Shifts and rotates move bits inside a word.
- The status flags are C, S, Z and V.
- CALL and RET are used for subroutines.
Practice questions
- Name the four status flags.
- What does a conditional branch instruction test?
- Which instruction returns from a subroutine?
Answers to the practice questions
- Carry, sign, zero and overflow.
- A flag of the status register.
- RET.
Sources
- Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit III
