943,938 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 712
  • Assembly RSS
Oct 17th, 2009
0

Displaying contents of registers..?

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ronen444 is offline Offline
18 posts
since Dec 2008
Oct 18th, 2009
0
Re: Displaying contents of registers..?
The reason jibberish is output to the consol is because
DX is to contain the offset of a dollar-sign '$' terminated string.
Assembly Syntax (Toggle Plain Text)
  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:
Assembly Syntax (Toggle Plain Text)
  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
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008
Oct 18th, 2009
0
Re: Displaying contents of registers..?
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ronen444 is offline Offline
18 posts
since Dec 2008
Oct 18th, 2009
0
Re: Displaying contents of registers..?
Use: [msg]
Reputation Points: 99
Solved Threads: 5
Junior Poster
Evenbit is offline Offline
140 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Assembly programming motorola 6800 ebook_example codes please...
Next Thread in Assembly Forum Timeline: help with MIPS snprintf function?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC