need a guide for doing the number conversion

Discussion in 'Assembly Language Programming (ALP) Forum' started by sophie88, Mar 31, 2010.

  1. sophie88

    sophie88 New Member

    Joined:
    Mar 31, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I am doing the assembly program that allows the user to input a decimal number to calculate and print out the corresponding binary and hexadecimal value.but i really not understand about the logical and the code what i should put for...any guide and coding for me to doing this kind of program? thanks...
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    After inputting the number from the user, set a variable V to zero. Loop over each digit from right to left and multiply V by 10, add the character code from the input and subtract the character code for '0'. This is because '0'-'9' are consecutive in the characterset, so '5'-'0'=5.

    For the hex output, loop over V from left to right and get the byte value. Divide by 16 to get the upper 4 bits. If the resulting value is between 0 and 9 then add '0' and display the result. If the value is between 10 and 15 then add 'a' and subtract 10, and display the result. Then get the byte value again and AND it with 15 to get the lower 4 bits, and display the value in the same way as the upper 4.

    For the binary output, loop over V from left to right and get the byte value Y. Initialise a bitmask variable B to 128 and AND this with Y. If the result is zero, display '0', otherwise display '1'. Divide B by 2 and repeat for the 6th binary digit. Keep dividing B by 2 and displaying bits until B=0. Then go onto the next byte value, reinitialise B to 128 and continue until you're done.

    Easy!
     
  3. sophie88

    sophie88 New Member

    Joined:
    Mar 31, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    thanks for your guide....but i still confused what kind of coding i should put in..any coding reference?
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    What processor are you programming? Each one has its own language.
     
  5. sophie88

    sophie88 New Member

    Joined:
    Mar 31, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    is a x86 processor to programing..
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice