x51

Instruction Set

PSW Register

Symbol Function Bit
CY Carry flag Bit 7
AC Auxiliary Carry flag Bit 6
FO Flag 0 Bit 5
RS1 Register bank select
Bit 4
RS0 Register bank select Bit 3
OV Overflow flag Bit 2
UD User definable flag Bit 1
P Parity flag Bit 0

*Register bank select:
RS1 RS0 - Register Bank and Address
0 0 - Bank0 (D:0x00 - D:0x07)
0 1 - Bank1 (D:0x08 - D:0x0F)
1 0 - Bank2 (D:0x10 - D:0x17)
1 1 - Bank3 (D:0x18H - D:0x1F)


Mov

MOV destination, source.
MOV transfers the value of source into destination.

MOV @Rn, #immediate

MOV @R0, #0F

MOV @Ri, direct

MOV @R1, P2

MOV @Ri, A

MOV @R1, A

MOV A, #immediate
Flags Affected: P

MOV A, #012h

MOV A, @Ri
Flags Affected: P

MOV A, @R1

MOV A, direct
Flags Affected: P

MOV A, P1

MOV A, Rn
Flags Affected: P

MOV A, R0

MOV bit, C

MOV 22h, C

MOV C, bit

MOV C, 22h

MOV dest_direct, src_direct

MOV P1, P0

MOV direct, #immediate

MOV P2, #01Fh

MOV direct, @Rn

MOV P0, @R1

MOV direct, A

MOV P1, A

MOV direct, Rn

MOV P1, R2

MOV DPTR, #immediate

MOV DPTR, #1234h

MOV Rn, #immediate

MOV R4, #1h

MOV Rn, A

MOV R2, A

MOV Rn, direct

MOV R4, P1

MOVX

MOVX transfers data between the accumulator and external data memory.

MOVX @Ri, A

MOVX @R0, A

MOVX A, @DPTR
Flags Affected: P

MOVX A, @DPTR

MOVX A, @Ri
Flags Affected: P

MOVX A, @R0

MOVC

MOVC transfers data data from the code or program memory to the accumulator

MOVC A, @A+DPTR
Flags Affected: P

MOVC A, @A+DPTR

MOVC A, @A+PC
Flags Affected: P

MOVC A, @A+PC

MUL

MUL multiplies unsigned 8-bit integer in the accumulator with the unsigned 8-bit integer in the B register producing a 16-bit product.

MUL AB
Flags Affected: C, OV, P

MUL AB

DIV

DIV divides the unsigned 8-bit integer in the accumulator by the unsigned 8-bit integer in register B.

DIV AB
Flags Affected: C, OV, P

DIV AB

ADD

ADD adds avalue to the accumulator and stores the results back in the accumulator.

ADD A, #immediate
Flags Affected: C, AC, OV, P

ADD A, #E3h

ADD A, @Ri
Flags Affected: C, AC, OV, P

ADD A, @R1

ADD A, direct
Flags Affected: C, AC, OV, P

ADD A, 30h

ADD A, Rn
Flags Affected: C, AC, OV, P

ADD A, R1

ADDC

ADDC adds a value and the value of the carry flag to the accumulator.

ADDC A, #immediate
Flags Affected: C, AC, OV, P

ADDC A, #40h

ADDC A, @Ri
Flags Affected: C, AC, OV, P

ADDC A, @R1

ADDC A, direct
Flags Affected: C, AC, OV, P

ADDC A, 20h

ADDC A, Rn
Flags Affected: C, AC, OV, P

ADDC A, R2

SUBB

SUBB subtracts value and the carry flag from the accumulator.

SUBB A, #immediate
Flags Affected: C, AC, OV, P

SUBB A, #04h

SUBB A, @Ri
Flags Affected: C, AC, OV, P

SUBB A, @R1

SUBB A, direct
Flags Affected: C, AC, OV, P

SUBB A, 20h

SUBB A, Rn
Flags Affected: C, AC, OV, P

SUBB A, R0

DEC

SUBB subtracts 1 from value.

DEC @Ri

DEC @R1

DEC A
Flags Affected: P

DEC A

DEC direct

DEC 20h

DEC Rn

DEC R0

NOP

NOP does nothing.

NOP

NOP

SETB

SETB set the value of any directly addressable bit to 1.

SETB bit

SETB PSW.5

SETB C
Flags Affected: C

SETB C

CLR

CLR set the value of any directly addressable bit to 0.

CLR A
Flags Affected: P

CLR A

CLR bit

CLR 03h

CLR C
Flags Affected: C

CLR C

XRL

XRL bitwise logical OR operation.

XRL A, #immediate
Flags Affected: P

XRL A, #01h

XRL A, @Ri
Flags Affected: P

XRL A, @R1

XRL A, direct
Flags Affected: P

XRL A, 01h

XRL A, Rn
Flags Affected: P

XRL A, R1

XRL direct, #immediate

XRL 35H, #0FFh

XRL direct, A

XRL 35h, A

ORL

ORL bitwise logical OR operation.

ORL A, #immediate
Flags Affected: P

ORL A, #0Fh

ORL A, @Ri
Flags Affected: P

