关注了几个在线文档但是当我尝试打印存储在寄存器%ecx中的数字时,没有任何反应。这可能是因为我基本上执行计算然后尝试在循环中打印吗?
mov $48, %ecx #Convert to ascii
mov $1, %edx #Print Byte
add %eax, %ecx
mov $4, %eax #Output To Console
mov $1, %ebx #File Descriptor - Standardout
int $0x80 #Call the Kernel
答案 0 :(得分:5)
write
系统调用需要指向要打印的数据的指针。据我所知,你有一个数字。您可以暂时将其存储在堆栈上进行打印,如下所示:
mov $48, %ecx #Convert to ascii
mov $1, %edx #Print Byte
add %eax, %ecx
push %ecx # store on stack
mov %esp, %ecx # load address
mov $4, %eax # Output To Console
mov $1, %ebx # File Descriptor - Standardout
int $0x80 # Call the Kernel
pop %ecx # clean up stack
请记住,对于多位数字,您需要更好的转换程序。
答案 1 :(得分:2)
此系统调用是write
。在C中,siganture将是:
int write(int fd[ebx], char *p[ecx], int size[edx]);
现在查看您的代码,ebx
,edx
和eax
即可。但ecx
是指向缓冲区的指针,而不是字符。此外,我真的不知道是什么
add eax, ecx
应该这样做,因为您的代码段中未定义eax
。
所以你需要做的是,在内存中保留一个缓冲区,将要写入的字节放入其中,让ecx
指向它。
如果eax
应该是0-9
范围内的单个数字,那么如果您放置mov $'0', ecx
,它就会更具可读性。