-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
0

1 Answer 1

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"?

Sign up to request clarification or add additional context in comments.

4 Comments

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.
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.
could write me that in code pls. i don't know how to do it.thanks
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.