How to Convert Decimal Input to Hex in Assembly Language?

Click For Summary
SUMMARY

This discussion focuses on converting decimal input to hexadecimal values in Assembly language. The user seeks to transform a double-digit decimal input, specifically converting 45 (decimal) to 2D (hexadecimal). The proposed method involves multiplying the tens digit by 10 and adding the units digit, with considerations for ASCII representation and potential masking and shifting operations for packed values. The implementation details are left for the user to complete.

PREREQUISITES
  • Understanding of Assembly language syntax and operations
  • Familiarity with hexadecimal and decimal number systems
  • Knowledge of ASCII encoding and byte manipulation
  • Experience with bitwise operations such as masking and shifting
NEXT STEPS
  • Research Assembly language techniques for byte manipulation
  • Learn about ASCII to decimal conversion methods in Assembly
  • Explore masking and shifting operations in Assembly language
  • Study the implementation of arithmetic operations in Assembly
USEFUL FOR

This discussion is beneficial for Assembly language programmers, computer science students, and anyone interested in low-level data manipulation and number system conversions.

kloong
Messages
35
Reaction score
0
Assembly language. how to change the 80h in my register to 50h?
that goes to others to. like 45h to 2Dh.

basically, i came up with a sequence to change the user's double digit decimal input to hex value.

i.e.
when i enter 45, AL = 45h
how do i change it to 2Dh??

; al = 45h. how to change it to 2Dh?


45(decimal) = 2Dh.
must be able to do this for other conversion.
 
Physics news on Phys.org
kloong said:
Assembly language. how to change the 80h in my register to 50h?
that goes to others to. like 45h to 2Dh.

basically, i came up with a sequence to change the user's double digit decimal input to hex value.

i.e.
when i enter 45, AL = 45h
how do i change it to 2Dh??

; al = 45h. how to change it to 2Dh?


45(decimal) = 2Dh.
must be able to do this for other conversion.

I'm not quite sure if I completely understand your question, but wouldn't the user's input in this case be two ASCII bytes? (The ASCII characters for '4'--0x34, and '5'--0x35) Unless you've already parsed these by ANDing with 0xf0)

If that's the case, you can simply multiply the first byte by 10, and add it to the second byte. Simple base 10 long form, as you probably did in elementary. In this case, 4 x 10 is 40 is 0x28 and when you add 5 to it, you get 0x2d, as in your example. If instead, it's packed into one byte, you'll need to do some masking and shifting before multiplying the 10s digit by 10 and adding it to the 1s digit.

The actual implementation is left as a task to the user.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
11K
Replies
11
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 5 ·
Replies
5
Views
4K