0

I'm working on a code in x64 that finds the maximum number of a set of data items. I am currently reading Programming from the ground up so I have to convert everything from 32 to 64. I keep getting this error every time I compile the program.

maximum.asm:22: error: comma, colon, decorator or end of line expected after operand
maximum.asm:22: error: comma, colon, decorator or end of line expected after operand
maximum.asm:28: error: comma, colon, decorator or end of line expected after operand
maximum.asm:28: error: comma, colon, decorator or end of line expected after operand
1 section .data
12         ;These are the data items
13
14 data_items:
15  db   3,67,34,222,45,75,54,34,44,33,22,11,66,0
16
17 section .text
18
19  global _start
20 _start:
21 mov $0, rdi                              
22 mov data_items(,rdi,8), rax             
23 mov rax, rbx                            
24
25 start_loop:                             
26 je loop_exit                             
27 inc rdi                               
28 mov data_items(,rdi,8), rax
29 cmp rbx, eax                            
30 jle start_loop                        
31 mov rax, rbx                            
32 jmp start_loop                         
33
34 loop_exit:
37 mov $1, rax
38 syscall
39
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

2

This is a mix of AT&T and Intel syntax, and using NASM db and section directives. NASM only supports Intel syntax. https://stackoverflow.com/tags/intel-syntax/info

Also, you can't port Linux 32-bit system calls to x86-64 by just changing int 0x80 to syscall. The calling convention is different and so are the call numbers. What are the calling conventions for UNIX & Linux system calls on i386 and x86-64

Don't try to port your tutorials to 64-bit while you're still learning the basics! Just build with nasm -felf32 foo.asm and gcc -m32 -static -nostdlib foo.o to make 32-bit executables. Trying to port will just introduce extra errors and confusion.

IIRC, the PGU book uses 32-bit AT&T syntax, so I'd recommend just using that instead of porting it to NASM at all. The two syntaxes are equivalent in what they can do; they can both represent any x86 machine code instruction. If you think in terms of what the machine can do (e.g. the scale factor in addressing modes is a 2-bit shift count), it's easier to deal with learning different syntaxes and understand why restrictions exist on what you can do.


BTW, db is a list of bytes. rax is a qword register, 8 bytes. You probably want movzx eax, [esi] / inc esi or something to load 1 byte at once.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847