Assembly Microprocessorssession 4
ing. Ernst E. Mak MSc
Generic Instructions Taxonomy
• input/output data• load a value(register) into a register• arithmetic• jumping / subroutine• control• bitwise operators : Boolean, Register shifts • interrupt handling• stacking
Subtract
• SUBTRACT, Mnemonic is SUB• syntax: SUB source
• destination (not shown):
– A register
• source– value– register– memory by index
As a result of a SUBtract, the destination is overwritten by the accumulator (a-register) minus the source.
subtraction examples
• SUB B
• SUB C
• SUB 15h
• SUB (HL)
BORROW
• decimal subtraction: 861-162
8 6 11 6 2
-
6 9 9
1010
subtraction with carry• subtraction include the carry(bit);• Mnemonic: sbc, syntax sbc a, source or sbc HL,source2
• Purpose: to calculate the effect of the carry while subtracting
SOURCE:single register a,b,c,d,e
if sbc a,...
double register HL,DE,BC
if sbc HL,...
Effect:
after for example: sbc a,b the a register will be:
a:=a-b-1 if the carry was set
a:=a-b if the carry was reset
Example: HL:=515-245 (= (2*256+3)-245)
ld hl,515d
ld c,245
ld a,l
sub c
ld e,a
ld a,h
sbc a,0
ld d,a
halt
Increment• increment, Mnemonic is inc• syntax: inc destination
• destination:– register– memory by index
as a result of an INCrement, the destination is increased by 1flags are set and reset accordingly, EXCEPT the CARRY
Decrement• increment, Mnemonic is dec• syntax: dec destination
• destination:– register– memory by index
as a result of an DECrement, the destination is decreased by 1
flags are set and reset accordingly , EXCEPT the CARRY
LOOPING
• backward loop init: ld a,2
label: inc a
cp 150d
jp nz,label
halt
LOOPING
• forward loop init: ld a,2
label: cp 0C3h
jp z,end
inc a
jp label
end: halt