There is a useful directive, namely "struc" working well with NASM. All it does it allows me to write code like
Code: Select all
mov ax, MyObject.Field123
Cheers,
Adrian
Code: Select all
mov ax, MyObject.Field123
Code: Select all
typedef struct
{
int a;
char b;
int c;
}my_struct;
Code: Select all
.struct 0
.balign 4
a: .int 0
.balign 1
b: .byte 0
.balign 4
c: .int 0
Code: Select all
.struct 0 ! offset is set to 0x0
.balign 4
foo: ! foo's address is 0x0, because offset
! was set so two lines above
.struct foo + 4 ! offset is set to foo + 4 = 4
.balign 4
bar: ! bar's address is 0x4
Code: Select all
.struct 0 ! offset is set to 0x0
.balign 4
foo: ! foo's address is 0x0, because offset
! was set so two lines above
.struct foo + 4 ! offset is set to foo + 4 = 4
.balign 4
bar: ! bar's address is 0x4
.section ".data"
.align 4
.type fmt, #object
fmt: .asciz "%d %d\n" ! format string for printf(3)
.section ".text"
.align 4
.global main
.type main, #function
main:
save %sp, -104, %sp ! prologue
ld [%fp - 8 - foo], %l0 ! load member foo from stack
mov 10, %l0 ! assign 10 and write back
st %l0, [%fp - 8 - foo]
ld [%fp - 8 - bar], %l0 ! load member bar from stack
mov 20, %l0 ! assign 20 and write back
st %l0, [%fp - 8 - bar]
sethi %hi(fmt), %o0 ! copy high bits of fmt's address
or %o0, fmt, %o0 ! copy low bits
ld [%fp - foo], %o1 ! load foo to second output
call printf ! call printf(3)
ld [%fp - bar], %o2 ! load bar to third output
mov 0, %i0 ! return value
ret
restore