0

Hi have a program in NASM and in this part of the code

section .data
fileName dq 1

section .text
global _start
_start:
    xor rax, rax
    xor rcx, rcx
    xor rdx, rdx
    xor rbx, rbx
    mov rbx, rsp
    mov fileName, qword [rbx+16]
    push rsp

i have the error

test.asm:59: error: invalid combination of opcode and operands

and the line 59 is mov fileName, qword [rbx+16]

Why is it wrong? And how can i solve it?

one user
  • 109
  • 9
  • @Carcigenicate: You cannot have two explicit memory operands for the same instruction. – ecm Jan 03 '21 at 17:48
  • 2
    It’s hard to tell what it should be without seeing what comes next. [rbx+16] is argv[1]. Probably you want two instructions: `mov rax, [rbx+16]; mov [fileName], rax` – prl Jan 03 '21 at 17:58
  • 1
    Note that rax was cleared a few lines before. If subsequent code needs rax to be 0, you need to move the xor instruction after using rax with the filename. – prl Jan 03 '21 at 18:56
  • @prl yeah i did that !! Thank you – one user Jan 03 '21 at 18:59
  • If this is setup for a system call, `syscall` doesn't care about RCX. And Linux `int 0x80` is the 32-bit compat ABI, only using 32-bit pointers so you can't pass it stack addresses. Also, `xor ebx,ebx` before `mov rbx, rsp` is redundant; you're already overwriting it. Also, you could just `mov rax, [rsp+16]` instead of messing around with RBX first. – Peter Cordes Jan 04 '21 at 08:56

0 Answers0