0
compiler: nasm
asm: x64
OS: Debian x64

Hello, I'm starting to get deeper and deeper into the assembly, and in this case I want to train a bit with a pile.

I wanted to push the value "AAAAAA" onto the stack and just display it with the sys_write system call, but after compiling the code nothing displays.

.text:
        global _start

_start:

        mov rax,'AAAAAAA'
        push rax

        mov rax,0x1
        mov rdx, 9
        mov rsi, [rsp+4*rsi]
        mov rdi,1
        syscall

        ;exit
        mov rax, 60
        mov rdi, 0
        syscall

before, I tried yet with this version

        mov rax,0x1
        mov rdx, 9
        pop rsi
        mov rdi,1
        syscall

but still not working, I miss some important detail in my knowledge, I feel that I'm getting closer but I can't get it out :(

Could this thread be a potential cause of my problem? :): Why do system calls use a different stack?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
reg3x_mr
  • 75
  • 1
  • 10
  • 1
    `write(int fd, void *buf, size_t len)` wants a *pointer* in RSI. You're loading the *value*. (Or loading some garbage, since you don't set RSI before using it in an addressing mode; in a dynamically-linked executable RSI would likely be non-zero on entry to _start!). So for example, `mov rsi, rsp`. See also [How do I print an integer in Assembly Level Programming without printf from the c library?](https://stackoverflow.com/a/46301894) for an example of printing from a stack buffer. – Peter Cordes May 01 '21 at 08:21
  • 1
    [Printing something in stack (assembly)](https://stackoverflow.com/a/46750560) shows a nice simple example, but the question has a different problem from yours. – Peter Cordes May 01 '21 at 08:28
  • @PeterCordes it's funny, it was enough to change ```mov``` to ```lea rsi, [rsp]```, but I was sure that "mov" was already working on addresses in memory – reg3x_mr May 01 '21 at 10:36
  • `mov reg, [address]` loads from memory. `lea reg, [address]` puts the address into the destination, just doing the address math. If the address you want is already in a register, `lea reg, [reg]` is just an inefficient way to write `mov reg,reg`. Note the lack of brackes on the source operand in that mov: it's *not* using the register as an address, just taking the bits from it. – Peter Cordes May 01 '21 at 10:42

0 Answers0