instruction set 8085

Upload: toswaroop

Post on 10-Oct-2015

48 views

Category:

Documents


0 download

TRANSCRIPT

  • Assembly Language Programming of 8085

  • TopicsIntroductionProgramming model of 8085Instruction set of 8085Example ProgramsAddressing modes of 8085Instruction & Data Formats of 8085

  • 1. IntroductionA microprocessor executes instructions given by the user Instructions should be in a language known to the microprocessorMicroprocessor understands the language of 0s and 1s onlyThis language is called Machine Language

  • For e.g.01001111Is a valid machine language instruction of 8085It copies the contents of one of the internal registers of 8085 to another

  • A Machine language program to add two numbers

    00111110;Copy value 2H in register A0000001000000110;Copy value 4H in register B0000010010000000;A = A + B

  • Assembly Language of 8085It uses English like words to convey the action/meaning called as MNEMONICSFor e.g.MOV to indicate data transferADD to add two valuesSUB to subtract two values

  • Assembly language program to add two numbers

    MVI A, 2H;Copy value 2H in register AMVI B, 4H;Copy value 4H in register BADD B;A = A + B

    Note:Assembly language is specific to a given processorFor e.g. assembly language of 8085 is different than that of Motorola 6800 microprocessor

  • Microprocessor understands Machine Language only!Microprocessor cannot understand a program written in Assembly languageA program known as Assembler is used to convert a Assembly language program to machine language

    AssemblyLanguageProgramAssemblerProgramMachine Language Code

  • Low-level/High-level languagesMachine language and Assembly language are both Microprocessor specific (Machine dependent)so they are calledLow-level languagesMachine independent languages are calledHigh-level languagesFor e.g. BASIC, PASCAL,C++,C,JAVA, etc.A software called Compiler is required to convert a high-level language program to machine code

  • 2. Programming model of 808516-bit Address Bus8-bit Data Bus

    Control Bus

  • 16- LinesUnidirectional8- LinesBidirectional

    Accumulator (8-bit)Flag Register (8-bit)B (8-bit)C (8-bit)D (8-bit)E (8-bit)H (8-bit)L (8-bit)Stack Pointer (SP) (16-bit)Program Counter (PC) (16-bit)

    S ZACPCY

  • Overview: 8085 Programming model Six general-purpose RegistersAccumulator RegisterFlag RegisterProgram Counter RegisterStack Pointer Register

  • Six general-purpose registersB, C, D, E, H, LCan be combined as register pairs to perform 16-bit operations (BC, DE, HL)Accumulator identified by name AThis register is a part of ALU8-bit data storagePerforms arithmetic and logical operationsResult of an operation is stored in accumulator

  • Flag RegisterThis is also a part of ALU8085 has five flags namedZero flag (Z)Carry flag (CY)Sign flag (S)Parity flag (P)Auxiliary Carry flag (AC)

  • These flags are five flip-flops in flag registerExecution of an arithmetic/logic operation can set or reset these flagsCondition of flags (set or reset) can be tested through software instructions8085 uses these flags in decision-making process

  • Program Counter (PC)A 16-bit memory pointer registerUsed to sequence execution of program instructionsStores address of a memory locationwhere next instruction byte is to be fetched by the 8085when 8085 gets busy to fetch current instruction from memoryPC is incremented by onePC is now pointing to the address of next instruction

  • Stack Pointer Registera 16-bit memory pointer registerPoints to a location in Stack memoryBeginning of the stack is defined by loading a 16-bit address in stack pointer register

  • 3.Instruction Set of 8085Consists of74 operation codes, e.g. MOV246 Instructions, e.g. MOV A,B8085 instructions can be classified asData Transfer (Copy) ArithmeticLogical and Bit manipulationBranchMachine Control

  • 1. Data Transfer (Copy) OperationsLoad a 8-bit number in a RegisterCopy from Register to RegisterCopy between Register and MemoryCopy between Input/Output Port and AccumulatorLoad a 16-bit number in a Register pairCopy between Register pair and Stack memory

  • Example Data Transfer (Copy) Operations / InstructionsLoad a 8-bit number 4F in register BCopy from Register B to Register ALoad a 16-bit number 2050 in Register pair HLCopy from Register B to Memory Address 2050Copy between Input/Output Port and Accumulator

    MVI B, 4FH

    MOV A,B

    LXI H, 2050H

    MOV M,B

    OUT 01HIN 07H

  • 2. Arithmetic OperationsAddition of two 8-bit numbersSubtraction of two 8-bit numbersIncrement/ Decrement a 8-bit number

  • Example Arithmetic Operations / InstructionsAdd a 8-bit number 32H to AccumulatorAdd contents of Register B to AccumulatorSubtract a 8-bit number 32H from AccumulatorSubtract contents of Register C from AccumulatorIncrement the contents of Register D by 1Decrement the contents of Register E by 1ADI 32H

    ADD B

    SUI 32H

    SUB C

    INR D

    DCR E

  • 3. Logical & Bit Manipulation OperationsAND two 8-bit numbersOR two 8-bit numbersExclusive-OR two 8-bit numbersCompare two 8-bit numbersComplement Rotate Left/Right Accumulator bits

  • Example Logical & Bit Manipulation Operations / InstructionsLogically AND Register H with AccumulatorLogically OR Register L with AccumulatorLogically XOR Register B with AccumulatorCompare contents of Register C with AccumulatorComplement AccumulatorRotate Accumulator LeftANA H

    ORA L

    XRA B

    CMP C

    CMA

    RAL

  • 4. Branching OperationsThese operations are used to control the flow of program executionJumpsConditional jumpsUnconditional jumpsCall & ReturnConditional Call & ReturnUnconditional Call & Return

  • Example Branching Operations / InstructionsJump to a 16-bit Address 2080H if Carry flag is SETUnconditional JumpCall a subroutine with its 16-bit Address Return back from the CallCall a subroutine with its 16-bit Address if Carry flag is RESETReturn if Zero flag is SET

    JC 2080H

    JMP 2050H

    CALL 3050H

    RET

    CNC 3050H

    RZ

  • 5. Machine Control InstructionsThese instructions affect the operation of the processor. For e.g.HLTStop program executionNOPDo not perform any operation

  • 4. Writing a Assembly Language Program

    Steps to write a programAnalyze the problemDevelop program LogicWrite an AlgorithmMake a FlowchartWrite program Instructions using Assembly language of 8085

  • Program 8085 in Assembly language to add two 8-bit numbers and store 8-bit result in register C.Analyze the problemAddition of two 8-bit numbers to be doneProgram LogicAdd two numbersStore result in register CExample 10011001 (99H) A+00111001 (39H) D 11010010 (D2H) C

  • Get two numbers

    Add them

    Store result

    Stop

    Load 1st no. in register DLoad 2nd no. in register E3. AlgorithmTranslation to 8085 operations Copy register D to AAdd register E to ACopy A to register C

    Stop processing

  • 4. Make a FlowchartStartLoad Registers D, E Copy D to AAdd A and ECopy A to CStopLoad 1st no. in register DLoad 2nd no. in register ECopy register D to AAdd register E to ACopy A to register C

    Stop processing

  • 5. Assembly Language ProgramGet two numbers

    Add them

    Store result

    Stop

    Load 1st no. in register DLoad 2nd no. in register ECopy register D to AAdd register E to ACopy A to register CStop processing

    MVI D, 2HMVI E, 3HMOV A, DADD EMOV C, A

    HLT

  • Program 8085 in Assembly language to add two 8-bit numbers. Result can be more than 8-bits.Analyze the problemResult of addition of two 8-bit numbers can be 9-bitExample 10011001 (99H) A+10011001 (99H) B100110010 (132H)The 9th bit in the result is called CARRY bit.

  • 0How 8085 does it?Adds register A and BStores 8-bit result in ASETS carry flag (CY) to indicate carry bit

    1001100110011001AB+99H99H10011001A1CY0011001099H32H

  • Storing result in Register memory10011001A32H1CYRegister CRegister BStep-1 Copy A to CStep-2 Clear register BIncrement B by 1

  • 2. Program LogicAdd two numbersCopy 8-bit result in A to CIf CARRY is generatedHandle itResult is in register pair BC

  • Load two numbers in registers D, E

    Add them

    Store 8 bit result in CCheck CARRY flagIf CARRY flag is SETStore CARRY in register BStop

    Load registers D, E3. AlgorithmTranslation to 8085 operations Copy register D to AAdd register E to ACopy A to register C

    Stop processing

    Use Conditional Jump instructionsClear register BIncrement BCopy A to register C

  • 4. Make a FlowchartStartLoad Registers D, E Copy D to AAdd A and ECopy A to CStopIf CARRYNOT SETClear BIncrement BFalseTrue

  • 5. Assembly Language ProgramMVI D, 2HMVI E, 3HMOV A, DADD EMOV C, A

    HLTLoad registers D, ECopy register D to AAdd register E to ACopy A to register C

    Stop processing

    Use Conditional Jump instructionsClear register BIncrement BCopy A to register C

    JNC ENDMVI B, 0HINR BEND:

  • 4. Addressing Modes of 8085Format of a typical Assembly language instruction is given below-[Label:] Mnemonic [Operands] [;comments] HLT MVI A, 20H MOV M, A ;Copy A to memory location whose address is stored in register pair HL LOAD: LDA 2050H ;Load A with contents of memory location with address 2050H READ: IN 07H ;Read data from Input port with address 07H

  • The various formats of specifying operands are called addressing modesAddressing modes of 8085Register AddressingImmediate AddressingMemory AddressingInput/Output Addressing

  • 1. Register AddressingOperands are one of the internal registers of 8085Examples-MOV A, BADD C

  • 2. Immediate AddressingValue of the operand is given in the instruction itselfExample-MVI A, 20HLXI H, 2050HADI 30HSUI 10H

  • 3. Memory AddressingOne of the operands is a memory locationDepending on how address of memory location is specified, memory addressing is of two typesDirect addressingIndirect addressing

  • 3(a) Direct Addressing16-bit Address of the memory location is specified in the instruction directlyExamples-LDA 2050H ;load A with contents of memory location with address 2050HSTA 3050H ;store A with contents of memory location with address 3050H

  • 3(b) Indirect AddressingA memory pointer register is used to store the address of the memory locationExample-MOV M, A ;copy register A to memory location whose address is stored in register pair HL30HA20HH50HL30H2050H

  • 4. Input/Output Addressing8-bit address of the port is directly specified in the instructionExamples-IN 07HOUT 21H

  • 5. Instruction & Data Formats8085 Instruction set can be classified according to size (in bytes) as1-byte Instructions2-byte Instructions3-byte Instructions

  • 1. One-byte InstructionsIncludes Opcode and Operand in the same byteExamples-

    OpcodeOperandBinary CodeHex CodeMOVC, A0100 11114FHADDB1000 000080HHLT0111 011076H

  • 1. Two-byte InstructionsFirst byte specifies Operation CodeSecond byte specifies OperandExamples-

    OpcodeOperandBinary CodeHex CodeMVIA, 32H0011 11100011 00103EH32HMVIB, F2H0000 01101111 001006HF2H

  • 1. Three-byte InstructionsFirst byte specifies Operation CodeSecond & Third byte specifies OperandExamples-

    OpcodeOperandBinary CodeHex CodeLXIH, 2050H0010 00010101 00000010 000021H50H20HLDA3070H0011 10100111 00000011 00003AH70H30H