I am trying to understand the world of Nasm assembly and I've been stuck getting access to a simple element in an Array. I've followed the tutorial at tutorialspoint:
section .text
global _start
_start:
call openFileIn ;open the org image
call readFromFileIn ;read the data
;call printBuffer
;call openFileOut ;open output file
;call writeToFile ;write the data in data
;call closeFileOut ;close file
;call closeFileIn ;close file
MOV ecx, fd_in ;store the pointer to the data
INC ecx ;increase the counter, i++
MOV ebx, [ecx] ;store the value of that adress
CMP [testWord], ebx ;I expect ebx to hold 0x00 (one byte size)
JE printYay ;If they are equal, print yay to shell
MOV ecx, ebx ;store value in ebx in a desperate attempt for
;getting some insight of the value i've got
;print out first element in info
;1. put syscall sys_write to EAX
;2. put an argument in EBX
;3. put the data into ECX
;4. put the size of the segment in EDX
;5. call kernel
MOV eax, 4
MOV ebx, 1
;MOV ecx, char
MOV edx, 1
int 0x80
;The value does not give me any character or symbol in bash when program
;is run
call exitProg ;exit process
I have displayed the code which I believe I do not understand, which is memory accessing in the registers. But if you want to view all the code with syntax highlights, please follow this link: pastebin
I compile with:
nasm -f elf <filename>
Link with:
ld -m elf_i386 -s -o <outputName> <objectFile>
You can find the files content I get when I read from file, pastebin
writeexpects a pointer to the thing to output.ld -m elf_i386makes a 32-bit binary, not an x32 binary (long mode with 32-bit pointers).. I assume you just mis-tagged it, since you're using the 32-bitint 0x80ABI as well, notsyscallwith numbers from/usr/include/asm/unistd_x32.h