Programmering - Assembler - MASM - Program development - .COM
v .COM Template 1 - MASM51-PG p.16 : Data before Code
v .COM Template 2 - MMAB p.51 : Data after Code
v .COM Template 3 - Minimal

Litteratur:
MASM51-PG : Microsoft Macro Assembler 5.1 Manual - Programming Guide
MMAB : The Waite Groups Microsoft Macro Assembler Bible
 

Compilation

file.asm > file.com
>MASM file;     .asm assumed
output: file.obj
>LINK file; .obj assumed
warning: no stack (ignore warning)
output: file.exe (the exe file is not executable!)
>EXE2BIN file file.com .exe assumed

 

En batchfil kan evt benyttes:

>COM file

COM.BAT indeholder:

@echo off
MASM %1;
LINK %1;
EXE2BIN %1 %1.com

 

.COM Template 1 - MASM51-PG p.16 : Data before Code

TITLE   title
_TEXT   SEGMENT
        ASSUME CS:_TEXT, DS:_TEXT, SS:_TEXT
        ORG 100H
start:  jmp begin
;-----------------------
msg     db      "data here$"
;-----------------------
begin:  nop           ;code here
        mov ax,4C00h  ;Terminate
        int 21h
_TEXT   ENDS
        END start
  

.Com Template 1 - Ex: Hello World 1

TITLE   hello
_TEXT   SEGMENT
        ASSUME CS:_TEXT, DS:_TEXT, SS:_TEXT
        ORG 100H
start:  jmp begin
;-----------------------
msg     db      "Hello World",13,10
len     EQU     $ - msg
;-----------------------
begin:  mov bx,1        ;handle: standard out
        mov cx,len      ;max bytes
        mov dx,offset msg
        mov ah,40h      ;Write File or Device
        int 21h

        mov ax,4C00h    ;Terminate
        int 21h
_TEXT   ENDS
        END start
  

.COM Template 1 - Ex : Hello World 2

CODE    SEGMENT
        ORG 100h
        ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
jump:   jmp start
;-----------------------------DATA
Msg     DB '  Hello World!  $'
;-----------------------------
start:  mov dx,OFFSET Msg
        mov ah,9        ;Display String (DS:DX -> String$)
        int 21h
        mov ax,4C00h    ;Terminate
        int 21h
CODE    ENDS
        END jump
  

.COM Template 2 - MMAB p.51 : Data after Code

        ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
CODE    SEGMENT
        ORG 100h
start:  nop             ;code here
        mov ax,4C00h    ;Terminate
        int 21h
;-----------------------------DATA
Msg     DB 'Data here$'
;-----------------------------
CODE    ENDS
        END start
  

.COM Template 2 - Hello World 3

        ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
CODE    SEGMENT
        ORG 100h
start:  mov dx,OFFSET Msg
        mov ah,9        ;Display String$ at DS:DX
        int 21h
        mov ax,4C00h    ;Terminate
        int 21h
;-----------------------------DATA
Msg     DB 'Hello World!$'
;-----------------------------
CODE    ENDS
        END start
  

.COM Template 3 - Minimal

	ASSUME cs:code
code	SEGMENT
	ORG 100h
start:  nop   ;code here
        ret
code	ENDS
	END start
  

.COM Template 3 - Ex : Hello World 4

        ASSUME CS:CODE
CODE    SEGMENT
	ORG 100h
start:  mov dx,OFFSET Msg
        mov ah,9          ;Display String$ at DS:DX
        int 21h
        ret
;-----------------------------DATA
Msg     DB 'Hello World!$'
;-----------------------------
CODE    ENDS
        END start
  

.COM Template 3 - Ex : SAY

;SAY.COM	(use:>SAY hello)
	ASSUME cs:code
code	SEGMENT
        mov si,82h   ;command line parameters in PSP
mess:   mov al,[si]
        cmp al,0Dh
        jz quit
	mov bh,0
        mov ah,0Eh  ;write teletype char in AL
        int 10h     ;BIOS VIDEO SERVICES
	inc si
        jmp mess
quit:   ret
code 	ENDS
	END start