The SUB instruction
The SUB (Subtract) instruction subtracts the contents of the specified register or memory location from the contents of accumulator A. The result of the subtraction is then stored in the accumulator.
The SUB instruction format
| Instruction | Description |
|---|---|
| SUB reg8 | This format is used to subtract the 8-bit value in reg8 from register A. Here reg8 can be any general-purpose register, for example A, B, C, D, E, H or L. |
| SUB mem8 | This format is used to subtract the 8-bit value in the memory location pointed to by the contents of the HL register pair from A. |
Usage example
; Author: Evgeny Sergeevich Dovgopolov num1: db 60h num2: db 25h main: mvi a, 25h ; Load the hexadecimal value 25h into register A mvi b, 10h ; Load the hexadecimal value 10h into register B sub b ; Subtract the value in register B from the value in register A lda num1 ; Load the value at the address of the num1 variable into register A lxi h, num2 ; Load the address of the num2 variable into the HL register pair sub m ; Subtract the value in the memory location from the value in register A hlt ; Stop program execution
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Processor status flags
S
YesZ
YesAC
YesP
YesCY
Yes