复制汇编代码中的read函数

问题描述

我正在尝试使用汇编语言复制以下c代码

long hex_read(char data_buf[]){
  return read(0,data_buf,16);
}

这是我在汇编语言中的实现:

    .globl hex_read
hex_read:
    subq $8,%rsp
    
    movq %rdi,%rsi
    movq $0,%rdi
    movq $16,%rdx
    call read

    addq $8,%rsp
    ret

然后我通过创建一个主汇编函数来测试此汇编代码

    .section .text
hex_read_buf:   .space 16


    .globl main

    
main:
    subq $8,%rsp
    movq $hex_read_buf,%rdi
    call hex_read
    addq $8,%rsp
    ret

但是,当我在gdb中对其进行测试时,无论我输入什么内容,hex_read(存储在%rax中)的返回值都将为0,这很奇怪。有人可以告诉我我在做什么错吗?非常感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)