140 likes | 740 Views
A Circular Queue Data Structure. Lecture L4.8. A Circular Queue. empty. Containing 2 values. ; A circular queue qsize equ 16 front dw 0 rear dw 0 qmin dw 0 qmax dw 0 qbuff rmb qsize initq ldd #qbuff std front std rear std qmin addd #(qsize-1) std qmax rts.
E N D
A Circular Queue Data Structure Lecture L4.8
A Circular Queue empty Containing 2 values
; A circular queue qsize equ 16 front dw 0 rear dw 0 qmin dw 0 qmax dw 0 qbuff rmb qsize initq ldd #qbuff std front std rear std qmin addd #(qsize-1) std qmax rts
; Store A in queue qstore psha ;save A ldd rear addd #1 ;inc rear cpd qmax bls qs1 ;if rear > qmax ldd qmin qs1 std rear ; rear = qmin cpd front ;if rear = front bne qs3 ; queue if full subd #1 ; dec rear cpd qmin bhs qs2 ; if rear < qmin ldd qmax qs2 std rear ; rear = qmax pula ; pop A bra qs4 ; and return qs3 pula ;else ldx rear staa 0,x ; store A at rear qs4 rts
; Check queue ; if queue is empty, carry = 1 ; else, carry = 0 and A = value taken from queue checkq ldd front cpd rear ;if front = rear bne cq0 ; queue is empty orcc #$01 ; set carry flag bra cq2 cq0 ldd front ;else addd #1 ; inc front cpd qmax bls cq1 ; if front > qmax ldd qmin cq1 std front ; front = qmin ldx front ldaa 0,x ; A = @front andcc #$fe ; clear carry flag cq2 rts