z80:Opcodes:ADD

From Learn @ Cemetech
Jump to navigationJump to search

The values of the two operands are added together, and the result is written back to the first one.

Syntax

   add a,op8		;8 bits
   add op16,op16	;16 bits

Allowed instructions

   add a,a
   add a,b
   add a,c
   add a,d
   add a,e
   add a,h
   add a,l
   add a,ixh
   add a,ixl
   add a,iyh
   add a,ixl
   add a,(hl)
   add a,(ix+n)
   add a,(iy+n)
   add a,n		;8-bit constant
   
   add hl,bc
   add hl,de
   add hl,hl
   add hl,sp
   
   add ix,bc
   add ix,de
   add ix,ix
   add ix,sp
   
   add iy,bc
   add iy,de
   add iy,iy
   add iy,sp

Effects

8-bit arithmetic

N flag is reset, P/V is interpreted as overflow. Rest of the flags is modified by definition.

16-bit arithmetic

preserves the S, Z and P/V flags, and H is undefined. Rest of flags modified by definition.

Uses

Obviously used to add two numbers together. However, you can add 16-bit numbers to sp, giving you control of where the stack pointer is pointing to.

T-States

r denotes 8-bit register. rr represents a two byte register pair: BC, DE, HL, SP

r 4
X 7
(hl) 7
(ix+X) 19
(iy+X) 19
hl, rr 11
ix, rr 15
iy, rr 15

See Also

ADC,DAA,DEC,INC,SBC,SUB