Search code examples
assemblytasm

How does it work? Delimiter and the Extended Addressing in my program


BOOK: IBM PC Assembly Language Programming: Fifth Edition by Peter Abel

p.143 Program: Accepting and Displaying Names

The movzx sets BX with the number of characters that were typed. In the mov,[bx] acts as an index register to facilitate extended addressing. The MOV combines the length in BX with the address of KBNAME and moves the 07H to the calculated address. for a lenth of 11, the instruction inserts 07H at KBNAME+11 (replacing the Enter character) following the name. The instruction in c10center

mov kbname[bx+1],'$'

inserts a $ delimiter following the 07H so that int 21h function 09H can display the name and sound the speaker

1  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?


Solution

  • 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).