-2

I have a Hexadecimal value in AL register in 8086 programming. How can I change it into decimal number?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 4
    The values in registers are just numbers. They aren't hexadecimal numbers or decimal numbers. If you want to be really pedantic, they are all stored internally as binary numbers. – Raymond Chen Jul 08 '22 at 15:58
  • 2
    Hex and decimal are number *formats* -- they are ways to represent/communicate/show numbers as a sequence of characters, i.e. in string form. – Erik Eidt Jul 08 '22 at 15:59

2 Answers2

4

You don't have a hexadecimal number, you have a binary number. That's the only kind in digital processors. If you need to display it in decimal - you need to convert it to ASCII string manually, here's an example: https://stackoverflow.com/a/23959237/4632951

Andrew Morozko
  • 2,576
  • 16
  • 16
  • 2
    SO's canonical answers for this are [Displaying numbers with DOS](https://stackoverflow.com/q/45904075) for x86-16 DOS, and a few including [How do I print an integer in Assembly Level Programming without printf from the c library?](https://stackoverflow.com/a/46301894) . For converting a number in a register into ASCII hex, see [How to convert a binary integer number to a hex string?](https://stackoverflow.com/q/53823756) – Peter Cordes Jul 09 '22 at 01:26
1

How can I change it into decimal number?

Use math!

If you have a number and want to know the value of the last digit, in decimal, you would do modulus 10.  So, if the number is 1234 then %10 on that would give you 4, and if the number is 5678, then %10 on that would yield 8.

Similarly, if you wanted to work on the 123 part you would divide 1234 by 10 to get 123.  Now you can %10 on that result to get 3.

There are algorithmic write ups of these, generally called itoa or integer to ascii/string.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53