Hi, I would like to know how to display the value of a register by outputing the value of let's say ax to the screen in 16bit asm...
Posted on 2001-10-01 01:08:40 by clip
As 16bit you mean under DOS?
You have convert binary value in AX to string (look for ready made routines), than, if you work in dos, display out the string for example with interrupt 21h.
Posted on 2001-10-02 01:01:46 by Bit7
or may be you can use OutputDebugString()? The good old DBWIN will show all outputs from 16-bit apps.

japheth
Posted on 2001-10-02 02:19:11 by japheth
could you please give an example using a said converter?
Posted on 2001-10-02 04:17:43 by clip
Here is a simple routine to convert ax to binary text in a string called "buffer" (make sure buffer is at least 17 bits long)!


mov cx, 16

.REPEAT
xor dx, dx
shr ax, 1
adc dl, 48
mov Buffer[cx - 1], dl
dec cx
.UNTIL cx == 0

Note, it destroys ax, if you change the shr to ror it won't (but isn't pairable on PPlain/MMX).

Mirno
Posted on 2001-10-02 04:36:00 by Mirno
Mirno:
I'm using nasm as my 16bit compiler so I tried to modify your code to nasm and I came up with this:

jmp start
Buffer db " $" ;> greater than 17 bits, (2 digit limit?)
start:

mov ax, 10 ; My number
mov di,Buffer
mov cx, 16

repeat:
xor dx, dx
shr ax, 1
adc dl, 48
add , cx ; >
mov bx, 1 ;>
sub , bx ;>
mov , dl ;>mov Buffer, dl (am I correct?)
dec cx
cmp cx, 0
jne repeat

mov ah, 9h
mov dx,Buffer
int 21h

my port doesnt seem to work when I compile/run it, it outputs 0, probably it's because I got something wrong. Any suggestion to make it work?
Posted on 2001-10-02 09:32:13 by clip
First of all, your buffer seems to be only 2 characters long, the code I gave prints the binary, and so will be 16 characters long for a 16 bit number (+ 1 for the terminator).

Secondly, I think you should be able to do your code like this:


mov ax, 10 ; My number
mov di, Buffer
mov cx, 16 ; Number of bits to place

repeat:
xor dx, dx
shr ax, 1
adc dl, 48
mov BYTE PTR [di + cx - 1], dl
dec cx
jnz repeat

mov ah, 9h
mov dx, di
int 21h


I'm not familiar with NASM or DOS, so I can't help too much with that!

But I did notice that you are corrupting your Buffer pointer (di), so for the first itteration it is correct, but after it is done, it doesn't restore it to its proper value, hence di is off by (cx - 1 (which is 15 for the first loop)). After one itteration it will be pointing to (buffer + 15), after two itterations it will point to (buffer + 15 + 14), etc.

You can carry on in the same way as you currently are, but add a restore to di at the end of your code, or (as NASM should be able to do) implement the code above.

Hope that helps!

Mirno
Posted on 2001-10-02 10:06:55 by Mirno