Q. Classify the instruction set of 8051 and list out the instructions in each type.

Similar documents
Instruction Set Of 8051

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

DR bit RISC Microcontroller. Instructions set details ver 3.10

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

Microcontroller Intel [Instruction Set]

Dragonchip. Instruction Set Manual

Programming of 8085 microprocessor and 8051 micro controller Study material

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

Dodatak. Skup instrukcija

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP

Application Brief D-005

Microcontroller. Instruction set of 8051

8051 Overview and Instruction Set

SN8F5000 Family Instruction Set

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors

AL8051S 8-BIT MICROCONTROLLER Application Notes

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller


Module Contents of the Module Hours COs

Embedded Controller Programming

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

8051 Microcontroller

Application Brief D-002

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

8051 Microcontrollers

C51 Family. Architectural Overview of the C51 Family. Summary

Introduction to uc & Embedded Systems

Legacy documentation refer to the Altium Wiki for current information. TSK52x MCU

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

Highlights. FP51 (FPGA based 1T 8051 core)

Legacy documentation refer to the Altium Wiki for current information. TSK51x MCU

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

NAME as31 - An Intel 8031/8051 assembler. SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm

TUTORIAL Assembly Language programming (2)

8051 Microcontroller Assembly Programming

Assembly Language programming (2)

Chapter Family Microcontrollers Instruction Set

MCS -51 Programmer s Guide and Instruction Set

Assembly Language programming (3)

8051 Instruction Set

8051 Core Specification

International Journal of Digital Application & Contemporary research Website: (Volume 1, Issue 2, September 2012)

What Registers are available? Programming in Assembler. Assembler Programming - like early Basic. Assembler Data Movement Instructions

Core8051. Advanced v0.1

University of Toronto at Scarborough CSC CSSF - Microprocessor Systems

Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

Lecture Instruction Set

Y51 Microcontroller. Technical Manual

INTEGRATED CIRCUITS P89C669 USER MANUAL. Preliminary Supersedes data of 2003 Jul Sep 16

~: Simple Programs in 8051 assembly language :~

IA8044/IA8344 Variants IA8044 4kB internal ROM with R0117 version 2.3 firmware, 192 byte internal RAM, 64kB external program and data space.

Principle and Interface Techniques of Microcontroller

C51 Family. C51 Family Programmer s Guide and Instruction Set. Summary

UNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes

Section Microcontroller Instruction Set

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

UNIT MICROCONTROLLER AND ITS PROGRAMMING

MICROPROCESSOR LABORATORY MANUAL

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

8051 Programming using Assembly

PART-A INTRODUCTION TO 8051 MICROCONTROLLER. 8-bit data bus - It can access 8 bits of data in one operation

CHAPTER 3 JUMP, LOOP, AND CALL INSTRUCTIONS

ELEG3924 Microprocessor

The P-51 Peripheral 8051 System on a Chip. Cybernetic Micro Systems.

ENE 334 Microprocessors

Lecture 5. EEE3410 Microcontroller Applications Department of Electrical Engineering Assembly Language Programming (1)

ET2640 Microprocessors

Assembly Language Programming of 8085

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

8051 Programming: Arithmetic and Logic

Question Bank Microprocessor and Microcontroller

ELEG3923 Microprocessor Ch.3 Jump, Loop, and Call

UNIT MICROCONTROLLER

Principle and Interface Techniques of Microcontroller

Assembly Language Programming of 8085

Lab-Report Microprocessors

1. Write A Program to move a block of data within the internal RAM

Chapter 9. Programming Framework

MICROPROCESSOR & MICROCONTROLLER

TYPES OF INTERRUPTS: -

JUMP, LOOP AND CALL INSTRUCTIONS

MODULE-1. Short Answer Questions

VRS540-4kB Flash, 128B RAM, 25~40MHz, 8-Bit MCU

CW6631B Bluetooth Audio Player Microcontroller User Manual

Preliminary Data Sheet SDLC COMMUNICATIONS CONTROLLER As of Production Version 00

VRS550-8kB Flash, 256B RAM, 25~40MHz, 8-Bit MCU VRS560-16kB Flash, 256B RAM, 40MHz, 8-Bit MCU


8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen

8051 Microcontroller Logical Operations. Prepared by : A. B. Modi Target Audience : 5 th Semester Students

