I am trying to duplicate the following c codde in assembly language:
long hex_read(char data_buf[]){
return read(0,data_buf,16);
}
And this is my implementation in assembly language:
.globl hex_read
hex_read:
subq $8,%rsp
movq %rdi,%rsi
movq $0,%rdi
movq $16,%rdx
call read
addq $8,%rsp
ret
I then tested this assembly code by creating a main assembly function.
.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
But when I test it in gdb, no matter what I input I will get 0 for the returning value of hex_read( stored in %rax), which is weird. Can someone tell me what I am doing wrong here? Thank you so much.