NASM INDEX
;------------------------------------------------------------------
; LOCAL LABELS
;------------------------------------------------------------------
;-------------------------------------------------------------------
;A label beginning with a single period is treated as a local label,
;which means that it is associated with the previous non-local label.
;-------------------------------------------------------------------
BITS 16
SEGMENT CODE
..start:
mov ax,CODE ;Code 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
call write_hello ;Call procedure
call write_world
mov ah,0x4c ;Call DOS to exit
mov al,0 ;Return(0) - error code
int 0x21 ;DOS interrupt
;------------------------------
;this procedure prints "Hello"
;------------------------------
write_hello: ;non-local label
push ax ;save registers used
push dx
mov dx,.string ;local string offset
mov ah,9 ;DOS function: "output string"
int 0x21 ;DOS interrupt
pop dx
pop ax ;restore saved registers
retn ;pops caller IP
.string: db "Hello, ",'$' ;local label
;------------------------------
;this procedure prints "World"
;------------------------------
write_world: ;non-local label
push ax ;save registers used
push dx
mov dx,.string ;local string offset
mov ah,9 ;DOS function: "output string"
int 0x21 ;DOS interrupt
pop dx
pop ax ;restore saved registers
retn ;pops caller IP
.string: db "World!",'$' ;local label
;----------------------------
;DATA segment: not needed
;----------------------------
SEGMENT STACK STACK
resb 100h
stack_top: