MC Module 2 (1)
MC Module 2 (1)
• MOV-general data loading and data transfer within internal RAM and SFRs
Move the content of a register Rn to accumulator where n changes from 0 to 7
MOV A,R2
MOV A,R7
MOV R2,A
Move an immediate 8 bit data to register A or Rn or to a memory location
MOV A,#45H
MOV R6,#56H
MOV 33H,#44H
MOV@R0,#0E8H
MOV DPTR,#F5A2H
• MOVC-load accumulator by a byte from program memory
• MOVX- transfer a byte between external RAM and accumulator
• XCH –exchange bytes between two locations within internal memory
• XCHD-exchange digits (lower nibble) between two locations within internal memory
• MOVC-load accumulator by a byte from program memory
• MOVX- transfer a byte between external RAM and accumulator
• XCH –exchange bytes between two locations within internal memory
• XCHD-exchange digits (lower nibble) between two locations within internal memory
• PUSH- store a byte over system Stack
• POP – Load a byte from system stack
These two instructions are related to the stack. Stack is a block of memory location for temporary
storage of data. To store content in the stack we use PUSH instruction and to take data from the
stack we use POP instruction.
2. Arithmetic Instructions
Using Arithmetic Instructions, you can perform addition, subtraction,
multiplication and division. The arithmetic instructions also include increment
by one, decrement by one and a special instruction called Decimal Adjust
Accumulator. The operations performed by the arithmetic instructions affect
flags like carry, overflow, zero, etc. in the PSW Register.
The Mnemonics associated with the Arithmetic Instructions of the 8051
Microcontroller Instruction Set are:
• ADD-add two operands ,all the flags are affected ADD AL,OFH
• ADDC-add two operand with carry ADC AX,BX
• SUBB-subtract one operand from another
• CMP-compare the content of 2 registers ,only flags are affected
• INC- increment operand by one, all flags are modified
• DEC-decrement operand by one, all flags are modified
• MUL-unsigned integer multiplication
• DIV-unsigned integer division
• DAA-decimal adjust for accumulator
3. Logical Instructions
It perform logical operations like AND, OR, XOR, NOT, Rotate, Clear and
Swap. Logical Instruction are performed on Bytes of data on a bit-by-
bit basis.
Mnemonics associated with Logical Instructions are as follows:
• ANL-logical AND operation
• ORL-logical OR operation
• XRL-logical XOR operation
• CLR-clear accumulator
• CPL-complement accumulator
• RL-rotate accumulator left
• RLC-rotate accumulator left through carry
• RR-rotate accumulator right
• RRC-rotate accumulator right through carry
• SWAP-swap nibbles within the accumulator
4.Boolean or Bit Manipulation Instructions
Boolean or Bit Manipulation Instructions will deal with bit variables.These
instructions can perform set, clear, and, or, complement etc.
The Mnemonics corresponding to the Boolean or Bit Manipulation
instructions are:
• CLR-clear bit
• SETB-set bit
• MOV-mov bit
• JC-jump if carry
• JNC-jump if no carry
• JB-jump if bit is set
• JNB-jump if bit is not set
• JBC-jump if bit is set and clear bit
• ANL-logically AND bit with carry
• ORL-Logically OR bit with carry
• CPL-complement bit
5.Program Branching Instructions
These instructions control the flow of program logic. The mnemonics of the
Program Branching Instructions are as follows.
• LJMP-unconditional long jump
• AJMP-unconditional absolute jump
• SJMP-unconditional short jump
• JZ-jump if accumulator is zero
• JNZ-jump if accumulator is zero
• CJNE-compare and jump if not equal
• DJNZ-decrement and jump if not zero
• NOP-No operation
• LCALL-unconditional long call
• ACALL-unconditional absolute call
• RET-return from call
• RETI-return from interrupt
• JMP-jump to the address location indicated by DPTR and A
• All these instructions, except the NOP (No Operation) affect the Program
Counter (PC) in one way or other. Some of these instructions has decision
making capability before transferring control to other part of the program.
• Program for Addition
ORG 0000H -directive indicates the start of the program. ORG 0000h tells
the compiler all subsequent code starting at address 0000h.
MOV A, #05h—Move the Value 05h to Register A
MOV R0, #09H--Move the Value 09h to Register R0
ADD A, R0- Add A value with R0 value and stores the result in A
END
Subtraction:
ORG 0000h
MOV R0, #03H // move the value 3 to register R0//
MOV A, #05H // move the value 5 to accumulator A//
SUBB A, R0 // Result value is stored in the Accumulator A //
END
Multiplication:
ORG 0000h
MOV B, #03H // move the value 3 to the register B//
MOV A, #05H // move the value 5 to accumulator A//
MUL A,B // Multiplied result is stored in the Accumulator A //
END
Division:
ORG 0000h
MOV B, #03H // move the value 3 to register B//
MOV A, #15H // move the value 5 to accumulator A//
DIV AB // final value is stored in the Accumulator A //
END
Program for data transfer
Let N = 05h, location A: 30h location B: 40h
mov r0,#30h //source address
mov r1,#40h //destination address
mov r7,#05h //Number of bytes to be moved
back: mov a,@r0
mov @r1,a
inc r0
inc r1
djnz r7,back //repeat till all data transferred
end
8051 interrupts: