繁体   English   中英

在Assembly x86中打印注册

[英]Print Register in Assembly x86

接下来是几个在线文档但当我尝试打印我存储在寄存器%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

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

请记住,对于多位数字,您需要更好的转换程序。

这个系统调用是一个write 在C中,siganture将是:

int write(int fd[ebx], char *p[ecx], int size[edx]);

现在看一下你的代码, ebxedxeax就可以了。 但是ecx是指向缓冲区的指针,而不是字符。 而且我真的不知道是什么

add eax, ecx

应该这样做,因为你的代码片段中没有定义eax

所以你需要做的是,在内存中保留一个缓冲区,将要写入的字节放入其中,然后让ecx指向它。

如果eax应该是0-9范围内的单个数字,那么如果你把mov $'0', ecx更加可读。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM