Moving from AT&T to Intel syntax (help!)

Programming, for all ages and all languages.
Post Reply
‹^› â
Posts: 4
Joined: Tue Aug 07, 2007 5:36 pm

Moving from AT&T to Intel syntax (help!)

Post by ‹^› ⠻

Hi, I recently decided to move to Intel but I encountered a problem. What's wrong with this code:

Code: Select all

section .data
	items	db 12, 34, 56, 34, 23, 33, 78, 51, 0
section .text
	global _start
_start:
	mov		edi, 0
	mov		eax, items[edi]
	mov 	ebx, eax
	start_loop:
		cmp		eax, 0
		je		end_loop
		inc		edi
		mov		eax, items[edi]
		cmp		ebx, eax
		jle		start_loop
		mov		ebx, eax
		jmp		start_loop
	end_loop:
		push	ebx
		mov		eax, 1
		call	_syscall
_syscall:
	int		0x80
	ret
NASM says it's got errors in lines 7 and 13, but it looks right to me. It says "comma or end of line expected". In AT&T I just put:

Code: Select all

movl    items(, %edi, 4), %eax
What am I doing wrong?

Thanks

Oh, also what does 'db' 'dw' 'dorwd' mean or stand for? My guess is byte, word, and double word but what does the 'd' mean?
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

last question first:
Oh, also what does 'db' 'dw' 'dorwd' mean or stand for? My guess is byte, word, and double word but what does the 'd' mean?
db is data byte, dw is data word, dd is data double [word], and dq is data quad [word]

so d is for data...
NASM says it's got errors in lines 7 and 13, but it looks right to me. It says "comma or end of line expected"
maybe im wrong, but i dont think so (if i thought i was wrong, i would change what i think and wouldnt be wrong anymore... hehehe)

if im wrong, someone else can correct me and we will both learn

Code: Select all

mov      eax, items[edi]
i dont think this is proper syntax (if it is, its a form i have never seen...)

try this:

Code: Select all

mov    eax, [items + edi]
remember 2 things:
1) to get the contents of a memory location (such as the value stored at items[edi]) use brackets around the address (that should be the only time you use brackets -- thats one of the best things about intel ASM, no unnecessary punctuation)
2) labels are simply numbers -- the number equal to the offset of the lable, added to the point of ORiGination (ORG if used, or the link address specified to your linker)

using these rules you get 'items+edi' for the address
because you want the contents (and not the address itself) place it in brackets: [items+edi]
giving you the following encoding:

Code: Select all

mov eax, [items+edi]
Post Reply