在程序集

时间:2016-03-21 12:35:15

标签: assembly nasm system-calls

我正在尝试将整数转换为字符串以便输出; 但我在两个寄存器中使用x86_64和NASM程序集,而整数是128位。 所以我不知道如何输出它; 谢谢!

1 个答案:

答案 0 :(得分:0)

这是一种(汇编式)算法,可用于无符号整数。从数字n开始:

start:
    if n is non-zero then goto nonZeroNum.
    output '0'.
    return.

nonZeroNum:
    set digitCount to zero.
numLoop:
    get n modulo 10 and push it onto the stack.
    increment digitCount.
    divide n by 10 (integer division).
    if n is non-zero then goto numLoop.

digitLoop:
    pop digit.
    convert number to character (eg, adding 48 for ASCII).
    output that character.
    decrement digitCount.
    if digitCount is non-zero then goto digitLoop.

这应该是一个良好的开端,我建议您手动通过湿软件运行它,以便了解它是如何工作的。

然后,您只需要编制将执行伪代码操作的汇编指令。这不应该太麻烦,因为它可能是一对一的映射。