Figure Programming model

CS 320. Computer Architecture Core Architecture


8085 INSTRUCTION SET INSTRUCTION DETAILS

Arithmetic and Logic

Contents. Join the Technical Community Today!

Transcription:

INTRODUCTION Here is a list of the operands and their meanings: A - accumulator; Rn - is one of working registers (R0-R7) in the currently active RAM memory bank; Direct - is any 8-bit address register of RAM. It can be any general-purpose register or a SFR (I/O port, control register etc.); @Ri - is indirect internal or external RAM location addressed by register R0 or R1; #data - is an 8-bit constant included in instruction (0-255); #data16 - is a 16-bit constant included as bytes 2 and 3 in instruction (0-65535); addr16 - is a 16-bit address. May be anywhere within 64KB of program memory; addr11 - is an 11-bit address. May be within the same 2KB page of program memory as the first byte of the following instruction; rel - is the address of a close memory location (from -128 to +127 relative to the first byte of the following instruction). On the basis of it, assembler computes the value to add or subtract from the number currently stored in the program counter; bit - is any bit-addressable I/O pin, control or status bit; and C - is carry flag of the status register (register PSW). Q. Classify the instruction set of 8051 and list out the instructions in each type. Sol: Depending on operation they perform, all instructions are divided in several groups: Arithmetic Instructions Branch Instructions Data Transfer Instructions Logic Instructions Bit-oriented Instructions The first part of each instruction, called MNEMONIC refers to the operation an instruction performs (copy, addition, logic operation etc.). Mnemonics are abbreviations of the name of operation being executed. For example: INC R1 - Means: Increment register R1 (increment register R1); LJMP LAB5 - Means: Long Jump LAB5 (long jump to the address marked as LAB5); JNZ LOOP - Means: Jump if Not Zero LOOP (if the number in the accumulator is not 0, jump to the address marked as LOOP); The other part of instruction, called OPERAND is separated from mnemonic by at least one whitespace and defines data being processed by instructions. Some of the instructions have no operand, while some of them have one, two or three. If there is more than one operand in an instruction, they are separated by a comma. For example:

RET - return from a subroutine; JZ TEMP - if the number in the accumulator is not 0, jump to the address marked as TEMP; ADD A,R3 - add R3 and accumulator; CJNE A,#20,LOOP - compare accumulator with 20. If they are not equal, jump to the address marked as LOOP; Arithmetic instructions Arithmetic instructions perform several basic operations such as addition, subtraction, division, multiplication etc. After execution, the result is stored in the first operand. For example: ADD A,R1 - The result of addition (A+R1) will be stored in the accumulator. Arithmetic Instructions Mnemonic ADD A,Rn Description Adds the register to the accumulator ADD A,direct Adds the direct byte to the accumulator ADD A,@Ri Adds the indirect RAM to the accumulator ADD A,#data Adds the immediate data to the accumulator ADDC A,Rn Adds the register to the accumulator with a carry flag ADDC A,direct ADDC A,@Ri ADDC A,#data SUBB A,Rn SUBB A,direct SUBB A,@Ri SUBB A,#data Adds the direct byte to the accumulator with a carry flag Adds the indirect RAM to the accumulator with a carry flag Adds the immediate data to the accumulator with a carry flag Subtracts the register from the accumulator with a borrow Subtracts the direct byte from the accumulator with a borrow Subtracts the indirect RAM from the accumulator with a borrow Subtracts the immediate data from the accumulator with a borrow INC A Increments the accumulator by 1 INC Rn Increments the register by 1

INC Rx Increments the direct byte by 1 INC @Ri Increments the indirect RAM by 1 DEC A Decrements the accumulator by 1 DEC Rn Decrements the register by 1 DEC Rx Decrements the direct byte by 1 DEC @Ri Decrements the indirect RAM by 1 INC DPTR Increments the Data Pointer by 1 MUL AB DIV AB DA A Multiplies A and B Divides A by B Decimal adjustment of the accumulator according to BCD code Branch Instructions There are two kinds of branch instructions: Unconditional jump instructions: upon their execution a jump to a new location from where the program continues execution is executed. Conditional jump instructions: a jump to a new program location is executed only if a specified condition is met. Otherwise, the program normally proceeds with the next instruction. Mnemonic ACALL addr11 LCALL addr16 Description Absolute subroutine call Long subroutine call RET RETI AJMP addr11 Returns from subroutine Returns from interrupt subroutine Absolute jump LJMP addr16 Long jump SJMP rel Short jump (from 128 to +127 locations relative to the following instruction)

