Reputation: 129
I'm trying to run this code and print the result, but for some reason I get this error message:
main.asm:10: error: invalid operands in non-64-bit mode main.asm:11: error: invalid operands in non-64-bit mode main.asm:12: error: invalid operands in non-64-bit mode main.asm:13: error: invalid operands in non-64-bit mode ld: cannot find *.o: No such file or directory
This is the code:
global _start
section .data
n DB 10
section .text
_start:
xor ax, ax
mov bx, 1
mov cx, (n)
.L1:
mov r9w, bx #one of the lines that leads to an error
imul r9w, bx #one of the lines that leads to an error
imul r9w, bx #one of the lines that leads to an error
add ax, r9w #one of the lines that leads to an error
inc bx
dec cx
test cx, cx
jne .L1
movq rax, 1
movq rdi, 1
movq rsi, ax
movq rdx, 8
syscall
xor rax, rax
ret
END:
I am fairly new to assembly and can't quite understand what the problem is - the BX register is 16 bits, and R9W is also 16 bits...
I use an online compiler to run this (https://www.tutorialspoint.com/compile_assembly_online.php)
Upvotes: 1
Views: 278
Reputation: 342
I see three main problems with your code:
ret
instruction. This can cause a segmentation fault because the stack currently contains a pointer to argc
mov
instruction rather than the movq
instruction.Upvotes: 3