4
\$\begingroup\$

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
asked Nov 16, 2019 at 2:15
\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

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
 .read: lodsb
 or al, al
 jnz .post 
 ret
 .post: int 0x10
 jmp .read
 Prompt: db 'Hello World', 0

As INT 10H does not trash AH or BX, there is no need to reinitialize them each time through the loop.

Cody Gray
4,56719 silver badges30 bronze badges
answered Nov 16, 2019 at 4:29
\$\endgroup\$
4
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Nov 16, 2019 at 4:33
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Nov 16, 2019 at 7:58
  • \$\begingroup\$ I interpret "trashing" as having a value reset to some default value. Would this be accurate? If so, Is there a way to efficiently determine if an interrupt trashes a register? I've been using HelpPC as a reference for interrupts, and there's no mention of trashing. \$\endgroup\$ Commented Nov 16, 2019 at 17:24
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Nov 16, 2019 at 17:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.