I've been teaching myself x86 Assembly and machine code. I ran into some trouble.

Note: This is all under FreeBSD using the NASM assembler. FreeBSD pushes kernel call arguments onto the stack rather than in Linux where the arguments are moved into registers.

Here's my Macro code for NASM
Code:
%define stdin 0
%define stdout 1
%define stderr 2

%define SYS_nosys 0
%define SYS_exit 1
%define SYS_fork 2
%define SYS_read 3
%define SYS_write 4

section .text
align 4

access.the.bsd.kernel:
        int 80h
        ret

%macro system 1
        mov eax, %1
        call access.the.bsd.kernel
%endmacro

%macro sys.exit 0
        system SYS_exit
%endmacro

%macro sys.fork 0
        system SYS_fork
%endmacro

%macro sys.read 0
        system SYS_read
%endmacro

%macro sys.write 0
        system SYS_write
%endmacro
Here's the code for my program.
Code:
%include 'system.inc'

section .data
    msg db "above",0Ah
    len equ msg
    
    msg2 db "below",0Ah
    len2 equ msg2
    
    msg3 db "done",0Ah
    len3 equ msg3

section .text
global _start

_start:
    mov eax, 5 
    cmp eax, 3
    jl .ifbelow

    push dword len
    push dword msg
    push dword stdout
    sys.write
    jmp .done

.ifbelow:
    push dword len2
    push dword msg2
    push dword stdout
    sys.write
    
.done:
    push dword len3
    push dword msg3
    push dword stdout
    sys.write
    
    push dword 0
    sys.exit
Now the problem is that when I call the kernel to print out msg it takes the whole .data section with it. It displays msg, msg2, and msg3.

Like so:
matt@mdwuni2:~/programming/Assembly/cmp# ./cond
above
below
done
done

The reason it prints out done twice is that the unconditional jump is working and sends it to the end of the program where I print out done again.

When I try to change the comparison to: cmp eax, 7
Where the program goes on the conditional jump to .ifbelow and prints out below.

Like so:
matt@mdwuni2:~/programming/Assembly/cmp# ./cond
below
done
done

The kernel call is dragging msg2 and msg3 and displaying it.

I've tried rearranging the .data section and it all seems to be having the same problem.

Am I doing something completely wrong?
All the jumps are working properly, it's just the displaying of the .data section that's messing up.

If anybody can help me I'd be extremely thankful

Thanks!
-WraithM

EDIT: Also if anybody can tell me a way to display the values of registers that'd be really awesome! That's something that I haven't figured out.