JC rel JNC rel JB bit,rel JBC bit,rel Jump if carry flag is set. Short jump. Jump if carry flag is not set. Short jump. Jump if direct bit is set. Short jump. Jump if direct bit is set and clears bit. Short jump. JMP @A+DPTR Jump indirect relative to the DPTR JZ rel JNZ rel Jump if the accumulator is zero. Short jump. Jump if the accumulator is not zero. Short jump. CJNE A,direct,rel jump. CJNE A,#data,rel Compares direct byte to the accumulator and jumps if not equal. Short Compares immediate data to the accumulator and jumps if not equal. Shortjump. CJNE Rn,#data,rel Compares immediate data to the register and jumps if not equal. Short jump. CJNE @Ri,#data,rel Compares immediate data to indirect register and jumps if not equal. Short jump. DJNZ Rn,rel DJNZ Rx,rel NOP Decrements register and jumps if not 0. Short jump. Decrements direct byte and jump if not 0. Short jump. No operation Data Transfer Instructions Data transfer instructions move the content of one register to another. The register the content of which is moved remains unchanged. If they have the suffix X (MOVX), the data is exchanged with external memory. Mnemonic Description Byte Cycle MOV A,Rn Moves the register to the accumulator 1 1 MOV A,direct Moves the direct byte to the accumulator 2 2

MOV A,@Ri Moves the indirect RAM to the accumulator 1 2 MOV A,#data Moves the immediate data to the accumulator 2 2 MOV Rn,A Moves the accumulator to the register 1 2 MOV Rn,direct Moves the direct byte to the register 2 4 MOV Rn,#data Moves the immediate data to the register 2 2 MOV direct,a Moves the accumulator to the direct byte 2 3 MOV direct,rn Moves the register to the direct byte 2 3 MOV direct,direct Moves the direct byte to the direct byte 3 4 MOV direct,@ri Moves the indirect RAM to the direct byte 2 4 MOV direct,#data Moves the immediate data to the direct byte 3 3 MOV @Ri,A Moves the accumulator to the indirect RAM 1 3 MOV @Ri,direct Moves the direct byte to the indirect RAM 2 5 MOV @Ri,#data Moves the immediate data to the indirect RAM 2 3 MOV DPTR,#data Moves a 16-bit data to the data pointer 3 3 MOVC Moves the code byte relative to the DPTR to the accumulator 1 3 A,@A+DPTR (address=a+dptr) MOVC A,@A+PC Moves the code byte relative to the PC to the accumulator 1 3 (address=a+pc) MOVX A,@Ri Moves the external RAM (8-bit address) to the accumulator 1 3-10 MOVX A,@DPTR Moves the external RAM (16-bit address) to the accumulator 1 3-10 MOVX @Ri,A Moves the accumulator to the external RAM (8-bit address) 1 4-11 MOVX @DPTR,A Moves the accumulator to the external RAM (16-bit address) 1 4-11 PUSH direct Pushes the direct byte onto the stack 2 4

POP direct Pops the direct byte from the stack/td> 2 3 XCH A,Rn Exchanges the register with the accumulator 1 2 XCH A,direct Exchanges the direct byte with the accumulator 2 3 XCH A,@Ri Exchanges the indirect RAM with the accumulator 1 3 XCHD A,@Ri Exchanges the low-order nibble indirect RAM with the 1 3 accumulator Logic Instructions Logic instructions perform logic operations upon corresponding bits of two registers. After execution, the result is stored in the first operand. Mnemonic Description Byte Cycle ANL A,Rn AND register to accumulator 1 1 ANL A,direct AND direct byte to accumulator 2 2 ANL A,@Ri AND indirect RAM to accumulator 1 2 ANL A,#data AND immediate data to accumulator 2 2 ANL direct,a AND accumulator to direct byte 2 3 ANL direct,#data AND immediae data to direct register 3 4 ORL A,Rn OR register to accumulator 1 1 ORL A,direct OR direct byte to accumulator 2 2 ORL A,@Ri OR indirect RAM to accumulator 1 2 ORL direct,a OR accumulator to direct byte 2 3 ORL direct,#data OR immediate data to direct byte 3 4 XRL A,Rn Exclusive OR register to accumulator 1 1

