; Source name : EAT4.ASM ; Executable name : EAT4.EXE ; Code model: : Real mode segmented model ; Version : 1.0 ; Created date : 9/12/1999 ; Last update : 9/12/1999 ; Author : Jeff Duntemann ; Description : A simple example of a DOS .EXE file programmed for ; real mode segmented model, using NASM 0.98 and ALINK. ; This program demonstrates how separately-assembled ; modules sharing both code and data are linked into a ; single executable module. [BITS 16] ; Set 16 bit code generation ;----------------------------| ; BEGIN CODE SEGMENT | ;----------------------------| ; Note that the following items are external to EAT4.ASM, and must ; be linked from the external file VIDLIB.OBJ. Assemble VIDLIB.ASM ; first to VIDLIB.OBJ before attempting the link. EXTERN GotoXY,Write,Writeln,ClrScr SEGMENT code PUBLIC ; SEGMENT SETUP ; ; In real mode segmented model, a program uses three segments, and it must ; set up the addresses in the three corresponding segment registers. This ; is what the ASSUME directive does in MASM; we ASSUME nothing in NASM! ; Each of the three segments has a name (here, code, data, and stack) and ; these names are identifiers indicating segment addresses. It is the ; appropriate segment address that is moved into each segment register. ; Note that you can't move an address directly into a segment register; ; you must first move the address into a general purpose register. Also ; note that we don't do anything with CS; the ..start: label tells the ; linker where the code segment begins. ..start: ; This is where program execution begins: mov ax,data ; Move segment address of data segment into AX mov ds,ax ; Copy address from AX into DS mov ax,stack ; Move segment address of stack segment into AX mov ss,ax ; Copy address from AX into SS mov sp,stacktop ; Point SP to the top of the stack call ClrScr ; Clear the full display mov word [TextPos], 0914H ; 0914H = X @ 20, Y @ 9 mov DX,[TextPos] ; TextPos contains X,Y position values call GotoXY ; Position cursor mov DX,Eat1 ; Load offset of Eat1 string into DX call Write ; and display it mov DX,[TextPos] ; Re-use text position variable mov DH,10 ; Put new Y value into DH call GotoXY ; Position cursor mov DX,Eat2 ; Load offset of Ear2 string into DX call Writeln ; and display it mov AH,4CH ; Terminate process DOS service mov AL,0 ; Pass this value back to ERRORLEVEL int 21H ; Control returns to DOS ;----------------------------| ; BEGIN DATA SEGMENT | ;----------------------------| SEGMENT data PUBLIC GLOBAL LRXY,CRLF LRXY DW 184FH ; 18H = 24D; 4FH = 79D; 0-based XY of LR screen corner TextPos DW 0 Eat1 DB "Eat at Joe's...",'$' Eat2 DB "...ten million flies can't ALL be wrong!",'$' CRLF DB 0DH,0AH,'$' ;----------------------------| ; END DATA SEGMENT | ;----------------------------| ;----------------------------| ; BEGIN STACK SEGMENT | ;----------------------------| SEGMENT stack stack ;This means a segment of *type* "stack" ; that is also *named* "stack"! Some ; linkers demand that a stack segment ; have the explicit type "stack" resb 64 ; Reserve 64 bytes for the program stack stacktop: ; It's significant that this label points to ; the *last* of the reserved 64 bytes, and ; not the first! ;----------------------------| ; END STACK SEGMENT | ;----------------------------|