newbie questions text code...



Hello. I'm reading Jeff Duntemann's book "Assembly Language Step by
Step". So, I'm a total novice. I'm in Chapter 10 and questioning some
code he has. Now the code is totally academic and is used mostly to
illustrate the use of the AND, XOR and SHR instructions.

The author says DOS will not display numeric values from a register but
only text. So, to display those numeric values you first have to
convert them to their string representations through the use of a
table; hence this code.

The table is:

Digits DB "0123456789ABCDEF"

And the code in the book is thus:

Byte2Str:

mov DI, AX ; Duplicate byte in DI
and DI, 000FH ; Mask out high 12 bits of DI
mov BX, Digits ; Load offset of Digits into BX
mov AH, BYTE [BX+DI] ; Load digit from table into AH
mov [SI +1], AH ; and store digit into string
xor AH, AH ; Zero out AH
mov DI, AX ; and move byte into DI
shr DI, 4 ; Shift high nybble of byte to
low
mov AH, BYTE [BX+DI] ;Load digit from table into AH
mov [SI], AH ; and store digit into string
ret ; We're done - go home

So at this point you're supposed to have the numeric value stored as a
string representation so you return back to you main program to have it
printed out.

My question is shouldn't he have included his AND instruction a second
time? Right after the SHR instruction? I know he has pushed the
lower four bits out of the question, and the upper four bits of the
first byte are now the lower four bits. But the upper eight bits of DI
are still contained in the middle 8 bits of the word.

Simple question, I guess, but I am wondering if I'm missing something.

Thanks.

.



Relevant Pages