ORL A, @R0

ORL A, direct
Flags Affected: P

ORL A, P0

ORL A, Rn
Flags Affected: P

ORL A, R1

ORL C, /bit
Flags Affected: C

ORL C, /21h

ORL C, bit
Flags Affected: C

ORL C, 21h

ORL A, Rn
Flags Affected: C

ORL A, R1

ORL direct, #immediate

ORL P0, #02h

ORL direct, A

ORL P1, A

ANL

ANL bitwise logical AND operation.

ANL A, #immediate
Flags Affected: P

ANL A, #32h

ANL A, @Ri
Flags Affected: P

ANL A, @R1

ANL A, direct
Flags Affected: P

ANL A, 20h

ANL A, Rn
Flags Affected: P

ANL A, R1

ANL C, /bit
Flags Affected: C

ANL C, /21h

ANL C, bit
Flags Affected: C

ANL C, 21h

ANL direct, A

ANL 20h, A

ANL direct, #immediate

ANL 30h, #31h

CPL

CPL bitwise logical NOT operation.

CPL A

CPL A

CPL bit

CPL 21h

CPL C
Flags Affected: C

CPL C

JZ

JZ jumps to the specified location if accumulator is set 0.

JZ offset

JZ LABEL

JNZ

JNZ jumps to the specified location if accumulator is not 0.

JNZ offset

JNZ LABEL

JNC

JNC jumps to the specified location if carry flag is 0.

JNC offset

JNC LABEL

JC

JC jumps to the specified location if carry flag is 1.

JC offset

JC LABEL

JB

JB jumps to the specified location if the bit is set to 1.

JB bit, offset

JB PSW.5 LABEL

JNB

JNB jumps to the specified location if the bit is set to 0.

JNB bit, offset

JNB PSW.5 LABEL


JMP

JMP jumps unconditionally to the address.

JMP @A + DPTR

JMP @A+DPTR

JBC

JBC jumps to the specified location if the bit is set to 1 and clear it after jump.

JBC 20h

JBC @A+DPTR

CJNE

CJNE Compare and Jump If Not Equal.

CJNE @Rn, #immediate, offset
Flags Affected: C

CJNE @R0, #21H, LABEL

CJNE A, #immediate, offset
Flags Affected: C

CJNE A, #21H, LABEL

CJNE A, direct, offset
Flags Affected: C

CJNE A, 20h, LABEL

CJNE Rn, #immediate, offset
Flags Affected: C

CJNE R4, #21H, LABEL

DJNZ

DJNZ decrements the value by 1 jumps to the specified location if value is not 0.

DJNZ direct, offset

DJNZ 21h, LABEL

DJNZ Rn, offset

DJNZ R2, LABEL

AJMP

AJMP Absolute Jump Within 2K Block.

AJMP addr11

AJMP LABEL

SJMP

SJMP Short Jump offset must be within -128 or +127 bytes of the instruction.

SJMP offset

SJMP LABEL

LJMP

LJMP Long Jump.

LJMP addr16

LJMP LABEL

INC

INC increments by 1.

INC @Ri

INC @R1

INC A
Flags Affected: P

INC A

INC direct

INC 21h

INC DPTR

INC DPTR

INC Rn

INC R1

SWAP

SWAP exchanges the low-order and high-order nibbles within the accumulator.
Accumulator - Bits 3-0 <-> Bits A7-4

SWAP A

SWAP A

XCH

XCH swap accumulator AND operand values.

XCH A, @Ri
Flags Affected: P

XCH A, @R1

XCH A, direct
Flags Affected: P

XCH A, 20h

XCH A, Rn
Flags Affected: P

XCH A, R1

XCHD

SWAP exchanges the low-order nibble of the accumulator with the low-order nibble of the RAM location.
Accumulator - Bits 3-0 <-> @Ri - Bits 3-0

XCHD A, @Ri
Flags Affected: P

XCHD A, @R0

RL

RL rotates the eight bits in the accumulator left one bit position. Bit 7 of the accumulator go into bit 0

RL A

RL A

RLC

RL rotates the eight bits in the accumulator and the one bit in the carry flag left one bit position. Bit 7 of the accumulator go into carry and carry go to Bit 0 of the accumulator.

RLC A
Flags Affected: C, P

RLC A

RR

RR rotates the eight bits in the accumulator right. Bit 0 of the accumulator go into bit 7.

RR A

RR A

RRC

RRC rotates the eight bits in the accumulator and carry flag right one bit position. Bit 0 of the accumulator go into the carry flag and bit 7 of the accumulator go into carry flag.

RRC A
Flags Affected: C, P

RRC A

RETI

RETI Return From Interrupt.

RETI

RETI

RET

RET Return From Subroutine.

RET

RET

PUSH

PUSH push value into the Stack.

PUSH direct

PUSH A

POP

POP pop value from the Stack.

POP direct

POP A

LCALL

LCALL calls a program subroutine.

LCALL addr16

LCALL LABEL

ACALL

ACALL calls a program subroutine within 2K Block.

LCALL addr16

ACALL LABEL

DA

DA Decimal Adjust Accumulator for BCD.

DA A
Flags Affected: C, P

DA A