0

I'm loading string in rcx and moving rcx + 8bytes and padding with zeros and store in %r8

%r8 will contain 0x72, 72 is the ascii for the letter "r". Using movq to move value of r8 into rdi which makes rdi 0x72. However on call puts i get sigsev, cannot access memory at 0x72. Why can't I do this?

        .data
string:    .asciz    "Hello world!"
.global main 
.text 

main: 
    leaq   string, %rcx
    movq $4, %rax 
    movzbq 4(%rcx,%rax,1), %r8 
    movq %r8, %rdi
    call puts
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Vini
  • 25
  • 7
  • 2
    puts takes a `char*` pointer arg, and you passed `0x72` as the address. Maybe you're looking for `call putchar` which takes a `char` by value. – Peter Cordes Sep 17 '20 at 16:39
  • 1
    Hint: in C, what is the difference between `puts("r")` and `puts('r')`, and why does the first one work while the second does not? – Nate Eldredge Sep 17 '20 at 17:57
  • 1
    You also have a problem with stack alignment. https://stackoverflow.com/questions/49391001/why-does-the-x86-64-amd64-system-v-abi-mandate-a-16-byte-stack-alignment/49397524#49397524 – Nate Eldredge Sep 17 '20 at 17:58
  • Thank you, makes sense! – Vini Sep 17 '20 at 18:33

0 Answers0