Showing posts with label 8085. Show all posts
Showing posts with label 8085. Show all posts

8085 ALP: ASCENDING ORDER in a block of DATA

  • Suppose, there is an array of ten 8-bit data stored in memory addresses from 2030h to 2039h.
  • Starting from 2030h, we compare the data of the first location with that of the second location.
  • If the data of the first location is greater than that of the second location, they are swapped.
  • Running external loop for 9 times, 8 times, 7 times and so on, we run every internal loop as 9 times, 8 times, 7 times and so on for every corresponding external loop. For e.g. for external loop 9, we run respective internal loop 9 times.
  • Doing so, after every external loop, the largest number will be at the last memory location.
MVI C, 09h
AGAIN: MOV D, C
LXI H, 2030h
NEXT: MOV A, M
INX H
CMP M
JC SKIP
MOV B, M
MOV M, A
DCX H
MOV M, B
INX H
SKIP: DCR D
JNZ NEXT
DCR C
JNZ AGAIN
HLT

Program to Find the Largest Number in a block of DATA: 8085

  • Suppose, there is an array or block of ten 8-bit data stored from memory address 2030h. And, we have to find out the greatest number among them.
  • What we are going to do here is that we compare every two data from the first location. If the data of first location is greater than that of second location, the latter will be replaced by the former. 
  • In this way, for 10 data, we run this logic 9 times and finally, the maximum number will be at the last location i.e, 2039h.


LXI H, 2030h
MVI C, 09h
AGAIN: MOV A, M
INX H
CMP M
JC SKIP
MOV M, A
SKIP: DCR C
JNZ AGAIN
HLT


Output:

8085 ALP: Division of TWO 16-bit NUMBERS

;SUPPOSE, We are going to divide 2050h by 1630h.
LXI H,0000H
SPHL
;SP holds quotient.
LXI H,2050H
;HL holds the dividend.
LXI B,1630H
;BC holds the divisor.
AGAIN: MOV A,H
CMP D
JC LAST
JZ CHKNXT
JMP DIVIDE
CHKNXT: MOV A,L
CMP C
JNC DIVIDE
JMP LAST
;Up to this, we have compared dividend with divisor.
DIVIDE: INX SP
;Now, HL <- HL - BC = HL + ((complement of BC) + 1)
;HL <- HL + DE + 1
MOV A,B
CMA
MOV D,A
MOV A,C
CMA
MOV E,A
INX D
DAD HL
;Finally, HL holds the remainder.
JMP AGAIN
LAST: HLT

8085 ALP: Separate a 8-bit data into two NIBBLES

In 8-bit data, there are two nibbles. Nibble is of 4-bit. Here, we take 6BH as a 8-bit data which is separated into two nibbles 06H and 0BH and stored at 2030h and 2031h respectively.

MVI A,6Bh
MOV C,A
ANI 0Fh
STA 2030h ;0Bh is stored.
MOV A,C
ANI F0h
RRC
RRC
RRC
RRC
STA 2031h ;06h is stored.
HLT

8085 ALP: Finding the SQUARE ROOT of a Number

MVI B,01h
MVI C,01h
LDA 2030h
;Suppose the number is located at 2030h
AGAIN: SUB B
JZ LAST
INR B
INR B
INR C
JMP AGAIN
LAST: MOV A,C
STA 2031h
;the square root is stored at 2031h
HLT

Addressing Modes of 8085 Microprocessor

Instruction
  • Instruction is a command or information given to the MP to perform a given specific task on specified data.
  • Each instruction has two parts: one the task to be performed and the other is data to be operated.
  • The code which specifies what operation to be performed is called operation code or opcode.
  • The data on which operation is performed is called operand.
        E.g. ADD B
        ADD is opcode and B is operand.
  • The complete instruction is combination of opcode and operand.
