【问题标题】:Interger print in Linux AssemblyLinux Assembly 中的整数打印
【发布时间】:2017-06-19 06:59:59
【问题描述】:
section .text

global _start

_start:

        mov eax, 4
        mov ebx, 1
        mov edx, num
        int 0x80
        mov eax, 1
        mov ebx, 0
        int 0x80

section .data

        num db 5

~

它编译得很好,但什么也没打印。谁能告诉我怎么回事?

【问题讨论】:

  • 您需要将数字 5 转换为数字“5”。亲自查看:将num db 5 替换为num db "5"。当然,一般方法需要itoa 等效项。 SO Doc 对此有所了解。
  • 我必须像这样写?数字分贝“5”?
  • 试试看会发生什么 :) 看一下 ASCII 表,虽然 ASCII 可能不是您的终端使用的字符集,但前 127 个字符在所有西方字符集中都是相同的。记住:你写的是字符串而不是数字。
  • 我几乎已经尝试过了。但仍然没有打印任何内容。请你写正确的代码,因为我真的不明白你。谢谢。
  • 查阅系统调用表以正确使用寄存器:)

标签: linux assembly printing


【解决方案1】:

您没有正确使用sys_write。字符串地址should go into ecx, and the number of bytes to write should go into edx

    mov eax, 4
    mov ebx, 1    ; fd (stdout)
    mov ecx, num  ; const char*
    mov edx, 1    ; count
    int 0x80

【讨论】:

  • 您还应该提到,为了使此代码能够正常工作,David 必须按照 Margaret 在 cmets 中建议他的操作,并将 num 更改为字符串,而不是整数。
猜你喜欢
  • 2011-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-29
  • 1970-01-01
  • 2022-11-09
  • 2012-03-26
相关资源
最近更新 更多