Professional Documents
Culture Documents
Language Programming
05/20/23 1
High Level Language
Compiler
Assembly Language
Assembler
Machine Code
Microprocessor Hardware
05/20/23 2
8085A Instruction Set
Data Transfer Instruction
Move data between registers or between memory locations and
registers. Includes moves, loads, stores and exchanges.
Arithmetic Instruction
Adds, Subtracts, Increments, Decrements data in registers or
memory.
Logic Instruction
ANDs, ORs, XORs, compares, rotates or complements data in
registers or between memory and registers.
05/20/23 3
Branch/Jump Instruction
Initiates conditional or unconditional jumps, calls, returns and
restart.
05/20/23 4
Programming Model
8 bit 8 bit
0000H 00H
8 bit 0001H 01H
0002H 02H
A FLAG
0003H 03H
B C
0004H 04H
D E
0005H 05H
H L 0006H 06H
SP
PC
FFFDH FDH
CPU FFFEH FEH
FFFFH FFH
05/20/23 5
MEMORY I/O
Data Transfer
IMMEDIATE DATA TRANSFER
• MVI reg , data8 ;data8 (reg)
• LXI rp ,data16;data16 (rp)
05/20/23 6
Example
MVI A ,10 ;A=0AH
MVI B ,10010001B ;B=91H
MVI D ,7FH ;D=7FH
05/20/23 7
Example
MVI B, 55H
MOV A,B
MOV C,A
MOV H,C
MOV L,A
MOV E,L
HLT
05/20/23 8
DIRECT DATA TRANSFER
• LDA address16
• STA address16
• LHLD address16
• SHLD address16
05/20/23 9
Example
0000H
0001H
• LDA 3000H ..
STORE
(3000H) (A) 2100H x1
A
2101H
x1
2102H
• STA 2100H ..
(A) (2100H) LOAD ..
3000H y1
A
..
y1
3509H
05/20/23 10
Example
0000H
0001H
LHLD 8000H
STORE..
(8000H) (L) L x1 3500H x1
(8000H + 1) (H) H x2 3501H x2
3502H
..
SHLD 3500H LOAD..
(L) (3500H) L y1 8000H y1
(H) (3500H + 1) H y2 8001H y2
3509H
05/20/23 11
INDIRECT DATA TRANSFER
• LDAX B ;pointer is BC register
• LDAX D ;pointer is DE register
• STAX B ;pointer is BC register
• STAX D ;pointer is DE register
• MOV reg , M ;pointer is HL register
• MOV M , reg ;pointer is HL register
• MVI M , data8 ;pointer is HL register
05/20/23 12
Example 0000H
LXI B , 2020H 0001H
MVI A , 88H 0002H
STAX B 0003H
INX B 0004H
LDAX B 0005H
LXI H , 3000H 0006H
MOV D,M
MOV M,A 2020H 88H
B C AAH
2021H
A 88H 20H 20H
D H L 3000H FFH
30H 00H
05/20/23 13
• Instruction INX – increment 0000H
Register pair 0001H
0002H
• BC = 2021H
0003H
0004H
0005H
0006H
2020H 88H
B C AAH
2021H
A AAH 20H 21H
D FFH H L 3000H AAH
30H 00H
05/20/23 14
• Transfer 10 byte data from memory location 3000h
• To memory location 3500h using LDA & STA
0000H
LDA 3000H 0001H
STA 3500H ..
3000H x1
.
3001H x2
. .. ..
LDA 3009H 3009H x10
STA 3509H
..
3500H x1
.. ..
3509H x10
05/20/23 15
• Transfer 10 byte data from memory location 3000h
• To memory location 3500h
0000H
MVI H,10 0001H
LXI B , 3000H ..
LXI D , 3500H 3000H x1
LOOP: LDAX B
STAX D 3001H x2
INX B .. ..
INX D 3009H x10
DCR H ..
JNZ LOOP
3500H x1
HLT
.. ..
3509H x10
05/20/23 16
Arithmetic Operation
• ALU
• FLAG
• CPU REGISTER
05/20/23 17
Arithmetic Instruction
• ADDITION
05/20/23 19
EXAMPLE
• Flag : S = 0 , Z = 0, AC = 1, P = 1,CY = 1
05/20/23 20
SUBTRACTION
05/20/23 21
INCREMENT/DECREMENT
05/20/23 22
Logic Instruction
AND
05/20/23 24
EXCLUSIVE-OR
05/20/23 25
COMPLEMENT THE ACCUMULATOR
• CMA A (A)
( )
A
• CMC ( )CY
(CY)
05/20/23 26
COMPARE
Compare Accumulator With Immediate
Data
• CPI data8 (A) – data8
A < data8/mem CY=1
A = data8/mem Z=1
A > data8/mem CY=0, Z=0
Compare Accumulator With Register/Memory
05/20/23 28
Rotate
05/20/23 29
Rotate
05/20/23 30
Rotate
05/20/23 31
Branch Instruction
Unconditional Jump
• JMP address16
(Byte 3) (Byte 2) (PC)
Conditional Jump
• J Condition address16
If (Condition= true)
(Byte 3) (Byte 2) (PC)
05/20/23 32
Condition
• JZ Z=1 Jump if Zero flag SET
• JNZ Z=0 Jump if Zero flag NOT SET
• JC CY=1 Jump if Carry flag SET
• JNC CY=0 Jump if Carry flag NOT SET
• JM S=1 Jump if Sign flag SET
• JP S=0 Jump if Sign flag NOT SET
• JPE P=1 Jump if Parity flag SET
• JPO P=0 Jump if Parity flag NOT SET
05/20/23 33
Example 1
Check Zero Flag
MVI B, 255
LOOP:DCR B
JNZ LOOP ;if Z == 0 then goto
;LOOP
05/20/23 34
Example 2 – Find the smallest value between
two number
(A) = x1 ; (B) = x2
05/20/23 36
Conditional Call Subroutine
C Condition address16
If (Condition = True)
(PCH) ((SP) –1)
(PCL) ((SP) –2)
(SP) – 2 (SP)
(Byte 3)(Byte 2) (PC)
05/20/23 37
• CZ Z=1 Call if Zero flag SET
• CNZ Z=0 Call if Zero flag NOT SET
• CC CY=1 Call if Carry flag SET
• CNCCY=0 Call if Carry flag NOT SET
• CM S=1 Call if Sign flag SET
• CP S=0 Call if Sign flag NOT SET
• CPE P=1 Call if Parity flag SET
• CPOP=0 Call if Parity flag NOT SET
05/20/23 38
Return From Subroutine
• RET
((SP)) (PCL)
((SP) + 1) (PCH)
(SP) + 2 (SP)
05/20/23 39
Return From Subroutine (Conditional)
• R Condition
If (Condition = True)
((SP)) (PCL)
((SP) + 1) (PCH)
(SP) + 2 (SP)
05/20/23 40
• RZ Z=1 Return if Zero flag SET
• RNZ Z=0 Return if Zero flag NOT SET
• RC CY=1 Return if Carry flag SET
• RNCCY=0 Return if Carry flag NOT SET
• RM S=1 Return if Sign flag SET
• RP S=0 Return if Sign flag NOT SET
• RPE P=1 Return if Parity flag SET
• RPOP=0 Return if Parity flag NOT SET
05/20/23 41
Example
ORG 0000H
LXI SP, 3FF0H ;init Stack Pointer
MVI A, 80H
OUT 83H ;Init 8255, all port as output
REPEAT: MVI A,0
OUT 80H
CALL DELAY ;Call subroutine
MVI A,1
OUT 80H
CALL DELAY ;Call subroutine
JMP REPEAT
05/20/23 42
I/O,Stack, Machine Control
Instruction
Stack Operation
Write The Content of Register Pair Onto
The Stack
• PUSH rp
(reg high) ((SP) –1)
(reg low) ((SP) –2)
(SP) – 2 (SP)
05/20/23 43
Write The Content of Accumulator & Flag
Status Onto The Stack
• PUSH PSW
(A) ((SP) –1)
(Flag) ((SP) –2)
(SP) – 2 (SP)
05/20/23 44
Retreive The Content of Register Pair
From The Stack
• POP rp
((SP)) (reg low)
((SP) + 1) (reg high)
(SP) + 2 (SP)
05/20/23 45
Retreive The Content of Accumulator &
Flag Status From The Stack
• POP PSW
((SP)) (Flag)
((SP) + 1) (A)
(SP) + 2 (SP)
05/20/23 46
STACK OPERATION
Lecture 2
(Revision)
05/20/23 47
How the Stack Works
• The stack is a reserved area of memory. It operates as a last-in
first-out bank of registers.
• The memory locations, which constitute the stack, are used to
store binary information temporarily during program execution.
• The stack can be located anywhere in read/write memory, but is
usually defined such that it neither interferes with the program
memory space or the data memory space.
• The start address of the stack is specified at the initialisation
stage of the program by loading the 16-bit CPU register, called
the stack pointer, with the desired address of the start of the
stack.
– e.g LXI SP, data 16
05/20/23 48
How the Stack Works
• Data from CPU register pairs are stored in the stack area of
memory when the processor executes a push rp instruction.
• The contents of the program counter is automatically stored in
the stack area of memory whenever the processor executes a
call or restart (rst n) instruction.
• Data stored in the stack area of memory are returned to
processor register pairs when the processor executes a pop rp
instruction.
• Data is automatically transferred from the stack area of memory
to the program counter whenever the processor executes a
return (ret) instruction.
05/20/23 49
Writing to the Stack
• To execute the instruction push HL
assuming initial sp contents is 2099
H.
• The stack pointer is decremented
by 1 (sp=2098) and the contents of
H are written to this location.
• The stack pointer is decremented
by 1 (sp=2097) and the contents of
L are written to this location.
05/20/23 50
Reading from the Stack
• To execute the instruction pop BC
assuming initial sp contents is 2097
H.
• The contents of the memory location
at the address specified by the
contents of sp is moved to register C
and sp is incremented.
• The contents of the memory location
at the address specified by the
contents of sp is moved to register B
and sp is incremented.
• Note : When data is read from the
stack the data is read first and then
the stack pointer incremented.
05/20/23 51
Example
Write a program to exchange the contents
of BC register with DE register
Program 1 Program 2
05/20/23 52
Input/Output Operation
Output To Port
• OUT Port_Address
(A) (Port)
05/20/23 53
Example
Input From The Port
Output To Port
MVI A, 01H
OUT 81H ;Write 01H to Port 81H
05/20/23 54
Interrupt
05/20/23 55
NEXT WEEK
ASSEMBLY LANGUAGE
PROGRAMMING
05/20/23 56