Addressing Modes
  • Each instruction performs an operation on the specified data. An operand must be specified for an instruction to be executed. The operand may be in the general purpose registers, accumulator or a memory location.
  • The method in which the operand is specified in an instruction is called addressing mode.
  • The various modes used in 8085 microprocessor are:

Pin Configuration of 8085 Microprocessor

Properties 
  • Single + 5V Supply
  • 4 Vectored Interrupts (One is Non Maskable)
  • Serial In/Serial Out Port
  • Decimal, Binary, and Double Precision Arithmetic
  • Direct Addressing Capability to 64K bytes of memory 
The Intel 8085 is a new generation, complete 8-bit parallel central processing unit (CPU). The 8085 uses a multiplexed data bus. The address is split between the 8-bit address bus and the 8-bit data bus.
Fig: 8085 Pin Diagram 

Functional Block Diagram of 8085 Microprocessor

Fig: Functional Block Diagram of 8085 Microprocessor

1. ALU
  • The ALU performs the actual numerical and logic operation such as ‘add’, ‘subtract’, ‘AND’, ‘OR’ etc.
  • Uses data from memory and from Accumulator to perform arithmetic operation and always stores result of operation in Accumulator.
  • The ALU consists of accumulator, flag register and temporary register.
    a. Accumulator
  • The accumulator is an 8-bit register that is a part of arithmetic/logic unit (ALU). This register is used to store 8-bit data and to perform arithmetic and logical operations. The result of an operation is stored in the accumulator.
  • The accumulator is also identified as register A.
    b. Flag register
  • 8085 has 8-bit flag register. There are only 5 active flags.
S
Z

AC

P

CY
Fig: 8085 flag register

8085 Interrupt Pins and Interrupt Priority

There are five interrupt pins in 8085 and one interrupt acknowledge (INTA) pin.
  • Pin 6 to pin 10 interrupts have the priorities from highest to lowest in decreasing order. 
  • Priority means which interrupt gets the acknowledgement first if more than one are interrupting the microprocessor. 
Maskable and Non-Maskable Interrupt 

Maskable interrupts: An interrupt which can be disabled by software that means we can disable the interrupt by sending appropriate instruction, is called a maskable interrupt. 

RST 7.5, RST 6.5, and RST 5.5 are the examples of Maskable Interrupt. 

Non-Maskable interrupts: As name suggests we cannot disable the interrupt by sending any instruction is called Non Maskable Interrupt. TRAP interrupt is the non-maskable interrupt for 8085. It means that if an interrupt comes via TRAP, 8085 will have to recognize the interrupt we cannot mask it.

Interrupt

  • Interrupt is a process where an external device can get the attention of the microprocessor. The process starts from the I/O device. An interrupt is considered to be an emergency signal that may be serviced. The Microprocessor may respond to it as soon as possible.
  • When the Microprocessor receives an interrupt signal, it suspends the currently executing program and jumps to an Interrupt Service Routine (ISR) to respond to the incoming interrupt. Each interrupt will most probably have its own ISR.
  • Responding to an interrupt may be immediate or delayed depending on whether the interrupt is maskable or non-maskable and whether interrupts are being masked or not. There are two ways of redirecting the execution to the ISR depending on whether the interrupt is vectored or non-vectored.
 Vector Interrupt: In this type of interrupt, Processor knows the address of Interrupt. In other word processor knows the address of interrupt service routine.
The examples of vector interrupt are RST 7.5, RST 6.5, RST 5.5, TRAP.

Non-Vector Interrupt: In this type of interrupt, Processor cannot know the address of Interrupt. It should give externally. In the device will have to send the address of interrupt service routine to processor for performing Interrupt.
The example of Non-vector interrupt is INTR.
  • When a device interrupts, it actually wants the MP to give a service which is equivalent to asking the MP to call a subroutine. This subroutine is called ISR (Interrupt Service Routine).

8085 Microprocessor :: Machine Control Instructions

i) HLT
Halt and enter wait state. The contents of the registers are unaffected during the HLT state.

