-1

1) Convert a decimal number to hex.

I dont know how to convert decimal to hex. I just input a number but i have no clue how to start next. Any help is appreciated.

TITLE   
include irvine32.inc
.data
a dword ?
b dword ?
final dword ?
count dword 0
prompt1 byte ,'Enter a number',0
.code
main PROC
    mov edx,offset prompt1
    call writestring
    call readint
    mov a,eax
main ENDP

END main
rkhb
  • 14,159
  • 7
  • 32
  • 60
lhag
  • 13
  • 2
  • 7

1 Answers1

1

Probably what they want from you is to write a loop that divides by 16 and gets the remainder of division by 16. It is not very clear, however, what you're asking. What is "prompt1"?

major4x
  • 432
  • 3
  • 15
  • i am getting a number from keyboard and i have to convert that to hex. Prompt1 is getting an input from user. Should i divide a by 16? since a is the decimal number to be converted to hex. – lhag Dec 05 '13 at 23:46
  • Ah, I see, you should subtract ASCII 0 if it is a digit between 0 and 9 or subtract ASCII 'a' if it is between 'a' and 'f' and add 10. Also one may enter the keycode uppercase. – major4x Dec 05 '13 at 23:50
  • could write me that in code pls. i don't know how to do it.thanks – lhag Dec 05 '13 at 23:58
  • 2
    `call WriteHex`. But I strongly suspect that you're supposed to do it yourself. Yes, you want to divide by 16, but probably not by using `div` (you could, but it's slow). I like a rotate, myself. Rotate the 4 leftmost bits into the rightmost position, mask 'em off, add '0', if above '9' add another 7 (27h if you like lowercase), `call WriteChar`... until done. – Frank Kotler Dec 06 '13 at 05:46