Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer for the first struct member list in nasm assembly

Tags:

x86

assembly

nasm

How can i declare a pointer for the first element in a list of a struct like this:

section .bss
struc agenda
     name   resb 10
     number resd 10
     type   resw 10
endstruc
like image 694
Alison Costa Avatar asked Dec 19 '22 15:12

Alison Costa


1 Answers

Simply declaring the structure does not reserve memory for it. You need an instance of it. Either:

section .bss
    my_agenda resb agenda_size
; or perhaps...
    agenda_array resb agenda_size * MAX_COUNT
; or...
section .data
    an_agenda istruc agenda
    at name db "fred"
    at number db "42"
    at type db "regular"
    iend
section .text
    mov esi, an_agenda
    mov al, [esi + name]

Something like that?

Heh! Jester has just posted essentially the same thing. He introduces the '.' notation for local labels. Probably a good idea. Without it, name is a global identifier and can't be reused. It takes slightly more typing - agenda.name, agenda.number, agenda.type. Probably worth it for increased clarity.

like image 143
Frank Kotler Avatar answered Dec 26 '22 12:12

Frank Kotler