ii) NOP
No operation is performed. The instruction is fetched and decoded; however, no operation is executed. The instruction is used to fill in time delays or to delete and insert instructions while troubleshooting.

iii) RIM
Read Interrupt Mask. This is a multipurpose instruction used to read the status of interrupts 7.5, 6.5, 5.5 and to read serial data input bit. The instruction loads 8 bits in the accumulator with the following interpretations:
                              D7         D6            D5             D4              D3              D2             D1             D0
SID
I7
I6
I5
IE
7.5
6.5
5.5

D7=serial input data bit
D6, D5, D4=interrupts pending if bit=1
D3=interrupt enable; flip-flop is set if bit=1
D2, D1, D0=interrupt masked if bit=1
e.g. After the execution of instruction RIM, the accumulator contained 49H. Explain
(A):      49H = 0           1          0          0          1          0          0          1
RST 7.5 is pending.
Interrupt enable flip-flop is set.
RST 7.5 and 6.5 are enabled. RST 5.5 masked.

iv) SIM
Set Interrupt Mask. This is a multipurpose instruction and used to implement the 8085 interrupts (RST 7.5, 6.5, and 5.5) and serial data output. 

The instruction interprets the accumulator contents as follows: 
                             D7          D6             D5             D4             D3             D2             D1              D0
SOD
SDE
xxx
R7.5
MSE
M7.5
M6.5
M5.5
D7=serial output data
D6=serial data enable (1=enable and 0=disable)
D4=if 1, reset RST 7.5 flip-flop
D3=if 1, mask set enable
D2, D1, D0=masks interrupts if bits=1

  • SOD – Serial Output Data: Bit D7 of the accumulator is latched into the SOD output line and made available to a serial peripheral if bit D6=1. 
  • SDE – Serial Data Enable: If this bit = 1, it enables the serial output. To implement serial output, this bit needs to be enabled. 
  • XXX – Don’t care. 
  • R7.5 – Reset RST 7.5: If this bit = 1, RST 7.5 flip-flop is reset. This is an additional control to reset RST 7.5. 
  • MSE – Mask Set Enable: If this bit is high, it enables the functions of bits D2, D1, D0. This is a master control over all the interrupt masking bits. If this bit is low, bits D2, D1, and D0 do not have any effect on the masks. 
  • M7.5 – D2 = 0, RST 7.5 is enabled. 
                             = 1, RST 7.5 is masked or disabled. 
  • M6.5 – D1 = 0, RST 6.5 is enabled. 
                             = 1, RST 6.5 is masked or disabled. 
  • M5.5 – D0 = 0, RST 5.5 is enabled. 
                             = 1, RST 5.5 is masked or disabled.

8085 Microprocessor :: Miscellaneous Instructions

i) PUSH
  • Syntax: PUSH reg. pair
  • e.g. PUSH B
Before instruction
B=32, C=57
SP=2099
After instruction
M [2097]=57
M [2098]=32
SP=2097

ii) POP
  • Syntax: POP reg. pair
  • e.g. POP H
Before instruction
SP=2090
M [2090]=F5
M [2091]=01
After instruction
H=01
L=F5
SP=2092
iii) EI
  • Enabling interrupts
iv) DI
  • Disabling interrupts
v) PCHL
  • The contents of registers H and L are copied to the program counter.
vi) SPHL
  • The contents of registers H and L are copied to the stack pointer register.
vii) XTHL
  • Exchange H and L with Top of Stack

8085 Microprocessor :: Branching Instructions

a) Jump Instructions
    i) Unconditional Jump
        The program sequence is transferred to the memory location specified by the 16-bit address without checking any condition.
  • Syntax: JMP 16-bit address
  • e.g. JMP 8085
    ii) Conditional Jump
