您的数字将迅速增长,而不仅仅是一个数字。您应该做的是输入一个整数
num而不是一个字符,然后将该整数转换为可以使用打印的字符串
sys_write。
这是进行转换的一种方法:重复除以10,首先获得最低的位数作为余数:
; Input:; eax = integer value to convert; esi = pointer to buffer to store the string in (must have room for at least 10 bytes); Output:; eax = pointer to the first character of the generated string; ecx = length of the generated stringint_to_string: add esi,9 mov byte [esi],0 ; String terminator mov ebx,10.next_digit: xor edx,edx ; Clear edx prior to dividing edx:eax by ebx div ebx ; eax /= 10 add dl,'0' ; Convert the remainder to ASCII dec esi ; store characters in reverse order mov [esi],dl test eax,eax jnz .next_digit ; Repeat until eax==0 ; return a pointer to the first digit (not necessarily the start of the provided buffer) mov eax,esi ret
您可以这样使用:
mov dword [num],1 ... mov eax,[num] ; function args using our own private calling convention mov esi,buffer call int_to_string; eax now holds the address that you pass to sys_write ...section .bss num resd 1 buffer resb 10
您的倍数可以简化为
shl dword [num],1。或者更好的是,在仍与保持一致时,将其加倍
add eax,eax。



