.NOLIST .INCLUDE "m8def.inc" .LIST ; Send a null terminated string over UART WriteHelloWorld: ldi ZH, HIGH(HelloWorldString) ldi ZL, LOW(HelloWorldString) ; Set R16 to 0x00 which we'll use for terminating a character later ldi R16, 0x00 CharSendLoop: ; Load the memory located at address Z into register R4, ; Then increase Z so on the next run it will by the next memory slot lpm R4, Z+ WaitToTransmit: ; sbis, skip next instruction if bit is set, so ; Basically skip next instruction if UDRE (ready to send) isset in UCSRA ; otherwise it will do rjmp WaitToTransmit and loop back around sbis UCSRA, UDRE rjmp WaitToTransmit ; Because there is room to transmit, it's now time to send something ; Send the contents of R4 (whatever is stored in memory at that address) ; to serial port. out UDR, R4 ; Now compare R4 and R16 (which is 0x00, termination) to see if R4 is 0 cp R4, R16 ; Branch-Not-Equal (brne) back to send the character since we're R4 is not ; 0x00 yet, it must still have something to send. brne CharSendLoop ; Otherwise we should return (where?) ret HelloWorldString: ; Here we define the immediates that will be inserted into ZH and ZL ; one byte at a time. .db 'H' .db 'e' .db 'l' .db 'l' .db 'o' .db ',' .db ' ' .db 'W' .db 'o' .db 'r' .db 'l' .db 'd' .db 0