Hi proteusguy,
Welcome to the forum.
There are a couple of issues here. Mainly, since you put the length in edx, it wants to be dword, not byte. Although the length would fit in a byte, by doing "mov edx..." we move four bytes - the length and the first three bytes of the string! Using "movzx edx, byte..." would also fix it.
; nasm -f elf32 this.asm
; ld -o this this.o -e main
struc CountedString
.length: resd 1
.str_ptr: resd 1
; .ref_count: resw 1
; don't need this
.counted_string_struc_size:
endstruc
; Nasm essentially does CountedString_size equ $ - CountedString
; don't need this since it's here - doesn't hurt
global system_exit
SECTION .text
system_exit: ; terminates the running app cleanly.
xor ebx,ebx ; 0 is normal exit code for linux sys_exit call
;mov eax,1 ; sys_exit call id is 1
xor eax,eax ; xor then inc is one byte shorter than direct assignment of literal
inc eax
int 0x80 ; call linux kernel
; ask nasm to tell linker about this entrypoint
global main
section .data
; SECTION .text
; don't need the terminating zero - doesn't hurt
startup_msg: db "Test machine v 0.01 startup.", 10, 0
startup_msg_len: equ $-startup_msg
startup_string:
istruc CountedString
at CountedString.length, dd startup_msg_len
at CountedString.str_ptr, dd startup_msg
; at CountedString.ref_count, dw 0ffffh
iend
section .text
main:
; print out our startup message then exit.
mov edx, startup_msg_len
mov ecx, startup_msg
mov ebx, 1 ; stdout file handle
mov eax, 4 ; sys_write call id
int 0x80
mov edx, [startup_string + CountedString.length]
mov ecx, [startup_string + CountedString.str_ptr]
mov ebx, 1 ; stdout file handle
mov eax, 4 ; sys_write call id
int 0x80
call system_exit ; exit application
There are a couple trivial issues... "main" is known to the C language as the entrypoint. If you're using gcc, this is right. Since we have no C code here, we don't need to use gcc - although we can. I chose to link it directly with ld. ld knows "_start:" as the default entrypoint. We can tell it something else with the "-e" switch. Normally I would probably use "_start:", but for no good reason I used "-e main".
You also need the square brackets around the length. If we use "equ" it's an immediate number so no [] needed. But if we use "dd", as in the structure, it's a memory variable and we need 'em.
You've got the "struc" thing pretty well, it was these other issues that were giving you trouble.
Best,
Frank