Quite often, we need to send strings to a computer. Usually, there is a section in your code where you define the message with a label:
;string is terminated with null MsgHelloWorld: .asciz "Hello World!\r\n" ;subroutine to print strings putstr: ld a,(hl) or a ret z call putchar inc hl jr putstr main: ld hl,#MsgHelloWorld call putstr halt
With a bit of extra code, we can make some code with embedded strings.
main: call putstr_imm .asciz "Hello World\r\n" call putstr_imm .asciz "Hello World again\r\n" halt ;subroutine to print inline strings putstr_imm: ;this exchange the stack pointer (SP) with HL ex sp,hl ;at this point, HL points to the code after the call, ;but we placed data instead, terminated with a null. ;So we skip the data while printing it. ;When done, normal code follows put1: ld a,(hl) or a jr nz,put_ret ;if null detected we resume code call putchar ;else we print bytes inc hl jr put1 put_ret: ;restore the stack pointer which point to the code after the string ex sp,hl ret