Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   need a guide for doing the number conversion (http://www.go4expert.com/forums/guide-doing-conversion-t21601/)

sophie88 31Mar2010 22:27

need a guide for doing the number conversion
 
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...

xpi0t0s 1Apr2010 11:38

Re: need a guide for doing the number conversion
 
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!

sophie88 5Apr2010 00:09

Re: need a guide for doing the number conversion
 
thanks for your guide....but i still confused what kind of coding i should put in..any coding reference?

xpi0t0s 5Apr2010 13:52

Re: need a guide for doing the number conversion
 
What processor are you programming? Each one has its own language.

sophie88 5Apr2010 22:35

Re: need a guide for doing the number conversion
 
is a x86 processor to programing..


All times are GMT +5.5. The time now is 06:56.