Hello, I'm having this little problem, and I will thank you if you help me with it.

What I'm trying to do is to display the contents of various 16-bit registers (e.g. AX, BX, CX, DX), however without success;

Well, what I tried to do is to check the total clusters and total free clusters on the hard-drive using DOS interrupt 21h and function 36h. It returns the number of total clusters into DX.

I tried to print the DX using the function 09h of the same interrupt, however I'm getting gibberish whenever i'm trying to do so.

In short - How can I convert number from registers such as AX or DX into strings, so I can print them to the screen?

The reason jibberish is output to the consol is because
DX is to contain the offset of a dollar-sign '$' terminated string.

mov dx, offset msg
mov ah, 0x9
int 0x21
int 0x20
msg db 'hello world$'

To print out the value contained in the registers you will
have to convert their value into the ASCII representation
of a hexadecimal/decimal/etc.. value.

To print out the value of the AX register in hex for example:

mov ax, 0x1234
call printw
int 0x20

printw:
 push ax
 shr ax, 8
 call printb
 pop ax
 push ax
 and  ax, 0xff
 call printb
 pop ax
 ret

printb:
  push ax
  shr al, 4
  call printasc
  pop ax
  and al, 0xf
  call printasc
  ret

printasc:
  add al, 0x30
  cmp al, 0x39
  jle printasc_e
  add al, 0x7
  printasc_e:
  mov dl, al
  mov ah, 0x2
  int 0x21
  ret

Thanks, NotNull, i'll try that.

One thing, however, because NASM does not let me compile when I do an offset, it always gives me an error about that.

Use: [msg]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.