NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: pprocacci on December 29, 2016, 04:47:37 AM
-
I've come across the error (in the subject) that I can't simply get my head around. I'm hoping someone is able to point me to the correct resolution.
STRUC something
.pos1: RESQ 1
.pos2: RESW 1
.pos3: RESW 1
.pos4: RESD 1
.pos5: RESQ 1
.pos6: RESQ 1
ENDSTRUC
BITS 64
DEFAULT REL
global _start:function
SECTION .bss
array: RESB something_size * 100
index: RESD 1
SECTION .text
_start:
mov eax, [index] ; Load index into array
mov qword [array + rax * something_size + something.pos5], 1
mov eax, 1
xor edi, edi
syscall
In short, this code allocates space for 100 something's named array in the bss segment.
It also allocates a double to store an index into that array.
The logic in start, attempts to store 1 in the array at array index 0 at offset pos5 ..... or so I thought.
What am I missing here?
Note: I also tried different registers given my reading on the net, but I simply cannot get anything to jive.
Thanks in advance!
-
An effective address consists of an (optional) displacement, an (optional) base register, and an (optional) index register multiplied by a scale of 1, 2, 4, or 8. You can't multiply a register by an arbitrary value (like "something_size").
(Your "syscall" doesn't look correct to me, either. 1 is the 32-bit system call number for sys_exit, but 64-bit system call number for sys_write - you want 3Ch for sys_exit I think... but check that!)
Best,
Frank
-
Hey Frank,
Nice see'ing you're still around.
I understand I think. Thanks for the follow up.
As for the syscall. It's correct on 64-bit BSD.
-
Ah, BSD! Yeah, that's the same as the 32-bit numbers. A pox on Linux for changing them. I have no idea what they think they gained.
Best,
Frank