# Printing a string in NASM Win16 Assembly

A small script that simply prints a given string. It's an improved snippet that combines some recommendations given in my post on string helper functions.

org 100h

mov     si, hello
call    puts
ret

puts:
jmp     .run
.putc:
mov     ah, 0Eh
mov     bx, 7
int     10h
.run:
lodsb
cmp     al, 0
jne     .putc
ret

hello db "Hello World!", 0


You have all the elements. The only thing that can be eliminated is jmp .run, as follows:

org 0x100

mov     si, Prompt
call    puts
ret

puts: mov     ah, 0xe
mov     bx, 7
or       al, al
jnz     .post
ret
.post: int     0x10

• Use TEST reg, reg to check for zero in preference to OR reg, reg, since the former is more likely to fuse with the conditional branch. I also find it more readable. Nov 16, 2019 at 4:33
• @CodyGray I agree, as test is more representative of what is being done and I think that's what you mean by more readable. Whereas or implies AL is being modified for some other reason. Nov 16, 2019 at 7:58
• I use trashing in the context that a register has been modified by an interrupt, function or subroutine where its value upon return is indeterminate. As to the reference your using, I think it would be safe to say that if nothing is returned, then nothing is modified either or it specifically states returned values. Nov 16, 2019 at 17:42