Skip to content

Instantly share code, notes, and snippets.

@mjdargen
Created July 8, 2021 14:29
Show Gist options
  • Save mjdargen/c5e558b0e00694c727aa758eb64da2e4 to your computer and use it in GitHub Desktop.
Save mjdargen/c5e558b0e00694c727aa758eb64da2e4 to your computer and use it in GitHub Desktop.
Starter code for PS7 queue size.
;
; queue_size.asm - subroutine to check queue size.
;
.ORIG x3000
LD R3, FIRST ; initialize front/head
ADD R3, R3, #1 ; add offset to test different values
LD R4, FIRST ; initialize rear/tail
ADD R4, R4, #3 ; add offset to test different values
JSR Q_SIZE ; call subroutine
HALT ; put breakpoint here to check value in R5
; ---------------------- QUEUE SIZE SUBROUTINE ---------------------- ;
; Description: computes current size of the queue
; Inputs: R3 - front/head, R4 is rear/tail
; Outputs: R5 - size
; NOTE: update FIRST/LAST based on start point and end point of queue
Q_SIZE
RET
Q_R1 .BLKW 1
Q_R2 .BLKW 1
FIRST .FILL x4000 ; starting address of queue storage
NEG_1ST .FILL xC000 ; negative of FIRST
LAST .FILL x4005 ; ending address of queue storage
NEG_LST .FILL xBFFB ; negative of LAST
.END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment