presentation 12007
TRANSCRIPT
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 1/25
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 2/25
The 8051 MICROCONTROLLER
Instruction set ……..
By:-Hitesh TejwaniGurpreet Kaur RaiAbhinav Biyani
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 3/25
The C8051 instructions are divided into five
functionalgroups:
Arithmetic operations
Logical operations
Data transfer operationsBoolean variable operations
Program branching operations
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 4/25
With arithmetic instructions, the C8051 CPU hasno special knowledge of the dataformat (e.g.signed/unsigned binary, binary coded decimal,ASCII, etc.)
The appropriate status bits in the PSW are setwhen specific conditions are met,which allows theuser software to manage the different data formats(carry, overflow etc…)
[@Ri] implies contents of memory location pointedto by R0 or R1
Rn refers to registers R0-R7 of the currentlyselected register
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 5/25
ADD
8-bit addition between the accumulator (A) and asecond operand.
The result is always in the accumulator.
The CY flag is set/reset appropriately.
ADDC
8-bit addition between the accumulator, a secondoperand and the previous value of the CY flag.
Useful for 16-bit addition in two steps.
The CY flag is set/reset appropriately.
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 6/25
Add 1E44H to 56CAH
CLR C ; Clear the CY flagMOV A, 44H ; The lower 8-bits of the 1st number
ADD A, CAH ; The lower 8-bits of the 2nd
numberMOV R1, A ; The result 0EH will be in R1. CY =
1.MOV A, 1EH ; The upper 8-bits of the 1st numberADDC A, 56H ; The upper 8-bits of the 2nd
numberMOV R2, A ; The result of the addition is 75H
The overall result: 750EH will be in R2:R1. CY = 0.
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 7/25
DA Decimal adjust the accumulator. Format the accumulator into a proper 2 digit packed BCD
number. Operates only on the accumulator. Works only after the ADD instruction.
SUBB Subtract with Borrow.
Subtract an operand and the previous value of the borrow(carry) flag from the accumulator. A A - <operand> - CY. The result is always saved in the accumulator. The CY flag is set/reset appropriately.
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 8/25
INC Increment the operand by one. The operand can be a register, a direct address, an indirect
address, the data pointer.
DEC Decrement the operand by one. The operand can be a register, a direct address, an indirect
address.
MUL AB / DIV AB Multiply A by B and place result in A:B. Divide A by B and place result in A:B.
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 9/25
Logical instructions perform Boolean operations(AND, OR, XOR, and NOT) on data bytes on a bit-by-bit
basis.
CPL / CLR Complement / Clear.Work on the accumulator or a bit.
CLR P1.2
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 10/25
RR – RL – RRC – RLC A
EXAMPLE:RR A
RR:
RRC:
RL:
RLC:
C
C
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 11/25
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 12/25
CLR - clear
RL – rotate left
RLC – rotate left through Carry
RR – rotate right
RRC – rotate right through Carry
SWAP – swap accumulator nibbles
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 13/25
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 14/25
PUSH / POP
Push and Pop a data byte onto the stack. The data byte is identified by a direct address from
the internal RAM locations. XCH
Exchange accumulator and a byte variable
XCH A, Rn XCH A, direct XCH A, @Ri
XCHD
Exchange lower digit of accumulator with the lower digit of thememory location specified. XCHD A, @Ri
The lower 4-bits of the accumulator are exchanged with the lower 4-bits of the internal memory location identified indirectly by theindex register.
The upper 4-bits of each are not modified.
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 15/25
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 16/25
Program branching instructions are used tocontrol the flow of program execution
Some instructions provide decision makingcapabilities before transferring control to otherparts of the program (conditional branches).
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 17/25
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 18/25
JZ Jump if A=0
JNZ Jump if A/=0
DJNZ Decrement and jump if A/=0
CJNE A,byte Jump if A/=byte
CJNE reg,#data Jump if byte/=#data
JC Jump if CY=1
JNC Jump if CY=0
JB Jump if bit=1
JNB Jump if bit=0
JBC Jump if bit=1 and clear bit
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 19/25
The 8051 provides 2 forms for the CALLinstruction:
Absolute Call – ACALL
Uses an 11-bit address similar to AJMP The subroutine must be within the same 2K page.
Long Call – LCALL
Uses a 16-bit address similar to LJMP
The subroutine can be anywhere.
Both forms push the 16-bit address of the nextinstruction on the stack and update the stack pointer.
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 20/25
Return is also similar to a jump, but
Return instruction pops PC from stack to get addressto jump to
ret ; PC stack
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 21/25
Another control transfer instruction is the CALL instruction,
which is used to call a subroutine.
LCALL(long call)This 3-byte instruction can be used to call
subroutines located anywhere within the 64K byte
address space of the 8051.
• ACALL (absolute call)
ACALL is 2-byte instruction. the targetaddress of the subroutine must be within 2K
byte range.
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 22/25
Main: ...
acall sublabel
...
...
sublabel:...
...
ret
the subroutine
call to the subroutine
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 23/25
Subroutines allow us to have "structured"assembly language programs.
This is useful for breaking a large design into
manageable parts. It saves code space when subroutines can be
called many times in the same program.
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 24/25
ACALL: Absolute Call
ADD, ADDC: Add Acc. (With Carry)
AJMP: Absolute Jump
ANL: Bitwise AND
CJNE: Compare & Jump if Not Equal
CLR: Clear Register
CPL: Complement Register
DA: Decimal Adjust
DEC: Decrement Register
DIV: Divide Accumulator by B
DJNZ: Dec. Reg. & Jump if Not Zero
INC: Increment Register
JB: Jump if Bit Set
JBC: Jump if Bit Set and Clear Bit
JC: Jump if Carry Set
JMP: Jump to Address
JNB: Jump if Bit Not Set
JNC: Jump if Carry Not Set
JNZ: Jump if Acc. Not Zero
JZ: Jump if Accumulator Zero
LCALL: Long Call
LJMP: Long Jump
MOV: Move Memory
MOVC: Move Code Memory
MOVX: Move Extended Memory
MUL: Multiply Accumulator by B
NOP: No Operation
ORL: Bitwise OR
POP: Pop Value From Stack
PUSH: Push Value Onto Stack
RET: Return From Subroutine
RETI: Return From Interrupt
RL: Rotate Accumulator Left
RLC: Rotate Acc. Left Through Carry
RR: Rotate Accumulator Right
RRC: Rotate Acc. Right Through Carry
SETB: Set Bit
SJMP: Short Jump
SUBB: Sub. From Acc. With Borrow
SWAP: Swap Accumulator Nibbles
XCH: Exchange Bytes
XCHD: Exchange Digits
XRL: Bitwise Exclusive OR
Undefined: Undefined Instruction
8/3/2019 Presentation 12007
http://slidepdf.com/reader/full/presentation-12007 25/25