OK, here are two examples that might help:
EXAMPLE 1:
;
; Standalone NASM "Hello world"
;
; BUILD:
; nasm -f elf64 hello.asm
; ld -s -o hello hello.o
;
; EXAMPLE OUTPUT:
; Hello, world!
;
section .text ;code section (shareable between processes)
global _start ;loader entry point
_start:
mov edx,len ;arg3: msg len
mov ecx,msg ;arg2: *msg
mov ebx,1 ;arg1: 1 (stdout)
mov eax,4 ;syscall@4 (sys_write)
int 0x80
mov ebx,0 ;arg1: exit code (0)
mov eax,1 ;sycall@1 (sys_exit)
int 0x80
section .data ;data section (per process)
msg db "Hello, world!",0xa ;our dear string
len equ $ - msg ;length of our dear string
EXAMPLE 2:
;
; "Hello world" using standard C library
;
; BUILD:
; nasm -f elf64 avg3.asm
; gcc -m64 -o avg avg.o
;
; EXAMPLE OUTPUT:
; sum=12
; avg=4
;
extern printf ;stdlib C function
section .text ;code section
global main ;standard GCC entry point
main:
push rbp ;set up stack frame: must be aligned
; Add 3+4+5
mov rax,3
add ax,4
add ax,5
; Save and print sum
push rax
mov rdi,fmt1 ;printf format string
mov rsi,rax ;1st parameter
mov rdx,0 ;No 2nd parameter
mov rax,0 ;No xmm registers
call printf
; Compute and print average
mov dx,0 ;Clear dividend, high
pop rax ;dividend, low <= sum
mov cx,3 ;divisor
div cx ;ax= high, dx= low
; Print average
mov rdi,fmt2 ;printf format string
mov rsi,rax ;1st parameter
mov rdx,0 ;No 2nd parameter
mov rax,0 ;No xmm registers
call printf
; Exit program
pop rbp
mov rax,0
ret
section .data ;data section
fmt1:
db "sum=%d",0xa,0
fmt2:
db "avg=%d",0xa,0
NOTES:
Personally, I prefer "Gnu Assembler" (gas). It makes it easy to switch between different architectures, and between C and in-line assembler, without the "cognitive dissonance" of dealing with Intel syntax ;)
I'd strongly urge you to leverage the standard C library has much as possible. In practice, this means linking your executable using gcc instead of ld.
Your "compute average" program is a great example why: it's much easier to let the printf formatter figure out the correct output, rather than converting your binary values to ASCII digits, and then figuring out how to format them into a string manually.
'Hope that helps!