mc is

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

INSTRUCTION SETS

Arithmetic Instructions:-

Mnemonic + Period
Description Addressing Mode
Operand (Cycles)
ADD A, Rn Add register to Accumulator Register 1
ADD A, direct Add direct byte to Accumulator Direct 2
ADD A, @Ri Add indirect RAM to Accumulator Indirect 1
ADD A, #data Add immediate data to Accumulator Immediate 2
Add register to Accumulator with
ADDC A, Rn Register 1
Carry
Add direct byte to Accumulator with
ADDC A, direct Direct 2
Carry
Add indirect RAM to Accumulator
ADDC A, @Ri Indirect 1
with Carry
Add immediate data to Accumulator
ADDC A, #data Immediate 2
with Carry
Subtract register from Accumulator
SUBB A, Rn Register 1
with borrow
Subtract direct byte from
SUBB A, direct Direct 2
Accumulator with borrow
Subtract indirect RAM from
SUBB A, @Ri Indirect 1
Accumulator with borrow
Subtract immediate data from
SUBB A, #data Immediate 2
Accumulator with borrow
Register
INC A Increment Accumulator 1
(Accumulator)
INC Rn Increment register Register 1
INC direct Increment direct byte Direct 2
INC @Ri Increment indirect RAM Indirect 1
Register
DEC A Decrement Accumulator 1
(Accumulator)
DEC Rn Decrement register Register 1
DEC direct Decrement direct byte Direct 2
DEC @Ri Decrement indirect RAM Indirect 1
INC DPTR Increment Data Pointer DPTR 2
MUL AB Multiply A and B Register 1
DIV AB Divide A by B Register 1
Register
DA A Decimal Adjust Accumulator 1
(Accumulator)
Logical Instruction : -

Mnemonic + Period
Description Addressing Mode
Operand (Cycles)
ANL A, Rn AND register to Accumulator Register 1
ANL A, direct AND direct byte to Accumulator Direct 2
AND indirect RAM to
ANL A, @Ri Indirect 1
Accumulator
AND immediate data to
ANL A, #data Immediate 2
Accumulator
ANL direct, A AND Accumulator to direct byte Direct 2
ANL direct, #data AND immediate data to direct byte Direct 3
ORL A, Rn OR register to Accumulator Register 1
ORL A, direct OR direct byte to Accumulator Direct 2
ORL A, @Ri OR indirect RAM to Accumulator Indirect 1
ORL A, #data OR immediate data to Accumulator Immediate 2
ORL direct, A OR Accumulator to direct byte Direct 2
ORL direct, #data OR immediate data to direct byte Direct 3
Exclusive-OR register to
XRL A, Rn Register 1
Accumulator
Exclusive-OR direct byte to
XRL A, direct Direct 2
Accumulator
Exclusive-OR indirect RAM to
XRL A, @Ri Indirect 1
Accumulator
Exclusive-OR immediate data to
XRL A, #data Immediate 2
Accumulator
Exclusive-OR Accumulator to
XRL direct, A Direct 2
direct byte
Exclusive-OR immediate data to
XRL direct, #data Direct 3
direct byte
Register
CLR A Clear Accumulator 1
(Accumulator)
Register
CPL A Complement Accumulator 1
(Accumulator)
Register
RL A Rotate Accumulator Left 1
(Accumulator)
Rotate Accumulator Left through Register
RLC A 1
Carry (Accumulator)
Mnemonic + Period
Description Addressing Mode
Operand (Cycles)
Register
RR A Rotate Accumulator Right 1
(Accumulator)
Rotate Accumulator Right through Register
RRC A 1
Carry (Accumulator)
Swap nibbles within the Register
SWAP A 1
Accumulator (Accumulator)

Data Transfer Instructions:-

Mnemonic + Addressing Period


