uart_tx_isr:
PUSH ACC ; save the registers we modify in this interrupt routine so we can restore them before we return
PUSH REG0
PUSH MPAGE
CLR UTX1IF ; clear the UART transmit interrupt
MOV A, uart_tx_head ; get the address where the next element will be stored in the transmit queue
XRL A, uart_tx_tail ; xor with the address of the first element in the transmit queue
JNZ uart_tx_next_byte ; if they are equal we get a zero result, and the queue is empty now
CLR uart_tx_busy ; the queue is empty, clear the flag that says that we are busy with transmit
ANL IEN2, #~008h ; disable the UART TX interrupt
JMP uart_tx_isr_end ; we are done
uart_tx_next_byte: ; the transmit queue is not empty
MOV MPAGE, #HIGH uart_tx_buffer ; map the memory page where the transmit queue is located
MOV R0, uart_tx_tail ; load the address of the next byte to be sent
MOVX A, @R0 ; read the byte from memory
INC uart_tx_tail ; increment the address
MOV U1DBUF, A ; put the byte in the UART transmit buffer
uart_tx_isr_end:
POP MPAGE ; restore all registers that we have modified in this interrupt routine
POP REG0
POP ACC
RETI ; return from this interrupt routine