# Help! Dec to Hex,Oct,Bin Converter

How to create a program in assembly language using ms-dos on windows xp that will input to digit decimal number and convert it to hexa,ocatl,and binary numbers. Help me pls.... Thankz...

• : How to create a program in assembly language using ms-dos on windows
: xp that will input to digit decimal number and convert it to
: hexa,ocatl,and binary numbers. Help me pls.... Thankz...
:

Is that the equivalent of the "How to do my homework"-question?
We're willing to [b]help[/b] you, with emphasis on 'help' - we're not willing to make your homework for you.

Please post your attempt and ask specific questions about parts you do not know. You could not possibly be stuck on the whole program - because if that's so then this little program is too much and you should first learn the basics of assembly.

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry
• : : How to create a program in assembly language using ms-dos on windows
: : xp that will input to digit decimal number and convert it to
: : hexa,ocatl,and binary numbers. Help me pls.... Thankz...
: :
:
: Is that the equivalent of the "How to do my homework"-question?
: We're willing to [b]help[/b] you, with emphasis on 'help' - we're
: not willing to make your homework for you.
:
: do not know. You could not possibly be stuck on the whole program -
: because if that's so then this little program is too much and you
: should first learn the basics of assembly.
:
: Best Regards,
: Richard
:
: The way I see it... Well, it's all pretty blurry

im having hard time to get the two decimal input using int 21 service 1 because it gets only one digit per int 21 and to get the 2nd digit i used int 21 again. I dont know how to input two digit and put the exact input to AX not the equivalent hexa of the ascci symbol I input! Help Pls... Thankz...
• : : : How to create a program in assembly language using ms-dos on windows
: : : xp that will input to digit decimal number and convert it to
: : : hexa,ocatl,and binary numbers. Help me pls.... Thankz...
: : :
: :
: : Is that the equivalent of the "How to do my homework"-question?
: : We're willing to [b]help[/b] you, with emphasis on 'help' - we're
: : not willing to make your homework for you.
: :
: : do not know. You could not possibly be stuck on the whole program -
: : because if that's so then this little program is too much and you
: : should first learn the basics of assembly.
: :
: : Best Regards,
: : Richard
: :
: : The way I see it... Well, it's all pretty blurry
:
: im having hard time to get the two decimal input using int 21
: service 1 because it gets only one digit per int 21 and to get the
: 2nd digit i used int 21 again. I dont know how to input two digit
: and put the exact input to AX not the equivalent hexa of the ascci
: symbol I input! Help Pls... Thankz...
:
You can convert the ascii value to its "natural" value by subtracting the ascii value of zero (0) from it. This way you'll get 2 separate digits, which can then be put together to form the 2 digit number you need.
• : You can convert the ascii value to its "natural" value by
: subtracting the ascii value of zero (0) from it. This way you'll get
: 2 separate digits, which can then be put together to form the 2
: digit number you need.

Sorry but i didn't get it. What do you mean by subtracting the ascii value of zero(0)??? Thankz..
• : : You can convert the ascii value to its "natural" value by
: : subtracting the ascii value of zero (0) from it. This way you'll get
: : 2 separate digits, which can then be put together to form the 2
: : digit number you need.
:
: Sorry but i didn't get it. What do you mean by subtracting the ascii
: value of zero(0)??? Thankz..
:

When the user inputs '0', then you will receive the value 48. This is because the character '0' has ASCII code 48. The ascii table (if the link doesn't work just Google for "ASCII Table")
http://www.neurophys.wisc.edu/comp/docs/ascii.html

So, what you do is when you get an input is, 1) check if it's valid (eg in the range '0'-'9') and 2) Convert it to a number.
For a single digit, to get the numeric value, substract by the ascii value of '0' (= 48). Then '0'->0, '1'->1, ... , and '9'->9 (because '0' to '9' are ordened contiguously from small to large in the ascii table).

Then the third problem would be to combine multiple of these converted digits. I suggest the following algorithm:
[code]
1) Store the first digit in a register
2) Then, for each additional digit, multiply the value of the register
by 10, and add the new digit. Store this value in the register again
3) The final number in the register is the number entered by the user
in decimal notation
[/code]

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry
• : When the user inputs '0', then you will receive the value 48. This
: is because the character '0' has ASCII code 48. The ascii table (if
: http://www.neurophys.wisc.edu/comp/docs/ascii.html
:
: So, what you do is when you get an input is, 1) check if it's valid
: (eg in the range '0'-'9') and 2) Convert it to a number.
: For a single digit, to get the numeric value, substract by the ascii
: value of '0' (= 48). Then '0'->0, '1'->1, ... , and '9'->9 (because
: '0' to '9' are ordened contiguously from small to large in the ascii
: table).
:
: Then the third problem would be to combine multiple of these
: converted digits. I suggest the following algorithm:
: [code]:
: 1) Store the first digit in a register
: 2) Then, for each additional digit, multiply the value of the register
: by 10, and add the new digit. Store this value in the register again
: 3) The final number in the register is the number entered by the user
: in decimal notation
: [/code]:
:
:
: Best Regards,
: Richard
:
: The way I see it... Well, it's all pretty blurry

if i use int 21 service 1, ex. I input 0 the hexa of its ascii code which is 30 will be store in the AL register? why should i subtract it by 48 not 30? May I put here my code? we only allow to used the ms-dos in windows we are not allowed to used any other compiler so Im having hard time!
• : if i use int 21 service 1, ex. I input 0 the hexa of its ascii code
: which is 30 will be store in the AL register? why should i subtract
: it by 48 not 30?

Because 48 in decimal is 30 in hexadecimal. Substracting by 48 is the same as substracting 30h (30 in hexadecimal).
Which you have to write (48 or 30h) depends on your compiler. Most compilers default to decimal notation and can be forced to use hexadecimal by prefix 0x, or post-fixing h.
In the case of Debug.exe, I think it defaults to hexadecimal notation, in which case you need to use the hexadecimal value 30 and not the decimal one.

: May I put here my code?
:
Please do Code says more than it's equivalent in words (atleast most of the time)

: we only allow to used the
: ms-dos in windows we are not allowed to used any other compiler so
: Im having hard time!
:

I assume you mean Debug.exe?
It's not meant to write programs, really. It's only meant to create very small debug codes.

What you need to do is first write the ASM code in a text file and when you're done, you insert each line into Debug.exe.
Label conversion here is going to be a bit of a problem. Probably, you'll have to do a '2-pass': first time, just use 0 for any jump instructions/data references, and then check what the 0 *should* have been. Then insert (or perhaps modify, if that's possible?) the code again only then using the correct values for the jump and data-references.

PS: Maybe it would be a good idea to bend the rules? Write the ASM instructions in a text file, then compile with NASM (Netwide Assembler - downloadable for free) and then check the resulting binary code for which jump offsets to use. Ofcourse, if you need to do some kind of examn in this and use Debug.exe there, it might be a good idea to get used to doing it the Debug way (which is no way to program).

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry