Subroutine Call and Return Instructions 8051 Micro-controller by Ravinder Nath Rajotiya - April 23, 2019June 10, 20190 Branch Type Instructions These are of two types: Subroutine CALL Instruction JMP Instruction Unconditional JMP Conditional JMP Subroutine Call Instructions: These instructions are used to calls a subroutine located at the specified address. There are two subroutine Call instructions, theses are ACAL and LCALL instruction ACALL Instruction Size : Two bytes Requirement : Subroutine that is called must be located in the same 2KByte block of program memory as the opcode following the ACALLinstruction. Operation: PC is first incemented twice to obtain the address of the following instruction PC is saved on stack low-byte first and high byte at high address. SP increased by two. Calcultes the subroutine address as: by combining the 5 high-order bits of the incremented PC (for A15-A11), the 3 high-order bits
8051 Arithmetic Instructions 8051 Micro-controller by Ravinder Nath Rajotiya - April 22, 2019June 10, 20190 Arithmetic Instructions One of the operand in arithmetic type of instruction is accumulator. Other operand, if there, will be immediate value, direct memory, register, register indirect, except in case of MUL and DIV where register B is used to hold the value of the 2nd operand. ADD Format of Instruction Opcode/Encoding Example and Operation Flags Affected ADD A, #imm 00100100 Immediate 8-bit ADD A, #03h A=A+#data C,AC,OV,P ADD A, @Ri 0010011i (i is Reg number) -- ADD A, @R1 A=A+ (Ri) C,AC,OV,P ADD A, direct 00100101 Direct ADD A, 20H A=A+(20) C,AC,OV,P ADD A, Rn 00101nnn -- ADD A, R0 A=A+R0 C,AC,OV,P ADDC Format of Instruction Opcode/Encoding Example and Operation Flags Affected ADDC A, #imm 00110100 #immediate ADDC A, #43h C,AC,OV,P ADD A, @Ri 0011011i (i is Reg number) -- ADDC A, @R1 C,AC,OV,P ADD A, direct 00110101 Direct ADDC A, 20H C,AC,OV,P ADD A, Rn 00111nnn -- ADDC A, R0 C,AC,OV,P Write a program to add multiple byte of data in assembly language of 8051 MOV R1, 55h ; Mov value at address 55h to R1 MOV
8051 Data Transfer Instructions 8051 Micro-controller by Ravinder Nath Rajotiya - April 22, 2019June 10, 20190 Date Transfer Instructions Used to move a source data to destination MOV Instruction Instruction/Addressing Opcode Subsequent Byte Example and Operation Flags Affected MOV Rn, #immediate 01111nnn MOV R4, #5h None MOV A, #Immediate 01110100 Immediate MOV A, #0FFh P MOV @Rn, #immediate 0111011n Immediate MOV @R0, #05h None MOV direct, #immediate 01110101 Direct, Immediate MOV P2, #0FFh None MOV Rn, A 11111nnn MOV R5, A None MOV A, Rn 11101nnn - MOV A, R6 P MOV @Ri, A 1111011i -- MOV @R0, A None MOV A, @Ri 1110011i -- MOV A, @Ri P MOV dest_direct, src_direct 10000101 Src_Address, dest_Addr MOV P1, P0 None MOV direct, @Rn 1000011n direct MOV P0, @R1 None MOV @Ri, Direct 1010011i direct MOV @Ri, P2 None MOV direct, A 11110101 direct MOV P0, A None MOV A, Direct 11100101 direct MOV A, P0 P MOV direct, Rn 10001nnn direct MOV P2, R5 None MOV DPTR, #immediate 10010000 immediate15-0 MOV DPTR, #1234h None MOV Rn, direct 10101nnn Direct MOV R4, P1 None MOV C, bit 10100010 bit MOV C, 22h None MOV bit, C 10010010 C MOV, 22, C None MOVC This instruction is used to move a byte from the code or program memory to the accumulator. Syntax : MOVC A, @A + PC MOVC A, @A+DPTR MOVC A, @A+DPTR 10010011 -- MOVC A, @A+DPTR A=(A+DPTR) P MOVC A, @A+PC 10000011 -- MOVC
8051 Instructions 8051 Micro-controller by Ravinder Nath Rajotiya - April 19, 2019June 10, 20190 Instructions of 8051 An instruction performs a specific operation. The instructions in 8051 can be classified as per the size they take up in memory or as per the function they perform. Classification as per Size Single Byte instructions Two Byte instructions 3 Byte Instructions Classification based on the function Data Transfer Instruction : MOV, MOVC, MOVX, SWAP, XCH, XCHG, PUSH, POP Arithmetic Instruction : ADD, ADDC, INC, SUB, SUBB, DEC, DA, MUL, DIV Branch Type Instructions : ACALL, LCALL, JMP, SJMP, Logical Instructions Rotate Instructions Date Transfer Instructions These are used to move or transfer data from source to destination. The source may be an immediate data, a register or a RAM or ROM location, the destination may be a register or
8051 Addressing Modes 8051 Micro-controller by Ravinder Nath Rajotiya - April 19, 2019June 10, 20190 Addressing Modes in 8051 The operands may be an immediate value, a value in registers or in memory. The way in which the operands are fetched by thee 8051 microcontroller is called as the addressing modes. 8051 supports the following types of addressing modes. Immediate addressing mode Direct addressing mode Register direct addressing mode Register indirect addressing mode Indexed addressing mode Immediate Addressing Mode In this addressing mode, an immediate 8-bit is part of the instruction. Here source is an immediate data, Destination can be a register or register indirect or direct memory Examples MOV @Rn, #data MOV A, #data ; Instruction size is 2 byte, 1-byte opcode(74) and 1-byte data MOV direct, #data MOV Rn,#data MOV DPTR,#data ; 3-byte instruction The #data is an eight bit constant and may be