EC2312-MM-2-16M.pdf

download EC2312-MM-2-16M.pdf

of 5

Transcript of EC2312-MM-2-16M.pdf

  • 8/10/2019 EC2312-MM-2-16M.pdf

    1/5

    UNIT 2 Programming of 8085 Micro processor

    1. Explain in details the instruction set for 8085?

    The instruction Set for 8085 can be given as Arithmetico Involves all the arithmetic executable functions in 8085o It affects the flagso Eg - ADD, SUB, INR, DCR

    Logicalo Involves all the logical executable functions in 8085o It affects the flagso Eg ORA, ANA, XOR

    Data transfero It involves moving of data from one memory space to anothero It does not affect any flagso Eg MOV, XCHG, XTHL

    Branchingo It involves JMP instructions that transfer the flow of operation from one address to anothero It does not affect any flagso Eg JZ 16 bit address, JNZ 16 bit address, JC 16 bit address, JNC 16 bit address

    Machine related, I/Oo It involves hardware related instructionso It does not affect the flago Eg NOP (No operation), HLT (Halt)

    Additionalo It involves other instructions like DI (Disable Interrupts), EI (Enable Interrupts), SIM (Set Interrupt

    Mask), RIM (Read Interrupt Mask)o It does not affect the flags

    2. Explain in details the addressing modes for 8085?

    Addressing Modes in 8085 -

    In the instruction format in 8085, the first part contains the instruction (opcode) itself. That is for example MOVA,B. The second part contains the data. That is for example MOV A,B. The manner in which this data is addressed isgiven by the addressing Modes. There are 5 different addressing modes that are given as -

    Immediate Addressing-o Data is given in a immediate fashion to the instructiono Hence if the data is 8 bit data, then its a 2 byte instruction. If the data is a 16 bit data, then its a

    3 byte instructiono Eg MVI A, 08

    Register Addressingo Registers are used for data passing to the instruction

  • 8/10/2019 EC2312-MM-2-16M.pdf

    2/5

    o Usually its a one byte instruction .o Eg MOV A,B

    Direct Addressingo The address where the data is stored to directly referred to in the instructiono Usually it is a 3 byte instruction.o

    Eg LDA 4400 Indirect Addressingo The required data is stored in a given address. The given address is stored in the HL register pair.

    This HL register pair is used in the instruction.o Usually its a 1 byte instruction. o MOV A,M

    Implicit Addressingo The address is not directly mentioned in the instruction. It is understood.o Eg XCHG (data is exchanged between HL and DE registers)o Usually its a 1 byte instruction.

    3. Explain in Detail looping with clear examples?

    Loops in programming:

    Some instructions need to be repeated again and again for the execution of a program. This is done sowith the help of loops.

    Loops are executed by conditional instructions that are repeated until the condition is satisfied. Eg- JC 16 bit address jumps when there is carry. JNC 16 bit address jumps when there is no carry. All the flags ie Zero, Sign, Parity, and Carry are used in JMP statements as conditions. Multiplication can be implemented as a loop of additions. Division can be implemented as a loop of

    subtractions. Loops can be used to execute programs such as arranging=g numbers in ascending or descending order by

    repeated CMP (comparison operations.)

    The logic of Multiplication and its Mnemonic are as follows.o Accumulator is initialized as zero to store the answer. The 2 numbers to be multiplied are stored

    in B and D. A=0; B = 4; D = 3.

    o Loop1 A + B A that is 0 + 4 4 D D 1 that is D is decremented from 3 to 2.

    JNC (Jump no zero) flag is checked. It is not set. Hence the loop is repeated.o Loop 2

    A + B A that is 4 + 4 8 D D 1 that is D is decremented from 2 to 1.

    JNC (Jump no zero) flag is checked. It is not set. Hence the loop is repeated.

  • 8/10/2019 EC2312-MM-2-16M.pdf

    3/5

    o Loop 3

    A + B A that is 8 + 4 12 D D 1 that is D is decremented from 1 to 0.

    JNC (Jump no zero) flag is checked. It is set. Because D has become 0. Hence the execution comes out ofthe loop..

    The Mnemonics for the program are given as-

    MVI A,00

    MVI B,04

    MVI D, 03

    L 1 - ADD B

    DCR DJNZ L1

    STA 4500

    HLT

    The logic of Division and its Mnemonics are as follows.o Accumulator is initialized to store the higher number (eg -15). The second number is stored in B

    (eg -4). D register is initialized to 00 to store the answer A=0; B = 4; D = 3.

    o Loop1

    A B A that is 15 4 11 D D + 1 that is D is incremented from 0 to 1.CMP Flag is used to check whether A > B. If yes, Carry flag is not set. Then the loop must be repeated.

    o Loop2 A B A that is 11 4 7 D D + 1 that is D is incremented from 1 to 2.

    CMP Flag is used to check whether A > B. If yes, Carry flag is not set. Then the loop must be repeated.o Loop3

    A B A that is 7 4 3 D D + 1 that is D is incremented from 2 to 3.

    CMP Flag is used to check whether A > B. Now B is greater than A. Hence the division is over. The loop is

    terminated. Now D has the answer. A has the reminder.

    The Mnemonics for division are given as

    MVI A,15

    MVI B,04

    L1 SUB B

  • 8/10/2019 EC2312-MM-2-16M.pdf

    4/5

    INR D

    CMP B

    JNC L1

    STA 4400

    HLT

    4. Write short notes on Stacks.

    Stacks:

    Memory space allocated for temporary storage of data Works in LIFO concept (Last In First Out) Grows backwards into the memory The size of the stack is limited only by the available memory 8085 has 2 instructions for stack operation

    o PUSH - Information is stored into the stack by pushing into it. Works in a decrement and then store fashion

    o POP - Information is retrieved by popping it off. Works in a use and then Increment style

    o Both PUSH and POP work with register pair onlyo PUSH & POP instructions must be given opposite of each other.

    Eg PUSH C, PUSH D must be followed by POP D, POP C Stack Pointer (SP) always point to the top of the stack In 8085, PSW (Processor Status Word) Register Pair can be pushed into the stack and then popped after

    completion of any operations.o The contents of the accumulator and the flags are returned to the state they were before the

    execution of the operations

    5. Write short notes on subroutines.

    Subroutines-

    A group of instructions that will be used repeatedly in different locations of the programo Hence to avoid using the same lines again and again, they are grouped into a subroutine and

    called from different locations In assembly language, a sub routine can exist anywhere in the code. For ease of use, it is usually placed

    separately from the main program. 8085 has 2 instructions that deal with subroutines-

    o CALL is used to direct the execution to the subroutine When CALL is used, the processor understands that the next 2 memory locationscontain 16 bit address of the subroutine.

    o RET is used to return the execution to the main routine When return is used, the processor pops the return address from the stack and returns

    to the main program Number of push and POP used in the subroutine must be same and used in opposite order, else RET will

    pick wrong value of the return address from the stack and the program will fail.

  • 8/10/2019 EC2312-MM-2-16M.pdf

    5/5

    A proper subroutine haso A single entry pointo A single exist pointo Is entered with a CALL & existed with a RTE

    CALL and RET statements can be used in a conditional format with carry, parity, sign and zero flags.o

    CC Call subroutine if carry flag is seto CNC Call subroutine if carry flag is not seto RC Return from subroutine if carry flag is seto RNC Return from subroutine if carry flag is not set.