0% found this document useful (0 votes)
25 views11 pages

Examples Stack N SR

Uploaded by

Ahuja Ahuja
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
0% found this document useful (0 votes)
25 views11 pages

Examples Stack N SR

Uploaded by

Ahuja Ahuja
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
You are on page 1/ 11
STACK S 1x Push ust pureH PUSH PusH ‘operand splot Rp lynoe Beer 2 Pow: Lond Stak Pointer 1 nthe stack poner river with a 16it aes. The [EXT instuctions were dacussed ia Chapter 7 Stowe Reise Pir on Stack 1D This ie este instruction 1 copies th contents othe specified register pron the sack a descebed blow (0 The ek power rept i again decremented nd the content of the Kore rpste eg regiier C) are ‘copied in that oeation (0 The opens B,D sind H represent repister pais BC, DIE and HL, sespectively © Te operand PSW represents rope Stas Word meaning the content of the accumulator and the gs Retrieve Regier Pair fom Sack (1 This I-byte ination 11 It copies the contents ofthe top exo memory Ieatons ofthe stack int the specied reser ie 11 Fn the contents ofthe merry loction indicted by the stack poner reper ae cop no the low-onder register (eg eps L), an then the sack potter reg isi intemened by 1 12 The content of the next memory locaton ae copied Int the high onder reistr (eg, ree Hand he stack pointer register asin ncereae by | PROBLEM STATEMENT Write a program to perform the following fuxetions; 1. Clear all tho fags. 2, Load OOH in the accumulator, and demonstrate thac the Zero flag is not affected by the data transfer instruction, us me 3 Logically OR the accumulator with itself w set dhe Zero flag, and display the fag at PORT or store all the flags om the stk, PROGRAM Memory ‘Address \\ wet ean ea ee a pet eT a # BS ( Bie oer D Mov AL Bo ey een ee mam z Bun y She 3 Re a z es Comments niitze the stack ‘har L Place (1) om stack {Clea Nags ‘Load OOH ‘Save flags on tack Retrieve lags in L Display Mags Loa OOH again ‘Sat lags and eset CY, AC ‘Save flags on sick Retrieve flags in L {Baa of program ‘ om m6 Aepative wo Ox Display SOTAG aan ona Sets nde C¥ mt AC fsirw — Srederansas a Siam _t! 009000 SUBROUTINE, Opcode Sab RET. Operand 16-bit memory address of a subroutine Call Subroutine Unconditionally © This is a 3-byte instruction that transfers the program sequence to a subroutine address 1 Saves the contents of the program counter (the ad- dress of the next instruction) on the stack CG Decrements the stack pointer register by 1wo Jumps unconditionally to the memory location speci- fied by the second and third bytes. The second number and the third byte specifies a page number 1 This instruction is accompanied by a return instruc- tion in the subroutine Return from Subroutine Unconditionally i This is a I-byte instruction 1 Inserts the two bytes from the top of the stack into the program counter and increments the stack pointer register by two Unconditionally returns from a subroutine Memory Address 2000 2010 2041 2042 2043 205F 2070 207F 2080 2398 23FF 2400 Jr sPa400HT CALL 207011 NEXT INSTRUCTION | HLT First Subroutine Instruction vi RET 4 Other Subroutines v Empty Space + ‘Initialize the stack pointer at 2400H {Call the subroutine located at 20704. This is 5 a byte instruction The address of the next instruction following the CALL instruction :End of the main program ‘Beginning of the subroutine snd of the subroutine The stack is initialized at 240081 Memory Address 2040 20.1 2082 2083 Mal Coe Mnemonies cp ‘CALL 20 a a 20 NEXT INSTRUCTION Comments {Call subroutine located at the memory location 20701 2000 207F PROBLEM Write a program to provide the given omoff time to three traffic lights (Green, Yellow, and Red) and ‘wo pedestrian signs (WALK and DON'T WALK), The signal lights and signs are turned onfoff by the data bits of an output port as shown below: Lights Data Bis On Time 1. Green Dy 2. Yellow D, 3. Red Dy y 4. WALK / De | 5. DONT WALK Dy seconds ‘The waffic-and pedestrian flow are in the same direction; the pedestrian should cross the road when the Green light is on. Gren ih see ere = See Mortman tna fray pe fois ao le 8 8 as) 4 od (cu) t : a 4 Memory ‘Address x00 on 03 05; 08 0A 0B. oD 0B oF 10 u 2 B Code ‘Mnemonics Comments 31 XX 3E START, a ps PORTH 06, oF cD 50 XX 3E ba PORTH 05 oD 50 LXI SRXX99/]sntalize stack pointer at cation XXSOH ‘High-order addres (page) of user memory MVEA,IL | :Load accumulator with the bt putern for es {Green light and WALK sign ovr port 1m om Green rt andl WALK sion MVIB,OFH Use B as a counter to count 1$seconds, B is decremented in the subrox Call delay subroutine located at XX5OH CALL DELAY :High-onder adress (page) of user memory MVLASIH / Load sceumulstor with the bit pattern for ‘Yellow light and DON’T WALK OUT PORTY / Tum on Yellow light and DON'T WALK {and tum off Green light and WALK MVIB,05 / ;Set up 5-second delay counter CALL DELAY Vy ry Is 16 7 18 19 1A IB Ic 1D IE. IF 20 XX 3 90 D3 PORTH 06 4 cp 50. XX 3 03 XX sHligh-order address of user memory MVLAOH / {Lond accumulator with the bit pattern For + Red light and DON’T WALK OUT PORT# ./ —:Turn on Red light, keep DON’T WALK on, + and turn off Yellow light ;Set up the counter for 20-second delay CALL DELAY / IMP START :Go back to location START to repeat the sequence ys sDELAY: This is a L-second delay subroutine that provides delay 5 according (o the parameter specified in register B sinpur: Number of seconds is specified in register B :Ouaput: None ‘Registers Modified: Register B xxso ps, etay_pusiy Save coments of DE and accumulator a coy ——srusH psw 521 SECONDY LXTD.COUNT Load register ut DE with cout for 53 Lo ~— i second del MoM ms 55 1B Loop: | DCXDY Decrement register pair DE SOA | MOV AD 57 BB gt |! ORAE IR (D) andl (E) to set Zero flag sc A AUEY nzoor np eotonp i dy tt gu 90 os AO sno DERBY Lao 1 second delay; decrement the counter xO INZSHCOND sth the en of time needed? If no, 20 3 2 back t repeat Isocond delay SE XX ;High-order memory address of user memory, SF FI POP PSW- —_:Retrieve contents of saved registers cc DI POP D < 61 co PRET :Return to main program

You might also like