Sei sulla pagina 1di 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 Arithmetic


o Involves all the arithmetic executable functions in 8085
o It affects the flags
o Eg - ADD, SUB, INR, DCR
Logical
o Involves all the logical executable functions in 8085
o It affects the flags
o Eg ORA, ANA, XOR
Data transfer
o It involves moving of data from one memory space to another
o It does not affect any flags
o Eg MOV, XCHG, XTHL
Branching
o It involves JMP instructions that transfer the flow of operation from one address to another
o It does not affect any flags
o Eg JZ 16 bit address, JNZ 16 bit address, JC 16 bit address, JNC 16 bit address
Machine related, I/O
o It involves hardware related instructions
o It does not affect the flag
o Eg NOP (No operation), HLT (Halt)
Additional
o 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 8085In the instruction format in 8085, the first part contains the instruction (opcode) itself. That is for example MOV
A,B. The second part contains the data. That is for example MOV A,B. The manner in which this data is addressed is
given by the addressing Modes. There are 5 different addressing modes that are given as

Immediate Addressingo Data is given in a immediate fashion to the instruction


o 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 instruction
o Eg MVI A, 08
Register Addressing
o Registers are used for data passing to the instruction

3.

o Usually its a one byte instruction.


o Eg MOV A,B
Direct Addressing
o The address where the data is stored to directly referred to in the instruction
o Usually it is a 3 byte instruction.
o Eg LDA 4400
Indirect Addressing
o 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 Addressing
o 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.

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 so
with 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+BA
that is 0 + 4 4
DD1
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+BA
that is 4 + 4 8
DD1
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.

Loop 3
A+BA
DD1

that is
that is

8 + 4 12
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 of
the loop..

The Mnemonics for the program are given asMVI A,00


MVI B,04
MVI D, 03
L 1 - ADD B
DCR D
JNZ 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
ABA
that is 15 4 11
DD+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
ABA
that is 11 4 7
DD+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
ABA
that is 7 4 3
DD+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

INR D
CMP B
JNC L1
STA 4400
HLT
4.

Write short notes on Stacks.

Stacks:

5.

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 only
o 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

Write short notes on subroutines.

Subroutines

A group of instructions that will be used repeatedly in different locations of the program
o 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 subroutineso CALL is used to direct the execution to the subroutine
When CALL is used, the processor understands that the next 2 memory locations
contain 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.

A proper subroutine has


o A single entry point
o A single exist point
o 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 set
o CNC Call subroutine if carry flag is not set
o RC Return from subroutine if carry flag is set
o RNC Return from subroutine if carry flag is not set.

Potrebbero piacerti anche