Description
Operand Mode (Cycles)
MOV A, Rn Move register to Accumulator Register 1
MOV A, direct Move direct byte to Accumulator Direct 1
MOV A, @Ri Move indirect RAM to Accumulator Indirect 1
MOV A, #data Move immediate data to Accumulator Immediate 1
MOV Rn, A Move Accumulator to register Register 1
MOV Rn, direct Move direct byte to register Direct 1
MOV Rn, #data Move immediate data to register Immediate 2
MOV direct, A Move Accumulator to direct byte Direct 1
MOV direct, Rn Move register to direct byte Direct 2
MOV direct,
Move direct byte to direct byte Direct 2
direct
MOV direct, @Ri Move indirect RAM to direct byte Indirect 2
MOV @Ri, A Move Accumulator to indirect RAM Indirect 2
MOV @Ri, direct Move direct byte to indirect RAM Indirect 2
MOV @Ri, #data Move immediate data to indirect RAM Indirect 2
MOV DPTR,
Load DPTR with 16-bit immediate data Immediate 2
#data16
MOVX A, Move code memory byte relative to DPTR +
2
@A+DPTR DPTR to Accumulator Immediate
MOVC A, Move code memory byte relative to PC
PC + Immediate 2
@A+PC to Accumulator
Move indirect RAM to Accumulator
MOVX A, @Ri Indirect 1
using X
MOVX A, Move indirect RAM to Accumulator
Indirect (DPTR) 1
@DPTR using DPTR
Move Accumulator to indirect RAM
MOVX @Ri, A Indirect 1
using X
Mnemonic + Addressing Period
Description
Operand Mode (Cycles)
MOVX @DPTR, Move Accumulator to indirect RAM
Indirect (DPTR) 1
A using DPTR
PUSH direct Push direct byte onto the stack Direct 2
POP direct Pop direct byte from the stack Direct 2
XCH A, Rn Exchange Accumulator with register Register 1
XCH A, direct Exchange Accumulator with direct byte Direct 2
Exchange Accumulator with indirect
XCH A, @Ri Indirect 1
RAM
Exchange low nibble of Accumulator
XCHD A, @Ri Indirect 1
with indirect RAM

Boolean Variable Manipulation:-

Addressing Period
Mnemonic + Description
Mode (Cycles)
Operand
CLR C Clear Carry Bit 1
CLR bit Clear direct bit Bit 2
SETB C Set Carry Bit 1
SETB bit Set direct bit Bit 2
CPL C Complement Carry Bit 1
CPL bit Complement direct bit Bit 2
ANL C, bit AND direct bit to Carry Bit 2
AND complement of direct bit to
ANL C, /bit Bit 2
Carry
ORL C, bit OR direct bit to Carry Bit 2
OR complement of direct bit to
ORL C, /bit Bit 2
Carry
MOV C, bit Move direct bit to Carry Bit 2
MOV bit, C Move Carry to direct bit Bit 2
JC rel Jump if Carry is set Relative 2
JNC rel Jump if Carry is not set Relative 2
JB bit, rel Jump if direct bit is set Bit + Relative 3
JNB bit, rel Jump if direct bit is not set Bit + Relative 3
Jump if direct bit is set and clear
JBC bit, rel Bit + Relative 3
bit
Program Branching and Control Instructions:-

Mnemonic + Period
Description Addressing Mode
Operand (Cycles)
ACALL addr11 Absolute Subroutine Call Absolute 2
LCALL addr16 Long Subroutine Call Absolute 3
RET Return from Subroutine - 2
Return from Interrupt Service
RETI - 2
Routine
AJMP addr11 Absolute Jump Absolute 2
LJMP addr16 Long Jump Absolute 3
SJMP rel Short Jump Relative 2
JMP @A+DPTR Jump indirect relative to the DPTR Indirect (DPTR) 2
JZ rel Jump if Accumulator is Zero Relative 2
JNZ rel Jump if Accumulator is Not Zero Relative 2
Compare direct byte to Accumulator
CJNE A, direct, rel Direct + Relative 3
and jump if not equal
Compare immediate data to
CJNE A, #data, rel Immediate + Relative 3
Accumulator and jump if not equal
Compare immediate data to register Register + Immediate
CJNE Rn, #data, rel 3
and jump if not equal + Relative
CJNE @Ri, #data, Compare immediate data to indirect Indirect + Immediate
3
rel RAM and jump if not equal + Relative
Decrement register and jump if not
DJNZ Rn, rel Register + Relative 3
zero
Decrement direct byte and jump if
DJNZ direct, rel Direct + Relative 3
not zero
NOP No Operation - 1

Description of Terms :

 Accumulator (A): A register in the MCS-51 CPU used for arithmetic, logic operations,
and data movement.

 Register (Rn): General-purpose registers (R0-R7) that can be used for various operations
like arithmetic, logic, and data manipulation.

 Direct Addressing: Refers to accessing memory locations directly using an address


specified in the instruction.
 Indirect Addressing (@Ri): Refers to accessing memory indirectly using the value stored
