for instance
Code: Select all
typedef struct test{
int c;
} test;
static test myInfo;
movq $0, myInfo.c does not work do i always use the following method ?
Code: Select all
movq $myInFo, %rsi;
movq $0, 0(%rsi)
Code: Select all
typedef struct test{
int c;
} test;
static test myInfo;
Code: Select all
movq $myInFo, %rsi;
movq $0, 0(%rsi)
Code: Select all
; -----------------
%DEFINE OFFSET ; Define the keyword OFFSET
; -----------------
[SECTION .bss] ; Uninitialized section
TESTStruct: ; The beginning of the structure
A RESD 0 ; The first member of the structure
B RESD 0 ; The second member of the structure
C RESD 0 ; The third member of the structure
TESTStruct_END: ; End of the structure (not necessary)
; -----------------
[SECTION .text] ; The code section
MOV EBX , OFFSET TESTStruct ; *EBX is the address of the structure
MOV DWORD PTR [EBX] , EAX ; First member of the structure (A)
MOV DWORD PTR [EBX + 0x04] , EAX ; Second member of the structure (B)
MOV DWORD PTR [EBX + 0x08] , EAX ; Third member of the strucure (C)
Code: Select all
; -----------------
%DEFINE OFFSET ; Define the keyword OFFSET
; -----------------
[SECTION .bss] ; Uninitialized section
TESTStruct: ; The beginning of the structure
A RESQ 0 ; The first member of the structure
B RESQ 0 ; The second member of the structure
C RESQ 0 ; The third member of the structure
TESTStruct_END: ; End of the structure (not necessary)
; -----------------
[SECTION .text] ; The code section
MOV EBX , OFFSET TESTStruct ; *EBX is the address of the structure
MOV DWORD PTR [EBX] , EAX ; DWORD #0 of the First member (A)
MOV DWORD PTR [EBX + 0x04] , EAX ; DWORD #1 of the First member (A)
MOV DWORD PTR [EBX + 0x08] , EAX ; DWORD #0 of the Second member (B)
MOV DWORD PTR [EBX + 0x0C] , EAX ; DWORD #1 of the Second member (B)
MOV DWORD PTR [EBX + 0x010] , EAX ; DWORD #0 of the Third member (C)
MOV DWORD PTR [EBX + 0x014] , EAX ; DWORD #1 of the Third member (C)
One thing you can do is define the field offsets as constants, which will allow you to refer to them by name (sort of).. more or less like this:os64dev wrote:Does anyone know how to address structure members in assembler:
for instancecan be addressed in C/C++ with myInfo.c = 0 but how does this work in assembler specifcally GAS.Code: Select all
typedef struct test{ int c; } test; static test myInfo;
movq $0, myInfo.c does not work do i always use the following method ?Code: Select all
movq $myInFo, %rsi; movq $0, 0(%rsi)
Code: Select all
Assuming C structure:
struct vect {
signed x,y;
};
You could use something like:
#define vect_x 0
#define vect_y 4
movl $0, vect_x(%esi)
movl $0, vect_y(%esi)
Where %esi has a pointer to the vect, and "signed" is assume to be 4-bytes. You could use symbols (.equ or .set) instead of preprocessor directives if you want.
Code: Select all
movl $0, (vect_x + my_vect)