.include "labmac.i" .section .text .globl main | Demonstrate Stack operation via key presses main: JSR SInit CLR.L D6 | clear insert value mloop: CALLEXEC KEY_Get | wait for button press CMP.B #KEY1, D0 | left button = PUSH BNE next1 ADD.L #1, D6 | new insert value MOVE.L D6, D0 JSR Push | call insert BRA mloop next1: CMP.B #KEY2, D0 | 2nd button BNE next2 JSR Pop | = POP MOVE.L D0,D1 | print value JSR outint BRA mloop next2: CMP.B #KEY4, D0 | right button BNE mloop | = EXIT RTS | --------------------------------------------- buflen = 10 buffer: DS.L buflen | Initialize Stack, Parameters: none SInit: MOVE.L #buflen, D5 | initialize SP-Index (empty) RTS | Push element onto Stack, Parameters: D0.L input value Push: SUB.L #1, D5 | decrement SP-Index BMI Error | full-error if SP-Index < 0 MOVE.L D0, (buffer,D5.L*4) | push data on stack RTS | Pop element from Stack, Parameters: D0.L return value Pop: CMP.L #buflen, D5 | empty if SP-Index > buflen BGE Error MOVE.L (buffer,D5.L*4), D0 | pop data from stack ADD.L #1, D5 | increment SP-Index RTS |------------------------------------------ outint: MOVEM.L D1-D2/A0,-(SP) | SAVE REGISTERS MOVE.L #intstr+10, A0 | pointer A0 behind last digit loop: DIVUL.L #10, D2:D1 | D1 := D1/10, D2 := remainder ADD.B #'0', D2 | make D2 digit character MOVE.B D2, -(A0) | write digit TST.L D1 | check quotient BNE loop | while ? 0 repeat with quotient in D1 print: CALLEXEC LCD_PutString | call string print (address in A0) MOVEM.L (SP)+,D1-D2/A0 | RESTORE REGISTERS RTS intstr: .asciz "1234567890 " | number can have up to 10 digits | ----------------------------------- | Print Error Message, Parameters: none Error: LEA estr, A0 | load error string CALLEXEC LCD_PutString RTS estr: .asciz "S-Error"