.include "labmac.i" .section .text .globl main main: JSR Qinit CLR.L D6 | clear insert value mloop: CALLEXEC KEY_Get | wait for button press CMP.B #KEY1, D0 | left button = insert BNE next1 ADD.L #1, D6 | new insert value MOVE.L D6, D0 JSR QInsert | call insert BRA mloop next1: CMP.B #KEY2, D0 | 2nd button BNE next2 JSR QDelete | = delete MOVE.L D0,D1 | print value JSR outint BRA mloop next2: CMP.B #KEY4, D0 | right button BNE mloop | .. is EXIT RTS | --------------------- buflen = 10 buffer: DS.L buflen | Parameters: none Qinit: LEA buffer+4, A5 | initialize HEAD LEA buffer, A6 | initialize TAIL CLR.L D5 | start length = empty RTS | Parameters: D0.L input value QInsert: CMP.L #buflen, D5 | check if space left BEQ QError ADD.L #1, D5 | update length SUB.L #4, A5 | decrement HEAD CMP.L #buffer, A5 | check HEAD underflow BGE InOK ADD.L #(buflen*4), A5 | put HEAD to end of queue InOK: MOVE.L D0, (A5) | write data in queue RTS | Parameters: D0.L return value QDelete: TST.L D5 | check if empty BEQ QError SUB.L #1, D5 | update length MOVE.L (A6), D0 | return TAIL element in D0 SUB.L #4, A6 | decrement TAIL CMP.L #buffer, A6 | check TAIL underflow BGE DelOK ADD.L #(buflen*4), A6 DelOK: RTS | Parameters: none QError: LEA estr, A0 | load error string CALLEXEC LCD_PutString RTS estr: .asciz "Q-Error" | --------------------- 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