Tutorial #9
2-18-99
Stacking Numbers
Stacking numbers is important when you need to store a number for a while, you don't usually stack many numbers because there is no need to. Say you stack 2 numbers, the first is 5 the second is 6, you have to take off the 6 before you can take off the 5. Push means you want to "push" a number on the stack and pop means you want to "take a number off" the stack. So here is a program to help explane it.
...Code we use in every asm program...
call _clrLCDFull ;clears the screen
ld hl,5 ;Loads 5 into hl
push hl ;Pushes 5 into stack
ld hl,10 ;Loads 10 into hl
push hl ;Pushes 10 into stack
ld hl,15 ;Loads 15 into hl
push hl ;Pushes 15 into stack
ld hl,20 ;Load 20 into hl
pop hl ;Take 20 off stack
call _disphl ;Display hl
call _newline ;Calls a new line
pop hl ;Takes 15 off stack
call _disphl ;Displays hl
call _newline ;Calls a new line
pop hl ;Takes 10 off stack
call _disphl ;Displays hl
call _newline ;Calls a new line
ret ;Returns to what it was doing
.end ;Ends program
END ;Needed for TASM
What the program did was display 15, then 10, then 5... If you read the comments you should understand... Any Questions? E-mail me.
(KSA)Tekken (uncool3@juno.com)