Click here to Skip to main content
15,888,016 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have this assignment to convert 25(10) -> binay(2) in assembly language. I don't know what to do next:

What I have tried:

INP, X, AD1 //a
INP, X, AD2 //2
FEA, X, AD1 //A=a
MOD, X, AD2 //
Posted
Updated 16-Nov-16 2:44am
v3
Comments
Jochen Arndt 16-Nov-16 7:39am    
'25' and '11001' are just two representations of the same value. So storing it into a register or memory using an appropriate assembler directice does the job.

Translating what CPallini told in the other answer...

You can translate decimal to binary manually too:
25 / 2 = 12, rest = 1
12 / 2 =  6, rest = 0
6  / 2 =  3, rest = 0
3  / 2 =  1, rest = 1

Now you just have to go backwards with the results and you get the binary 11001

Another example: 147
147 / 2 = 73, rest = 1
73  / 2 = 36, rest = 1
36  / 2 = 18, rest = 0
18  / 2 =  9, rest = 0
9   / 2 =  4, rest = 1
4   / 2 =  2, rest = 0
2   / 2 =  1, rest = 0
gives you: 10010011

Now you can try to implement it in the specific language of your needs

note: this will always give you the binary until the first representative 1, if you want to have them grouped in bytes (with zeros filling the left side) you have to do it yourself counting how many "digits" do you get and filling them by hand
 
Share this answer
 
v2
Comments
Klajdi Murati 16-Nov-16 7:56am    
I know how to convert a decimal number into binary. I just don.t know how to do that USING ASM
Dave Kreskowiak 16-Nov-16 8:39am    
We're not going to write your code for you.

Also, the code that you do write is entirely dependent on the assembler you're using and the platform you're targeting.
Nelek 16-Nov-16 8:49am    
"I don't know what to do next" is not that clarifying. I just gave you an idea for an algorithm, if you already now how to do that, then you should have given more details in your question.
To obtain the string representation of a the binary number you could iteratively test the most significant bit and then shift left the number. The details of the implementation depend on the assembly language you are using.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900