MC Module 2
MC Module 2
• EXAMPLES:
MOV A, @R0
MOV @R1,B
MOV @R1,A
MOV 20H, @R1
MOV @R0, 03H
Indexed Addressing Mode
• It is widely used in accessing data elements of look-up table entries
located in the program ROM space.
• Either DPTR or PC can be used as an Indexed register & only program
memory can be accessed in Index Addressing Mode.
Internal RAM
ADD A, @R1
ADDC A, @R0
•MOV A,#7BH----------------A=7BH
•MOV 0F0H, #02H-----------B=02H
•MUL AB----------------------AXB =7BH X 02H= 00F6H
A=F6H, B=00H ,OV Flag=0
•MOV B, #0FEH--------------B= FEH
•MUL AB-----------------------AXB=F6H X FEH = F414H
A=14H, B=F4H, OV=1
Division Operation
• Division operation uses registers A and B as both source and
destination.
• Unsigned number in A is divided by unsigned number in B
register.
• DIV AB -----Divide A by B and put integer part of quotient in
register A and integer part of remainder in B register.
MOV A, #0FFH---------------A=0FFH
•MOV 0F0H,#2CH-------------B=02CH
•DIV AB-----------------------A = 05H, B = 23H
•DIV AB--------------------- A=00H, B=05H
•DIV AB------------------------A= 00H, B = 00H
•DIV AB-----------------------A=??, B=??, OV=1
Decimal Arithmetic
• Decimal adjust accumulator for addition ( DA A)
Logical OR
ORL destination(8 bit), source(8 bit)
ORL A,# Data ORL Direct, A
ORL A , direct ORL Direct, #Data
ORL A , Rn
ORL A, @Rp
Logical EX-0R
XRL destination, source
XRL A,# Data XRL Direct,#Data
XRL A, Direct XRL Direct, A
XRL A, Rn
XRL A , @Rp
Logical NOT
CPL A ----Complements the operand and stores the result in
operand
CPL A
CPL C
CPL bit address
Example for byte level logical operation
• MOV A,# 0FFH-----------------A=FFH
• MOV R0, #77H-----------------R0=77H
• ANL A, R0------------------------A=77H
• MOV 15H, A----------------------15H=77H
• CPL A-------------------------------A=88H
• ORL 15H,#88H------------------15H=FFH
• XRL A,15H-------------------------A=77H
• XRL A, R0------------------------A=00H
• ANL A,15H-------------------------A=00H
• ORL A,R0--------------------------A=77H
• CLR A-------------------------------A=00H
• XRL 15H,A-------------------------15H=FFH
• XRL A,R0----------------------------A=77H
Bit-Level Logical operations
Internal RAM Bit Addresses
Byte Address(Hex) Bit Address(Hex)
20--------------------------------------------------------------- 00- 07 (8 Bits)
21----------------------------------------------------------------- 08-0F
22----------------------------------------------------------------- 10-17
23---------------------------------------------------------------- 18-1F
24---------------------------------------------------------------- 20-27
25---------------------------------------------------------------- 28-2F
26---------------------------------------------------------------- 30-37
27---------------------------------------------------------------- 38-3F
28---------------------------------------------------------------- 40- 47
29---------------------------------------------------------------- 48-4F
2A---------------------------------------------------------------- 50-57
2B---------------------------------------------------------------- 58-5F
2C---------------------------------------------------------------- 60-67
2D---------------------------------------------------------------- 68-6F
2E---------------------------------------------------------------- 70-77
2F---------------------------------------------------------------- 78-7F
INTERNAL RAM
SFR Bit Addresses
• The bit instructions that can use a SFR latch bit are:-
CLR, CPL, MOV, SETB
Bit Manipulation Instructions
Mnemonic Operation
ANL C, b------------AND C & the addressed bit ,put the result in C
ANL C, /b -----------AND C & the complement of the addressed bit, put the
result in C ,the addressed bit is not altered
ORL C, b
ORL C, /b
CPL C--------------Complement the C flag
CPL b---------------Complement the addressed bit
CLR C -----------------Clear the carry flag to zero
CLR b ------------------Clear the addressed bit to zero
MOV C, b----------Copy the addressed bit to the C flag
MOV b, C-----------Copy the C flag to the addressed bit
SETB C------------Set the C flag to 1
SETB b---------------Set the addressed bit to 1
EXAMPLE
SETB 00h----------------Bit 0 of RAM byte 20h=1
MOV C,00h--------------C =1
MOV 7Fh, C -----------Bit 7 of RAM byte 2Fh =1
ANL C, / 00H-------------C=0, bit 0 of RAM byte 20h = 1
ORL C, 00H-------------- C=1( 0+1=1)
CPL 7Fh--------------------Bit 7 of RAM byte 2Fh =0
CLR C----------------------C=0
ORL C, / 7Fh------------C=1 , Bit 7 of RAM byte 2FH=0
(0+1=1)
Rotate & Swap Operations
• RL A--------Rotate Accumulator Left
• RLC A------ Rotate Accumulator Left through Carry
• RR A----------Rotate Accumulator Right
• RRC A----------Rotate Accumulator Right through
Carry
RELATIVE RANGE
•Jumps that replace the PC contents with a new address that is
greater than the address of the instruction following the jump by
127d or less than the address of the instruction following the
jump by 128d are called RELATIVE JUMPS.
•Here the address that is placed in the PC is relative to the
address where the jump occurs.
RELATIVE
JUMP Address -128
(256 Bytes)
00-FFH
JUMP ADDRESS
PC NEXT INSTRUCTION -1
+127
ADVANTAGES
1) Only 1 byte of data need is specified either in
positive format for jumps ahead in the program or in 2’s
complement negative format for jumps behind.
2) It saves program bytes & speeds up the program
execution.
3) The program written using the relative range can be
located anywhere in the program address space without
reassembling the code to generate absolute address.
DISADVANTAGE
1) The addresses to be jumped should be within the
range -128 d to 127d .
Short Absolute Range
•
Page no. Holds Address within the page
FFFFh
LCALL < 16-bit address>------------3 Byte Instruction
LJMP < 16-bit address>------------ 3 Byte Instruction
JMP @ A+ DPTR-----------------------3 Byte Instruction
CONDITIONAL JUMP INSTRUCTIONS
1) Bit Jumps
JC radd----Jump to relative address if C=1
JNC radd------Jump to relative address if C=0
JB b, radd--Jump to relative address if
addressable bit =1
JNB b, radd--Jump to relative address if
addressable bit =0
JBC b, radd---Jump to relative address if
addressable bit =1 and clear the addressable bit to
0.
2) Byte Jumps
CJNE A, add, radd----Compare (A) ≠ (add) , jump to radd. Set the carry flag
to 1 (C=1) if A is less than content of direct address otherwise C=0.
CJNE A,#n, radd---Compare (A) ≠ #n , jump to radd. Set the carry flag to 1
(C=1) if A is less than the number otherwise C=0.