Op-code
Description
Flag status
JC
Jump on carry
CY=1
JNC
Jump on no carry
CY=0
JP
Jump on positive
S=0
JM
Jump on minus
S=1
JPE
Jump on even parity
P=1
JPO
Jump on odd parity
P=0
JZ
Jump on zero
Z=1
JNZ
Jump on non-zero
Z=0

b) Call Instructions / Return Instructions
    i) Unconditional call/return
Syntax: CALL 16-bit address
              :
              :
              :
             RET

    ii) Conditional call/return
Op-code
Description
Flag status
CC/RC
Call/Return on carry
CY=1
CNC/RNC
Call/Return on no carry
CY=0
CP/RP
Call/Return on positive
S=0
CM/RM
Call/Return on minus
S=1
CPE/RPE
Call/Return on even parity
P=1
CPO/RPO
Call/Return on odd parity
P=0
CZ/RZ
Call/Return on zero
Z=1
CNZ/RNZ
Call/Return on non-zero
Z=0

c) Restart Instructions
    The RST instructions are equivalent to 1-byte call instructions to one of the eight memory locations on page 0. The instructions are generally used in conjunction with interrupts and inserted using external hardware. However, these can be used as software instructions in a program to transfer program execution to one of the eight locations.
Op-code
Restart Address (H)
RST 0
0000
RST 1
0008
RST 2
0010
RST 3
0018
RST 4
0020
RST 5
0028
RST 6
0030
RST 7
0038

8085 Microprocessor :: Logical Instructions

i) ANA
  • Syntax: ANA reg./M
  • e.g. ANA B    ;A<=A/\B
ii) ANI
  • Syntax: ANI 8-bit data
  • e.g. ANI 23H    ;A<=A/\23H
iii) ORA
  • Syntax: ORA Reg./M
  • e.g. ORA B    ;A<=A\/B
iv) ORI
  • Syntax: ORI 8-bit data
  • e.g. ORI 23H    ;A<=A\/23H
v) XRA
  • Syntax: XRA Reg./M
  • e.g. XRA B    ;A<=A⊕B
vi) XRI
  • Syntax: XRI 8-bit data
  • e.g. XRI 23H    ;A<=A⊕23H
vii) CMA
  • e.g. CMA    ;complements the content of accumulator
viii) CMP
Syntax: CMP Reg./M

The contents of the operand (register/memory) are compared with the content of accumulator and both contents are preserved and the comparison is shown by setting the flags.

If A>Reg./M, CY=0, Z=0
If A=Reg./M, CY=0, Z=1
If A<Reg./M, CY=1, Z=0

ix) CPI
Syntax: CPI 8-bit data

If A>data, CY=0, Z=0
If A=data, CY=0, Z=1
If A<data, CY=1, Z=0

x) RLC
Each binary bit of the accumulator is rotated left by one position. Bit D7 is placed in the position of D0 as well as in the carry flag (CY). Other flags are not affected.

Syntax: RLC

Before RLC: 10100111, CY=0
After RLC: 01001111; CY=1

xi) RRC
Syntax: RRC

Before RLC: 10100111, CY=0
After RLC: 11010011; CY=1

xii) RAL
Each binary bit of the accumulator is rotated left by one position through the carry flag (CY). Other flags are not affected.

Syntax: RAL

Before RAL: 10100111, CY=0
After RAL: 01001110; CY=1

xiii) RAR
Each binary bit of the accumulator is rotated right by one position through the carry flag. Other flags are not affected.

Syntax: RAL

Before RAL: 10100111, CY=0
After RAL: 01010011; CY=1

xiv) DAA
Decimal Adjust Accumulator

The contents of accumulator are changed from binary value to two binary-coded decimal (BCD) digits. This is the only instruction that uses the AC flag to perform binary to BCD conversion. All flags are affected.

8085 Microprocessor :: Arithmetic Instructions

i) ADD
Syntax: ADD R/M
  • e.g. ADD B    ;A<=A+B
ii) ADC
Syntax: ADC R/M
  • e.g. ADC B    ;A<=A+B+CY
