Arithmetic instructions:

Addressing modes

Dir Ind Reg Imm

add a,<byte> X X X X

addc a,<byte> X X X X

subb a,<byte> X X X X

inc a A only

inc <byte> X X X

dec a A only

dec <byte> X X X

mul ab A and B only

div ab A and B only

da a A only

mul multiplies A and B

the high order byte of the 16 bit result is in B

the low order byte in A

div divides A by B

the answer is placed in A

the remainder is in B

da is decimal adjust accumulator, and follows any add or addc instruction working with BCD arithmetic

Logical instructions:

Addressing modes

Dir Ind Reg Imm

anl a,<byte> X X X X

anl <byte>,a X

anl <byte>,#data X

same for orl and xrl

clr a A only

cpl a A only

rl a A only

rlc a A only

same for rr

swap a A only

anl AND

orl OR

xrl XOR

clr clear

cpl NOT

rl rotate left 1 bit

rlc rotate left through carry

rr rotate right

swap low nibble (4 bits) of A with high nibble

Data transfer:

Addressing modes

Dir Ind Reg Imm

mov a,<src> X X X X

mov <dst>,a X X X

mov <dst>,<src> X X X X

push <src> X

pop <dst> X

xch a,<byte> X X X

xchd a,@Ri X

mov instructions are the same as high level language assignment statements.

push has the same effect as:

inc sp

mov “@sp”,<src>

pop has the same effect as:

mov <dst>,“@sp”

dec sp

xch exchanges the contents of A with <byte>

xchd exchanges the low nibble of A with the low nibble of the address pointed to by R0 or R1

The 2051 is capable of addressing single bits.

In RAM these bits are equivalent to the byte addresses 20h to 2fh.

These bits are numbered 0 - 7fh

Some SFR registers can be bit addressed.

These bits have symbols associated with them and are normally accessed via the symbol. Otherwise they are numbered 80 - 0ffh

Boolean Instructions:

anl c,bit ;c = c and bit

anl c,/bit ;c = c and not bit

same for orl

mov c,bit ;c = bit

mov bit,c ;bit = c

clr c ;c = 0

clr bit ;bit = 0

setb c ;c = 1

setb bit ;bit = 1

cpl c ;c = not c

cpl bit ;bit = not bit

jc rel ;jump if c == 1

jnc rel ;jump if c != 1

jb bit,rel ;jump if bit == 1

jnb bit,rel ;jump if bit != 1

jbc bit,rel ;jump if bit == 1

;then clear bit

Program Branching:

jmp addr ;or sjmp/ajmp/ljmp

call addr ;or acall/lcall

ret ;return from subroutine

nop ; no operation

jz rel ;jump if A == 0

jnz rel ;jump if A != 0

djnz <byte>,rel ;decrement, jmp if !=0

cjne a,<byte>,rel ;jump if A != <byte>

cjne <byte>,#data,rel ;jump if <byte> != #data

jmp or call may be used as generic instructions.

The assembler will choose which specific instruction to use. Sometimes it does not choose the best! Forward jmp's will be converted to ljmp's.

relative addresses are -128 to 127 bytes from the PC.

PC will already be pointing to the next instruction

The $ sign is interpreted by the assembler as current location counter

sjmp $

is an infinite loop.

The relative offset is not 0 though!

It is 0feh

159.233 Assembler 6 - 1