在 Assembly 中将 128 位整数转换为字符串
Convertion of 128-bit integer to string in Assembly
我正在尝试将整数转换为字符串以便输出;
但是我在两个寄存器中使用 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.
这应该是一个好的开始,我建议 运行 通过你的湿软件手动进行它,以便你了解它是如何工作的。
然后您只需计算出执行伪代码所执行操作的汇编指令即可。这应该不会太麻烦,因为它很可能是一对一的映射。
我正在尝试将整数转换为字符串以便输出;
但是我在两个寄存器中使用 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.
这应该是一个好的开始,我建议 运行 通过你的湿软件手动进行它,以便你了解它是如何工作的。
然后您只需计算出执行伪代码所执行操作的汇编指令即可。这应该不会太麻烦,因为它很可能是一对一的映射。