Domanda

While writing the simplest assembly for shellcode i wrote this code

BITS 64
global _start
section .data
_start:
  ;ssize_t write(int fd, const void *buf, size_t count);
  ;rax = 1

jmp poziv

vracajse:
xor rsi,rsi
pop rsi
xor rax,rax
mov al,1 ; were calling write
;The parameters are in rdi, rsi, rdx, r10, r8, r9. in that order
xor rdi,rdi ;
xor rcx,rcx ; need low 8 bytes dont want null in machine code
mov cl,1
mov edi,ecx ; edi =1 writing to stdout
xor rdx,rdx
mov dl,15 ; were writing 15 chars
syscall

poziv:
call vracajse

poruka:
.ascii "Pozdrav svete!\n"

and got the following error

writing_2nd_try.nasm:28: error: parser: instruction expected

Why is is telling me that my code poruka: .ascii "Some string" is not a valid instruction (label and a message) but if i write it as db then its okay.

(Also interesting to me is if i write .section data instead section .data i get the following errors

writing_2nd_try.nasm:3: error: attempt to define a local label before any non-local labels
writing_2nd_try.nasm:3: error: parser: instruction expected

)

Im kinda new to all this, but i thought i knew what i was doing.

È stato utile?

Soluzione

Why is is telling me that my code poruka: .ascii "Some string" is not a valid instruction (label and a message) but if i write it as db then its okay.

The syntax and directives differs between assemblers. .ascii is a directive recognized by the GNU assembler, but with NASM you use db (declare byte) instead, as you've already discovered.

(Also interesting to me is if i write .section data instead section .data i get the following errors

Because section is a directive recognized by NASM, and .section is not. So NASM thinks that you're declaring a local label named section (label names starting with a period are considered local in NASM syntax). So NASM sees a local label named section followed by the word data, which makes no sense.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top