BOOK: IBM PC Assembly Language Programming: Fifth Edition by Peter Abel
p.143 Program: Accepting and Displaying Names
The
movzx
setsBX
with the number of characters that were typed. In themov,[bx]
acts as an index register to facilitate extended addressing. TheMOV
combines the length inBX
with the address ofKBNAME
and moves the07H
to the calculated address. for a lenth of 11, the instruction inserts07H
atKBNAME+11
(replacing the Enter character) following the name. The instruction in c10centermov kbname[bx+1],'$'
inserts a
$
delimiter following the07H
so thatint 21h
function09H
can display the name and sound the speaker1 c10center proc near 2 movzx bx,actulen 3 mov kbname[bx],07 4 mov kbname[bx+1],'$' 5 mov dl,actulen 6 shr dl,1 7 neg dl 8 add dl,40 9 mov dh,12 10 call q20cursor 11 ret 12 c10center endp
my question is what does the ,07
in line 3 do?
also i am confused how does line 4 works? delimiter?
Line 3: it's putting the "bell" character (indeed, character 7; it's called bell because the computer beeps when printing it) in the position specified by bx
of the buffer kbname
. Notice that it had first to move (with zero-extension, so I suppose it's some kind of 8-bit value?) actulen
in bx
, because in 16 bit x86 it's one or the few registers that can be used in indexed addressing modes.
Line 4 does a similar thing, but with the $
character at the next position in the string.
In C, these two lines would just be
kbname[actulen] = 7;
kbname[actulen+1] = '$';
The book talks about a "delimiter" because int 21h/ah=09h
uses $
as a marker that the string it has to display has ended. In this respect, in DOS assembly programming $-terminated ("ASCII$") strings are really similar to C's NUL-terminated ("ASCIIZ") strings (actually, the delimiter choice is way stupider, since $ is a character that does occur in "normal" strings you'd like to display).