COM is an example of DOS-executable COM program. When executed in DOS it displays a line of text, plays a beep sound and terminates with errorlevel=0.
When a COM file is loaded in memory, DOS creates PSP structure (256 bytes) followed by the file contents. Segment registers CS,DS,ES,SS are all preloaded with the same paragraph address of PSP, instruction pointer IP is set to 256 and stack pointer SP to 0xFFFE (end of common segment).
Program option Entry is fixed at 256, there is no need to explicitly specify ENTRY=256
in COM format.
euroasm.exe com.htm
EUROASM ; No need to change default EUROASM options. ;; com PROGRAM FORMAT=COM,MODEL=TINY,WIDTH=16,LISTGLOBALS=OFF MOV SI,Message: ; Load the offset of Message. CALL Write.D16: ; Write the ASCIIZ string DS:SI. CALL Beep.D16: ; Play a beep sound. CALL Exit.D16: ; Terminate the program with errorlevel 0. ;; Write.D16: PROC ; Write ASCIIZ string DS:SI in 16bit DOS. MOV AH,02h ; Dos function WRITE CHARACTER FROM DL TO STANDARD OUTPUT. .1:MOV DL,[SI] ; Get one character. TEST DL ; Test if it is the terminating zero. JZ .9: ; Go to the end if yes. INT 21h ; Call DOS service to write a character. INC SI ; Let SI point to the next character. JMP .1: ; Repeat until DL=0. .9:RET ; Return to caller. ENDPROC Write.D16: ;; Beep.D16: PROC ; Echo beep sound in 16bit DOS. MOV DL,7 ; BEL character, interpreted as a beep sound. MOV AH,2 ; DOS function WRITE CHARACTER TO STANDARD OUTPUT. INT 0x21 ; Call DOS service to send a BEL. RET ; Return to caller. ENDPROC Beep.D16: ;; Exit.D16: PROC ; Terminate program in 16bit DOS. MOV AX,4C00h ; DOS function TERMINATE WITH RETURN CODE IN AL. INT 21h ; Call DOS service to terminate the program. ENDPROC Exit.D16: ;; ; Data are defined after the code. Message: DB "%^WIDTH[]bit %^FORMAT program %^PROGRAM.com created by EuroAssembler.",13,10,0 ENDPROGRAM com