在程序集中将 128 位整数转换为字符串



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

下面是可用于无符号整数的(程序集样式)算法。从数字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.

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

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

最新更新