org 100h jmp start ; First argument is the name. Second argument is the size %macro QUEUE 2 %1: jmp .doneInit ; Don't run all the code when the queue is instantiated .mySize EQU %2 .myData resb (%2) .numElements dw 0 .readOffset dw 0 .writeOffset dw 0 .tmp db 0 ; I don't know what you mean by Status exactly. ; I'll define Status to be 0=empty, 1=nonempty, 2=full ; Status is returned in AL .Status: push bx mov bx, [.numElements] cmp bx, 0 ; Is it empty? jne .checkFull pop bx mov al, 0x00 ret .checkFull: cmp bx, .mySize ; Is it full? jne .partFilled pop bx mov al, 0x02 ret .partFilled: pop bx mov al, 0x01 ret ; Empty the queue .Reset: mov word [.numElements], 0 mov word [.readOffset], 0 mov word [.writeOffset], 0 ret ; Reads one byte and puts it in AL ; If read an empty queue, undefined behavior occurs, so don't do it .Read: push bx dec word [.numElements] mov bx,[.readOffset] mov al,[bx+.myData] inc bx cmp bx,.mySize jne .dontZeroRead mov bx,0 .dontZeroRead: mov word [.readOffset],bx pop bx ret ; Writes AL into the queue ; If writing to full queue, badness happens, do don't do it .Write: push bx inc word [.numElements] mov bx,[.writeOffset] mov [bx+.myData],al inc bx cmp bx,.mySize jne .dontZeroWrite mov bx,0 .dontZeroWrite: mov word [.writeOffset],bx pop bx ret .doneInit: %endm myText db "Hello. La la laaaaa. Yea, there is stuff here. Stuff. Stuffff Stuffff Stuuuuuuff. Go figure. Anyway. Yea. Bye now!" ; '!' is terminating character start: QUEUE myQ, 45 call myQ.Reset mov si,myText mov ax,0x0002 int 0x10 mov dl,0x00 ; Set to 1 when we reached the end. push cs pop ds writeToQueue: call myQ.Status cmp al,0x02 ; Queue is full je newReadFromQueue mov al,[si] call myQ.Write inc si cmp al,'.' je newReadFromQueue cmp al,'!' jne writeToQueue mov dl,0x01 jmp newReadFromQueue newReadFromQueue: ; Print a newline every time a new read starts ; Just to make sure we are switching correctly mov al,0x0A call showAL mov al,0x0D call showAL readFromQueue: call myQ.Status cmp al,0x00 ; Empty? je queueEmpty call myQ.Read call showAL jmp readFromQueue queueEmpty: cmp dl,0x01 ; No more text to read? je exitProgram jmp writeToQueue ; Loop forever or else the window will close exitProgram: jmp exitProgram ; Or exit gracefully if running under dosbox or from a batch file. mov ah,0x00 int 0x21 showAL: mov ah,0x0E int 0x03 int 0x10 ret