0 ratings0% found this document useful (0 votes) 25 views11 pagesStack and Delay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
STACK
Opeode
it
Pus
Pus
Pus
Pus
PUSH
Operand
srs tit
gees
gees
1 Lag Suck Pointer
1 La tho stack poimsr register with» 162i aiess The
EX! insractions were dicased in Chapter 7
Store Regier Param Sack
1D This is. byt nsstion
1 Ieoopies the conten ofthe speed ester pron the
stack as described below
10 The tack pln eps s decremented, and the con-
tens of te high-order epter (eg. reisor B) se
‘apie in he cation sh by the stack pointer ester
(© Te stack pointer eps agin decremented, a the
content ofthe laure oie (erie C) ae
copied in tht action
10 The operands, D, and H represent register pais BC,
DDE, ond IL, respeatively
11 The opera PSW resents Progra Status Wont
meaning the contents ofthe secular al he Has
Retrieve Reps Pi rom Sick
10 Thiisa rhs insrction
1 teeopis the contents oF ths top eo memary cations
‘ofthe ck ino the specified regis pt
12 Fist the coments ofthe memory leatio inated by
‘he ack pine register se copied into he low-order
gine (eg. register Land then the tick pointer re
ister is incremented by 1
1D The comers ofthe next memory location are coped
Into te high order epee. seis), and the
stack pointer register i gai incremented by 1Cees
Prey
ns
Contents onthe Stak and in the Rect Aor tho PUSH InstructionPROBLEM STATEMENT
Write a program to perform the following functions:
1, Clear all the fags.
2. Load OOH in the accumulator, and demonstrate thatthe Zero fla
data transfer instruction,
3. Logically OR the accumulator with itself to set the Zero flag, and display the flag at
PORT! or store all the flags on the stack.
not affected by theMachine
‘Code
nstretions|
XI SPXXOOIE
MMVI L008
ust
Por PSW
ME ACOEL
ust PSw
por
MOV AL.
OUT PORTO
MVIA.oOH
ORAA
PUSH FSW
POP H
MOV AL
ANT AOH
our port!
her
Comments
Inialire the stack
‘Clear,
Place (L) om stack
“Clear Bags
{Loa OOH
‘Save ays on sack
‘Retrieve flags in
Display Mags
‘Load 00H again
'Set flags and vest CY, AC
‘Save flags on stack
Retrieve flags in L
‘Mask all Mags except Z
dof program
Stig ia Mer Alera
om
oe
irs
we NVIADON oO gin
*
” ona Sas an at C¥ md AC
5 Fusi'sw ‘Segsen
* ir ae on
Rag RegiserSUBROUTINE
Opeode
CALL
RET
Operand
16-bit memory
address of a
subroutine
Call Subroutine Unconditionally
(I This is a 3-byte instruction that transfers the program
sequence (0 a subroutine address
7 Saves the contents of the program counter (the ad-
dress of the next instruction) on the stack
i Decrements the stack pointer register by two
Jumps unconditionally to the memory location speci-
fied by the second and third bytes. The second
byte specifies a line number and the third byte
specifies a page number
This instruction is accompanied by a ret
tion in the subroutine
Return from Subroutine Unconditional
This is a I-byte instruction
C1 Inserts the two bytes from the top of the stack into
the program counter and inerements the stack
pointer register by two
1 Unconditionally returns from a subroutine
instruMemory
Address
2000
2040
2041
2042,
2043
205F
2070
207F
2080
2398
23FF
2400
LXI SP2400H
Lu
CALL. 2070H
NEXT INSTRUCTION
|
HLT
First Subroutine
Instruction
+
RET
L
Other Subroutines
Empty Space
4
sTnitialize the stack pointer at 2400H
;Call the subroutine located at 2070H. This is
+ a 3-byte instruction
The address of the next instruction following
the CALL instruction
:End of the main program
‘Beginning of the subroutine
End of the subroutine
‘The stack is initialized at 2400HMemory
Address
2040
2001
2082
2083
Mnemonics
CALL 2070H
INSTRUCTION
Call subroutine located at them
Comments
very
location 2070H
2000
Subroutine
2042 ——————- 2070
2043
205F 201FPROBLEM
Write a program to provide the given owoff time to thre trafic lights (Green, Yellow, and
Red) and two pedestrian signs (WALK and DON'T WALK). The signal lights and signs
are urned onoft by the data bits of an output port as shown below:
Data Bits On Time
1, Green 15 seconds
2. Yellow 5 seconds
3. Red 20 seconds
4. WALK 15 seconds
5. DON'T WALK 25 seconds
‘The traffic and pedestrian flow are in the same direction; the pedestrian should cross the
road when the Green
Sequence DON'T Hex
Im Seconds. WALK WALK Red Yellow Green Code
o Dy BR oP bh Db Db Bm
ay 4
15 10:00 - 4H
ol
20 oo = MH
mt 4
ed ' o 0 © 0 0 = 8HMemory
Address
Xx00
o1
a
03
04
05
06
07
08
09
0A,
op.
oc
op
0
OF
10
u
12
3
Code
31
9 LXI SPXX99
XX
3E START: MVIAAIH
a
m court port#
PORTH
06 MVIBOFH
oF
cD CALL. DELAY
50
XX
3B MVIAS4H
a4
pa our PoRT#
PORTH
06 MYI BOS
05
cD ‘CALL DELAY
50
Mnemonics
Comments
sInitialize stack pointer at location XX99H
‘High-order address (page) of user memory
‘Load accumulator with the bit pattern for
+ Green light and WALK sign
“Turn on Geen lioht and WALK sion
:Use B as a counter to count 1Sseconds.
+ Bis decremented in the subroutine
:Call delay subroutine located at XXSOH
‘igh-order address (page) of user memory
:Load accumulator with the bit pattern for
i Yellow light and DON'T WALK
Turn on Yellow light and DON'T WALK
5 and turn off Green light and WALK
{Set up 5-second delay counter14
15
16
7
18
19
1A
1B
Ic
1D
IE
IF
20
Xxx
3E
90
D3
PORTH
06
4
cD
50
XX
G
03
XX
MVIA,90H
OUT PORT#
MVIB,14H
CALL DELAY
JMP START
;sHigh-order address of user memory
:Load accumulator with the bit pattern for
3 Red light and DON’T WALK
Turn on Red light, keep DON’T WALK on,
and turn off Yellow light
{Set up the counter for 20-second delay
:Go back to location START to repeat the
sequencesDELAY: This is @ [-second delay subroutine that provides delay
according (othe parameter specified in register B
XxX50
3
52
53
55
56
37
58
59
5A
SB
5c
sD
SE
sr
60
61
slnput: Number of seconds is
:Ouaput: None
Registers Modified: Register B
bs DELAY: PUSH D
FS PUSH PSW
1 SECOND: LXID,COUNT
Lo
HI
1B Loop: DCX D
A MOV A.D
BB. ORAE
a INZ LOOP
55
XxX
05 DCRB
Q JNZ SECOND
52
XX
FI POP PSW
DI POP D
o RET
specified in register B
‘Save contents of DE and accumulator
Load register pair DE with a count for
+ I-second delay
{Decrement register pair DE
OR (D) and (E) to set Zero fla
Jump to Loop if delay count is not equal to 0
End of I second delay; decrement the counter
Is this the end of time needed? If not, go
back to repeat I-second delay
High-order memory address of user memory
Retrieve contents of saved registers
sReturn to main program,