Assembly Language Stack and Subroutine
Assembly Language Stack and Subroutine
Mr. DEEPAK P.
Associate Professor
ECE Department
SNGCE
DEEPAK.P
UNIT 2
DEEPAK.P
1/8/14
8085
PROGRAMMING MODEL
DEEPAK.P
3
Overview: 8085
1. Six general-purpose Registers
Programming model
2. Accumulator Register
3. Flag Register
4. Program Counter Register
5. Stack Pointer Register
Programming Model
DEEPAK.P
Programming Model
DEEPAK.P
1/8/14
DEEPAK.P
7
byte
2.First byte specifies Operation Code Second
byte specifies Operand
3.First byte specifies Operation Code Second &
Third byte specifies Operand
1/8/14
ADDRESSING MODES
DEEPAK.P
10
Addressing
Modes
of
The microprocessor has different ways of
8085 the data or operand for the
specifying
instruction.
The various formats of specifying
Addressing Modes of
2)8085
Immediate Addressing Mode:
In this type of addressing mode, immediate
Memory Addressing
One of the operands is a memory location
Depending on how address of memory
Addressing
Modes
of
4) Indirect Addressing Mode: In this type
of8085
addressing mode, the 16bit memory
address is indirectly provided with the
instruction using a register pair
Example: LDAX B
(Load the accumulator with the contents
of the memory location whose address is
stored in the register pair BC)
MOV M, A ;copy register A to memory location
whose address is stored
H
Lin register pair HL
30H
20H
50H
2050H 30H
Addressing
Modes
of
5) Implied Addressing mode: In this type of
8085 mode, No operand (register or
addressing
data) is specified in the instruction.
The operand is inborn to the instruction.
Example: CMA (Complement Accumulator) ,
1/8/14
INSTRUCTION SET
DEEPAK.P
16
Consists of
74 operation codes, e.g. MOV, MVI
246 Instructions, e.g. MOV A,B, MVI A,03
Instruction
MOV
Move
MVIMove Immediate
LDA
Load Accumulator Directly from Memory
STAStore Accumulator Directly in Memory
LHLD
Load Hand L Registers Directly from
Memory
SHLD
Store Hand L Registers Directly in
Memory
LXI Load register pair Immediate
LDAX
Load accumulator indirect
STAX
Store Accumulator In direct
XCHG
Exchange DE pair and HL pair
XTHL
Exchange between HL pair and stack
Instruction
Arithmetic Instructions
ADD
Add to Accumulator
Carry Flag
SUB
Arithmetic Instructions
SBB
Borrow
INR
Arithmetic Instructions
Logical Instructions
ANA
ANI
ORA
ORI
XRA
Accumulator
XRI
Exclusive OR Using Immediate Data
CMP
Compare
CPI
Compare Using Immediate Data
Logical Instructions
RLC
RRC
RAL
RAR
CMA
CMC
STC
Logical Instructions
Logical Instructions
Logical Instructions
Logical Instructions
Branching Instructions
The unconditional branching instructions are
as follows:
JMP Jump
CALL
Call
RET
Return
Conditional branching instructions
jumps
Calls Returns
JC CC
RC (Carry)
JNC
CNC RNC (No Carry)
JZ CZ
RZ (Zero)
JNZ
CNZ RNZ (Not Zero)
Branching Instructions
JP
JM
JPE
Even)
JPO
(Parity Odd)
PCHL
Counter
RST
Used with
CP
CM
CPE
RP (Plus)
RM (Minus)
RPE (Parity
CPO
RPO
Jump Instructions
Call Instructions
Return Instructions
Re start Instructions
the Stack
POP
Pop Two Bytes of Data off
the Stack
XTHL
Exchange Top of Stack with
Hand L
SPHL
Move contents of Hand L to
Stack Pointer
The I/O instructions are as follows:
IN
Initiate Input Operation
OUT
Initiate Output Operation
follows:
EI
DI
HLT
NOP
4/8/14
ASSEMBLY LANGUAGE
PROGRAMMING
DEEPAK.P
41
Programming
1. Write an assembly program to add two
numbers
o
o
o
o
o
o
MVI D, 02BH
MVI C, 06FH
MOV A, C
ADD D
STA 4500
HLT
Program
1. Write an assembly program to add two
numbers
o
o
o
o
o
o
LXI H, 4500
MOV A, M
INX H
ADD M
STA 4500
HLT
Program
2. Write an Assembly Language Program to
add two numbers ; results contain carry
LOOP1
LXI H, 4500
MOV A, M
INX H
ADD M
JNC LOOP 1
INR C
STA 4500
MOV A, C
STA 4501
HLT
Program
2. Write an Assembly Language Program to
add two numbers ; results contain carry
( write the program using JC)
LXI H, 4500
LOOP1
LOOP1
MOV A, M
INX H
ADD M
JC
LOOP 1
JMP
LOOP 2
INR C
STA 4500
MOV A, C
STA 4501
HLT
SUM OF DATAS
4. To write an assembly language program to
calculate the sum of datas using 8085
microprocessor
Multiplication ; No carry
LDA 2000 // Load multiplicant to accumulator
MOV B,A // Move multiplicant from A(acc) to B
register
LDA 2001 // Load multiplier to accumulator
MOV C,A // Move multiplier from A to C
MVI A,00 // Load immediate value 00 to a
L: ADD B // Add B(multiplier) with A
DCR C // Decrement C, it act as a counter
JNZ L // Jump to L if C reaches 0
STA 2010 // Store result in to memory
HLT // End
a number by 8
MVI C,OO
LXI H, 4100
MOV B, M
INX H
MOV A, M
DCR B
LOOP 2
ADD M
JNC LOOP1
INR C
LOOP 1
DCR B
JNZ LOOP2
STA 4500
HLT
Multiplication
ASCENDING ORDER
9. To write a program to sort given n
DESCENDING ORDER
10. To write a program to sort given n
Program
11. Write an Assembly Language Program to
transfer a block of data from a series of
locations to other.
MVI C, 0AH
ten
LXI H, 2200H
LXI D, 2300H
2200 location
BK: MOV A, M
; Get byte from source memory
block i.e 2200 to
accumulator.
STAX D
Program
INX H
pointer
INX D
pointer
DCR C
of bytes
JNZ BK
HLT
Largest Number
Write an Assembly Language Program
LOOP 1
JMP
LOOP 2
LOOP1
STA 4500
LOOP2
MOV A, M
STA 4500
HLT
Smallest Number
Write an Assembly Language Program
LOOP 1
JMP
LOOP 2
LOOP1
STA 4500
LOOP2
MOV A, M
STA 4500
HLT
Occurrence Counting
Write an Assembly Language Program
UP Counting
Write an Assembly Language Program
to count up to 7F
UP Counting
Write an Assembly Language Program
9/8/14
DEEPAK.P
63
STACK
The stack is an area of memory identified
memory.
Programmer can defines the bottom of
STACK
Stack is defined by setting the SP (Stack
Pointer) register.
LXI SP, FFFFH ,This sets SP to location FFFFH
(end of memory for 8085).
STACK
Save information by PUSHing onto STACK
Retrieved from STACK by POPing it off.
PUSH and POP work with register pairs only.
Example PUSH B
Decrement SP, Copy B to (SP-1)
Decrement SP, Copy C to (SP-1)
Example POP B
Copy (SP+1) to C, Increment SP
Copy (SP+1) to B, Increment SP
SUBROUTINE
A subroutine is a group of instructions
SUBROUTINE
You must set the SP correctly before using
CALL
CALL 5000H
Push the PC value onto the stack
Load PC with 16bit address supplied CALL
ins.
RET : Load PC with stack top; POP PC
SUBROUTINE
SUBROUTINE
SUBRTN:
PUSH PSW
PUSH B
PUSH D
PUSH H
subroutine coding
POP H
POP D
POP B
POP PSW
RETURN
9/8/14
DEEPAK.P
71
Serial Input
Serial Input
Example Pseudocode:
1) RIM
2) A7 (SID)
As seen from the figure 1, if the SID line is
Serial Input
Serial Input
RIM
Line
-There is a One bit Output port inside the 8085
Line
Line
Line
Pseudocode:
A 40H
SIM
SOD (A7)
Line
SIM
Problem
The SID Pin of an 8085 microprocessor is
INSTRUCTION SUMMARY
INSTRUCTION SUMMARY
INSTRUCTION SUMMARY
INSTRUCTION SUMMARY
INSTRUCTION SUMMARY