iii) ADI
Syntax: ADI 8-bit data
  • e.g. ADI 45    ;A<=A+45
iv) ACI
Syntax: ACI 8-bit data
  • e.g. ACI 45    ;A<=A+45+CY
v) SUB
Syntax: SUB R/M
  • e.g. SUB B    ;A<=A-B
vi) SBB
Syntax: SBB R/M
  • e.g. SBB B    ;A<=A-B-CY
vii) SUI
Syntax: SUI 8-bit data
  • e.g. SUI 45 ; A<=A-45
viii) SBI
Syntax: SBI 8-bit data
  • e.g. SBI 45    ;A<=A-45-CY
ix) DAD
Syntax: DAD register pair 
  • ;contents of register pair is added to HL and the sum is saved in HL pair.
  • e.g. DAD B    ;HL<=HL+BC
x) INR
Syntax: INR R/M
  • e.g. INR B    ;B<=B-1
xi) DCR
Syntax: DCR R/M
  • e.g. DCR C    ;C<=C-1
xii) INX
Syntax: INX register pair
  • e.g. INX H    ;HL<=HL+1
xiii) DCX
Syntax: DCX register pair
  • e.g. DCX B    ;BC<=BC-1

8085 Microprocessor :: Data Transfer Instructions

i) MOV
Syntax: MOV Rd, Rs
  • MOV M, Rs
  • MOV Rd, M
ii) MVI
Syntax: MVI Rd/M, 8-bit data

iii) LXI
Syntax: LXI Reg. pair, 16-bit data
  • e.g. LXI B, 8085    ;B<=80, C<=85
iv) LDA
Syntax: LDA 16-bit address
  • e.g. LDA 8085    ;A<=M[8085]
v) STA
Syntax: STA 16-bit address
  • e.g. STA 8085    ;M[8085]<=A
vi) LDAX
Syntax: LDAX B/D register pair
  • e.g. LDAX B    ;A<=M[8050] (if B=80, C=50)
vii) STAX
Syntax: STAX B/D register pair
  • e.g. STAX B    ;M[8050]<=A (if B=80, C=50)
viii) LHLD
Syntax: LHLD 16-bit address
  • e.g. LHLD 8085    ;L<=M[8085], H<=M[8086]
ix) SHLD
Syntax: SHLD 16-bit address
  • e.g. SHLD 8085    ;M[8085]<=L, M[8086]<=H
x) XCHG
Syntax: XCHG ;interchanges between D and H; and E and L
  • H<=D and L<=E
  • D<=H and E<=L
xi) IN
Syntax: IN 8-bit port address
  • e.g. IN 15    ;data received from port address 15 is transferred into Accumulator.
xii) OUT
Syntax: OUT 8-bit port address
  • e.g. OUT 15    ;content of Accumulator is transferred to port address 15.

Differences between 8085 and 8086 Microprocessor

8085
8086
8085 is 8-bit microprocessor
8086 is 16-bit microprocessor
8085 has 16-bit address bus
8086 has 20-bit address bus
Clock speed: 3 MHz
Clock speed can vary between 5, 8 and 10 MHz for three different MP.
8085 can access up to 2^16 = 64 KB of memory
8086 can access up to 2^20 = 1 MB of memory
8085 doesn't have an instruction queue
8086 has instruction queue
8085 does not support pipelined architecture
8086 supports pipelined architecture.
8085 does not support multiprocessing support
8086 supports
8085 can address 2^8 = 256 I/O's
8086 can access 2^16 = 65,536 I/O's
8085 only supports integer and decimal
8086 supports integer, decimal and ASCII arithmetic.
8085 does not support Multiplication and Division
8086 supports.
8085 supports only single operating mode
8086 operates in two modes.
8085 requires less external hardware
8086 requires more external hardware.
The cost of 8085 is low.
The cost of 8086 is high.
In 8085, memory space is not segmented.
In 8086, memory space is segmented.