Displaying contents of registers..?

Reply

Join Date: Dec 2008
Posts: 18
Reputation: Ronen444 is an unknown quantity at this point 
Solved Threads: 0
Ronen444 Ronen444 is offline Offline
Newbie Poster

Displaying contents of registers..?

 
0
  #1
Oct 17th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 133
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 13
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #2
Oct 18th, 2009
The reason jibberish is output to the consol is because
DX is to contain the offset of a dollar-sign '$' terminated string.
  1. mov dx, offset msg
  2. mov ah, 0x9
  3. int 0x21
  4. int 0x20
  5. 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:
  1. mov ax, 0x1234
  2. call printw
  3. int 0x20
  4.  
  5. printw:
  6. push ax
  7. shr ax, 8
  8. call printb
  9. pop ax
  10. push ax
  11. and ax, 0xff
  12. call printb
  13. pop ax
  14. ret
  15.  
  16. printb:
  17. push ax
  18. shr al, 4
  19. call printasc
  20. pop ax
  21. and al, 0xf
  22. call printasc
  23. ret
  24.  
  25. printasc:
  26. add al, 0x30
  27. cmp al, 0x39
  28. jle printasc_e
  29. add al, 0x7
  30. printasc_e:
  31. mov dl, al
  32. mov ah, 0x2
  33. int 0x21
  34. ret
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 18
Reputation: Ronen444 is an unknown quantity at this point 
Solved Threads: 0
Ronen444 Ronen444 is offline Offline
Newbie Poster
 
0
  #3
Oct 18th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 129
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster
 
0
  #4
Oct 18th, 2009
Use: [msg]
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC