\$\begingroup\$
\$\endgroup\$
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
1 Answer 1
\$\begingroup\$
\$\endgroup\$
4
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.
answered Nov 16, 2019 at 4:29
-
1\$\begingroup\$ Use
TEST reg, reg
to check for zero in preference toOR reg, reg
, since the former is more likely to fuse with the conditional branch. I also find it more readable. \$\endgroup\$Cody Gray– Cody Gray2019年11月16日 04:33:14 +00:00Commented 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. Whereasor
implies AL is being modified for some other reason. \$\endgroup\$Shift_Left– Shift_Left2019年11月16日 07:58:49 +00:00Commented 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\$T145– T1452019年11月16日 17:24:27 +00:00Commented 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\$Shift_Left– Shift_Left2019年11月16日 17:42:46 +00:00Commented Nov 16, 2019 at 17:42
lang-lisp