NASM INDEX
;-------------------------------------------------------
; Assembly Language Procedures - Modules of code
; that perform a specific task
;-------------------------------------------------------
; An assembly procedure is a sequence of instructions
; that end with a ret instruction. The call instruction
; saves the current IP on the stack (near call),
; loads the address of the procedure into IP and jump
; to that address. The ret instruction pops IP to return
; control when done.
;-------------------------------------------------------
;
BITS 16
SEGMENT CODE
..start:
mov ax,DATA ;Address of data segment...
mov ds,ax ;into DS
mov sp,stack_top ;Start stack pointer
mov ax,STACK ;Address of stack segment
mov ss,ax ;into SS
mov dx,msg ;Offset of msg to DX
call write_msg ;Call procedure
mov ah,0x4c ;Call DOS to exit
mov al,0 ;Return(0) - error code
int 0x21 ;DOS interrupt
;------------------------------
;this procedure prints a string
;------------------------------
write_msg: ;procedure label
push ax ;save registers used
mov ah,9 ;DOS function: "output string"
int 0x21 ;DOS interrupt
pop ax ;restore saved registers
retn ;pops caller IP
SEGMENT DATA ;Start of DATA segment
msg: db "Hello, World!",'$' ;data: message string
;$-terminated
SEGMENT STACK STACK
resb 100h
stack_top: