EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

bincom.htm

Binary-generated COM is an example of binary program arranged to generate 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).
Binary image generated by €ASM should reserve 256 bytes for PSP in the assembly source, but whose bytes will be omitted from the generated output file, usign option OUTFILE="%^PROGRAM.com"[257..] , which also changes the default extension .bin to .com, as required by DOS loader.

Format
BIN arranged as COM
Platform
DOS
Build
euroasm.exe bincom.htm
Run
bincom.com
See also
com
       EUROASM          ; No need to change default €ASM options.
;;
bincom PROGRAM FORMAT=BIN,MODEL=TINY,WIDTH=16, \ Those are the defaults anyway.
               OUTFILE="%^PROGRAM.com"[257..], \ Omit the first 256 bytes generated in output file.
               LISTMAP=ON ,LISTGLOBALS=OFF
[COM]  SEGMENT PURPOSE=CODE+DATA+STACK ; Common segment for PSP, code and data. It may not exceed 64 KB.
$ EQU 256               ; Skip the PSP structure and shift the origin to 256=100h.
;;                      ; Program code must begin here, at offset 256.
  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 bincom

▲Back to the top▲