home *** CD-ROM | disk | FTP | other *** search
- name hello
- page 55,132
- title 'HELLO.EXE --- print Hello on terminal'
- ;
- ; HELLO.EXE utility to demonstrate various parts
- ; of a functional EXE-type assembly language program,
- ; use of segments, and a MS-DOS function call.
- ;
- ; Ray Duncan, September 1983
- ;
- ; To assemble, link, and convert this program into
- ; an EXE file, follow these steps:
- ;
- ; C>MASM HELLO-E;
- ; C>LINK HELLO-E;
- ;
-
- ;show use of some EQUATES:
- cr equ 0dh ;ASCII carriage return
- lf equ 0ah ;ASCII line feed
-
- ;begin the "Code" segment
- ;containing executable
- ;machine code
- cseg segment para public 'CODE'
-
- assume cs:cseg,ds:dseg,ss:stack
-
- print proc far ;actual program code
- ;is completely contained
- ;in the "procedure" named
- ;"PRINT".
- ;
- ;set Data Segment Register
- ;to point to the Data Segment
- ;of this program, so that the
- ;message we want to print is
- ;addressable.
- mov ax,dseg
- mov ds,ax
- ;now put the offset of the
- ;message text into DX,
- mov dx,offset message
- ;now DS:DX specifies the
- ;full address of the message.
- mov ah,9 ;use the MS-DOS function 9
- int 21h ;to print the string.
- ;
- mov ax,4c00h ;exit back to MS-DOS with
- int 21h ;"return code" of zero.
-
- print endp ;end of the "procedure"
- ;named "PRINT"
- ;
- cseg ends ;end of the code segment
- ;containing executable
- ;program.
- ;
- ;now we define a data segment
- ;containing our program's
- ;constants and variables.
- dseg segment para 'DATA'
- ;
- message db cr,lf,'Hello!',cr,lf,'$'
- ;
- dseg ends
- ;
- ;lastly, we define a Stack
- ;Segment which contains
- ;a scratch area of memory
- ;for use by our program's stack
- stack segment para stack 'STACK'
- ;allow 64 words in this case
- dw 64 dup (?)
-
- stack ends
- ;the final "End" statement
- ;signals the end of this
- ;program source file, and gives
- ;the starting address of
- ;the executable program
- end print