I'm supposed to get a 4-digit number from the user, convert it to binary (and hex), then print it out.

I have absolutely no idea where to start. I know the algorithm; taking the number, diving it by 2, repeat until the number reaches 0 and the remainders of everything from bottom up is the number in binary (same with diving by 16 for hex).

I have a little pseudo-code for the binary conversion part:

while number > 0

mov number, eax
mov ebx, 2
divide ebx
mov binary, edx ;Remainder
mov number, eax ;Quotient

(Courtesy of help from another forum)

Despite knowing what I want to do , I have no idea how to implement it into assembly (intel 80186). Can anyone please help? I'm urgently needing a solution. I've googled this beforehand too but could not find an appropriate solution.

Thanks in advance!

Recommended Answers

All 3 Replies

How will the user enter the number?
Will you get it in ASCII?
What operating system?

How will the user enter the number?
Will you get it in ASCII?
What operating system?

Via prompting, then they just type in the number.
I have no idea about this one...I'm guessing that's fine too?
Not too sure about this last one either (not my computer), but on the assignment sheet it said 'intel 80186 and higher'.

I missed the part about 80186, so it is probably DOS. If they type the number, getting it from standard input might be easiest, and ASCII/ANSI characters will be the input.

Here's some help on buffered input:
http://www.ctyme.com/intr/rb-2563.htm
http://www.frontiernet.net/~fys/kbbuffio.htm
The first one is reference material, the second has an example, but your assembler may use different syntax.

You need to subtract 30h from each character to get the actual value of the digit. (The "3" character is represented by 33h in ASCII.)

Hope this gets you started.

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.