XRL A,direct Exclusive OR direct byte to accumulator 2 2 XRL A,@Ri Exclusive OR indirect RAM to accumulator 1 2 XRL A,#data Exclusive OR immediate data to accumulator 2 2 XRL direct,a Exclusive OR accumulator to direct byte 2 3 XORL direct,#data Exclusive OR immediate data to direct byte 3 4 CLR A Clears the accumulator 1 1 CPL A Complements the accumulator (1=0, 0=1) 1 1 SWAP A Swaps nibbles within the accumulator 1 1 RL A Rotates bits in the accumulator left 1 1 RLC A Rotates bits in the accumulator left through carry 1 1 RR A Rotates bits in the accumulator right 1 1 RRC A Rotates bits in the accumulator right through carry 1 1 Bit-oriented Instructions Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is that these are performed upon single bits. Mnemonic Description Byte Cycle CLR C Clears the carry flag 1 1 CLR bit Clears the direct bit 2 3 SETB C Sets the carry flag 1 1 SETB bit Sets the direct bit 2 3 CPL C Complements the carry flag 1 1 CPL bit Complements the direct bit 2 3

ANL C,bit AND direct bit to the carry flag 2 2 ANL C,/bit AND complements of direct bit to the carry flag 2 2 ORL C,bit OR direct bit to the carry flag 2 2 ORL C,/bit OR complements of direct bit to the carry flag 2 2 MOV C,bit Moves the direct bit to the carry flag 2 2 MOV bit,c Moves the carry flag to the direct bit 2 3 Q. Give any four examples for program control flow instructions and explain. Sol: There are two kinds of program control flow instructions: Unconditional jump instructions: upon their execution a jump to a new location from where the program continues execution is executed. Conditional jump instructions: a jump to a new program location is executed only if a specified condition is met. Otherwise, the program normally proceeds with the next instruction. 1. ACALL addr11 Absolute subroutine call The ACALL instruction calls a subroutine located at the specified address. The PC is incremented twice to obtain the address of the following instruction. The 16-bit PC is then stored on the stack (low-order byte first) and the stack pointer is incremented twice. No flags are affected. The address of the subroutine is calculated by combining the 5 high-order bits of the incremented PC (for A15-A11), the 3 high-order bits of the ACALL instruction opcode (for A10-A8), and the second byte of the instruction (for A7-A0). The subroutine that is called must be located in the same 2KByte block of program memory as the opcode following the ACALL instruction.

2. LCALL addr16 Long subroutine call The LCALL instruction calls a subroutine located at the specified address. This instruction first adds 3 to the PC to generate the address of the next instruction. This result is pushed onto the stack low-byte first and the stack pointer is incremented by 2. The high-order and low-order bytes of the PC are loaded from the second and third bytes of the instruction respectively. Program execution is transferred to the subroutine at this address. No flags are affected by this instruction. 3. RET Returns from subroutine The RET instruction pops the high-order and low-order bytes of the PC from the stack (and decrements the stack pointer by 2). Program execution resumes from the resulting address which is typically the instruction following an ACALL or LCALL instruction. No flags are affected by this instruction.

4. RETI Returns from interrupt subroutine The RETI instruction is used to end an interrupt service routine. This instruction pops the high-order and low-order bytes of the PC (and decrements the stack pointer by 2) and restores the interrput logic to accept additional interrupts. No other registers are affected by this instruction. The RETI instruction does not restore the PSW to its value before the interrupt. The interrupt service routine must save and restore the PSW. Execution returns to the instruction immediately after the point at which the interrupt was detected. If another interrupt was pending when the RETI instruction is executed, one instruction at the return address is executed before the pending interrupt is processed. RETI Bytes Cycles Encoding Operation Example 1 2 00110010 RETI PC 15-8 = (SP) SP = SP - 1 PC 7-0 = (SP) SP = SP - 1 RETI Q. Write in detail about the instruction SJMP.

Sol: The SJMP instruction encodes the destination address as a relative offset. The instruction is 2 bytes long, consisting of the opcode and relative offset byte. SJMP rel Short jump (from 128 to +127 locations relative to the following instruction)