Assembly language. conversion.

In summary, the conversation is about converting a user's double digit decimal input to a hex value using assembly language. The user is trying to change the input of 45(decimal) to 2Dh and is looking for guidance on how to do this for other conversions as well. The solution involves multiplying the first byte by 10 and adding it to the second byte, or masking and shifting before multiplying and adding. The details of the implementation are left to the user.
  • #1
kloong
36
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
  • #2
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.
 
  • #3


Assembly language is a low-level programming language that uses mnemonic codes to represent machine instructions. It is a direct representation of the machine code and is used to write programs that can be directly executed by a computer's processor.

To change the value in a register, you can use the MOV (move) instruction. For example, to change the value in the AL register from 80h to 50h, you can use the following code:

MOV AL, 50h

This will move the value 50h into the AL register, replacing the previous value of 80h.

To convert a decimal value to a hex value in assembly language, you can use the DIV (divide) instruction. This instruction divides the value in the AX register by the specified value and stores the quotient in the AL register and the remainder in the AH register.

For example, to convert the decimal value 45 to a hex value, you can use the following code:

MOV AX, 45 ; move the value 45 into the AX register
MOV BL, 16 ; move the value 16 into the BL register (16 is the decimal equivalent of 10h, which is used for hex conversion)
DIV BL ; divide AX by BL, resulting in a quotient of 2 and a remainder of D (13 in decimal)
ADD AH, 30h ; add 30h (decimal equivalent of 0 in ASCII) to the AH register to convert the remainder to its ASCII representation
ADD AL, 30h ; add 30h (decimal equivalent of 0 in ASCII) to the AL register to convert the quotient to its ASCII representation
MOV DL, AH ; move the value in AH to DL register
MOV DH, AL ; move the value in AL to DH register
; DL and DH now hold the hex representation of the decimal value 45 (2Dh)

This process can be repeated for other conversions as well. Keep in mind that assembly language is very specific and requires precise instructions and syntax, so it is important to double check your code and make sure it is correct.
 

1. What is assembly language and why is it used?

Assembly language is a low-level programming language that uses mnemonic codes to represent machine instructions. It is used to directly communicate with the computer's hardware, making it more efficient for certain tasks such as system programming and device driver development.

2. How is assembly language converted into machine code?

Assembly language is converted into machine code through a process called assembly or compilation. This involves using an assembler program to convert the mnemonic codes into their corresponding binary codes, which can then be executed by the computer's processor.

3. Are there different types of assembly languages?

Yes, there are different types of assembly languages for different types of processors and computer architectures. Some popular examples include x86 assembly for Intel processors and ARM assembly for mobile devices.

4. Is it necessary to learn assembly language to become a successful programmer?

No, it is not necessary to learn assembly language to become a successful programmer. Many high-level programming languages have been developed to make programming more accessible and efficient for general tasks. However, having knowledge of assembly language can be beneficial for low-level tasks and understanding how computers work at a deeper level.

5. Are there any disadvantages to using assembly language?

While assembly language can be more efficient for certain tasks, it also has some drawbacks. It can be more difficult to learn and understand compared to high-level languages, and it is not as portable between different computer architectures. Additionally, making changes or updates to assembly code can be more time-consuming and prone to errors.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
22
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Programming and Computer Science
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top