in a register (Ri). For example, @R0 or @R1.

 Immediate Data (#data): Refers to a constant or immediate value specified directly in the
instruction itself.

 DPTR (Data Pointer): A 16-bit register used for accessing external data memory in the
MCS-51 architecture.

 Bit Addressable RAM: The MCS-51 architecture allows individual bits in the internal
RAM to be accessed directly using bit-addressing instructions.

 Program Counter (PC): A register that holds the address of the next instruction to be
executed.

 Stack Operations: Instructions like PUSH and POP are used to push data onto the stack or
pop data from the stack, which is crucial for subroutine calls and managing program flow.

 Exchange Instructions (XCH, XCHD): Used for swapping data between the
Accumulator and registers, direct memory locations, or specific bits.

 Move Code (MOVC): Moves code bytes from program memory (code memory) to the
Accumulator, relative to either the Program Counter (PC) or the Data Pointer (DPTR).

 Jump Instructions (AJMP, SJMP, LJMP): Used for altering program flow by jumping
to different addresses, either absolute or relative to the current program counter.

 Conditional Jump (JZ, JNZ, JC, JNC, JB, JNB): Instructions that conditionally jump to
another address based on the status of the Accumulator or specific bits.

 Clear (CLR) and Set (SETB) Instructions: Used to clear or set specific bits in the
Accumulator or in bit-addressable RAM.

 Rotate and Swap Instructions (RL, RLC, RR, RRC, SWAP): Used for rotating bits
within the Accumulator or swapping nibbles (4-bit segments) of the Accumulator.

 No Operation (NOP): An instruction that does nothing and typically used for padding or
delays.
Real-Time Application Using MCS-51 Microcontroller: Digital Stopwatch

This application implements a simple digital stopwatch using an 8051 microcontroller and a
7-segment display.

Hardware Requirements:

 8051 Microcontroller
 4-digit 7-segment display (common anode or common cathode)
 Push buttons (for start/stop and reset)
 Resistors and connecting wires

Connections:

 Connect the 7-segment display segments (a-g) to Port 1 (P1.0 - P1.6).


 Connect the common anode/cathode pins of the display digits to Port 2 (P2.0 - P2.3).
 Connect the start/stop button to P3.0.
 Connect the reset button to P3.1.

Program:

assembly
Copy code
ORG 0H
MOV P1, #0FFH ; Configure Port 1 as output for 7-segment segments
MOV P2, #0F0H ; Configure Port 2 as output for 7-segment digit selection
MOV P3, #0FFH ; Configure Port 3 as input for buttons
MOV TMOD, #01H ; Timer 0, Mode 1 (16-bit timer)
SETB EA ; Enable global interrupts
SETB ET0 ; Enable Timer 0 interrupt

CLR TR0 ; Stop Timer 0

MAIN: JB P3.0, START_STOP ; Check if start/stop button is pressed


JB P3.1, RESET ; Check if reset button is pressed
SJMP MAIN

START_STOP:
CPL TR0 ; Toggle Timer 0 (start/stop)
ACALL DEBOUNCE
SJMP MAIN

RESET:
CLR TR0 ; Stop Timer 0
CLR TF0 ; Clear Timer 0 overflow flag
MOV TH0, #0 ; Reset timer
MOV TL0, #0
MOV R0, #0 ; Reset counters
MOV R1, #0
MOV R2, #0
MOV R3, #0
ACALL DEBOUNCE
SJMP MAIN

TIMER0_ISR:
CLR TF0 ; Clear Timer 0 overflow flag
ACALL INCREMENT_TIME
RETI

INCREMENT_TIME:
INC R0 ; Increment hundredths of a second
CJNE R0, #100, DISPLAY_TIME
MOV R0, #0
INC R1 ; Increment seconds
CJNE R1, #60, DISPLAY_TIME
MOV R1, #0
INC R2 ; Increment minutes
CJNE R2, #60, DISPLAY_TIME
MOV R2, #0
INC R3 ; Increment hours
DISPLAY_TIME:
MOV A, R3 ; Display hours
ACALL DISPLAY_DIGIT
MOV A, R2 ; Display minutes
ACALL DISPLAY_DIGIT
MOV A, R1 ; Display seconds
ACALL DISPLAY_DIGIT
MOV A, R0 ; Display hundredths of a second
ACALL DISPLAY_DIGIT
RET

DISPLAY_DIGIT:
; Code to display the digit on the 7-segment display
; Use lookup table for 7-segment codes
RET

DEBOUNCE:
MOV R7, #50 ; Simple debounce delay
DB1: DJNZ R7, DB1
RET

END

You might also like