如何使用汇编语言将十进制数转换为二进制? [英] How to convert a decimal number to binary using assembly language?

查看:1176
本文介绍了如何使用汇编语言将十进制数转换为二进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此转换25(10) - > binay(2)用汇编语言编写。我不知道下一步该做什么:



我尝试过的事情:



INP,X,AD1 // a

INP,X,AD2 // 2

FEA,X,AD1 // A = a

MOD,X,AD2 //

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 //

推荐答案

翻译CPallini在其他答案中所说的内容......



您也可以手动将十进制转换为二进制:

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



现在你只需要向后看结果就可以得到二进制数11001



又如:147


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

为您提供: 10010011



现在你可以尝试用你需要的特定语言来实现它



注意:这总是会给你二进制,直到第一个代表1,如果你想让它们按字节分组(零填充左侧)你必须自己计算你有多少数字手动获取并填充它们

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


要获得二进制数字的字符串表示,您可以迭代地测试最高位,然后向左移动数字。实现的细节取决于您使用的汇编语言。
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.


这篇关于如何使用汇编语言将十进制数转换为二进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