MS-DOS COM

Read an old MASM book and build the first MS-DOS COM file. You need to donwnload 16bit linker to compile, and need exe2bin to convert from exe to com.

It sets AH/DL for Console input and does INT 21H to call it. Loops if no input (AL=0H).
CPU usage of NTVDM.exe (16bit host) was 25% on the 4CPU machine for the first 5-6 seconds (because it’s looping), then went down to 0%. Why?

AH=06H , DL=0FFH -> Console input (will get the char code in AL)
INT 21H -> DOS system call (no echo, no wait)

    MOV AH,06H
    MOV DL,0FFH
    INT 21H

Similarly, it sets AH=09H, DL= & does INT 21H to print it later. Then, AH=4CH means ‘process exit’ and AL=00H is the return code.

comtest.a16

.286

ASSUME CS:CODE,DS:CODE
CODE SEGMENT
    ORG 100H
START:
    MOV BX,0
NOINPUT:
    MOV AH,06H
    MOV DL,0FFH
    INT 21H
    JNZ PRINT
    INC BX
    CMP BX,5
    JGE START
    JMP NOINPUT
 PRINT:
    SHL BX,1
    MOV DX,TABLE[BX]
    MOV AH,09H
    INT 21H
    
    MOV AH,4CH
    MOV AL,00H
    INT 21H

FAIR    DB  'FAIR',0DH,0AH,'$'
CLOUDY  DB  'CLOUDY',0DH,0AH,'$'
RAINY   DB  'RAINY',0DH,0AH,'$'
RLATER  DB  'RAINY LATER CLOUDY',0DH,0AH,'$'
CLATER  DB  'CLOUDY LATER RAINY',0DH,0AH,'$'

TABLE   DW  OFFSET FAIR, OFFSET CLOUDY, OFFSET RAINY
        DW  OFFSET RLATER, OFFSET CLATER

 CODE ENDS
    END START

comtest.mak

COMTEST = comtest.exe
COMTESTCOM = comtest.com

COMTESTOBJS = comtest.obj

all : comtest

comtest : $(COMTESTOBJS)
	link16 $(COMTESTOBJS),$(COMTEST);
	exe2bin $(COMTEST) $(COMTESTCOM)

clean:
	del /f *.obj *.o *.exe *.lst

.SUFFIXES: .a16 .asm .obj

.a16.obj: 
	ml /c /Fl $<

.asm.obj: 
	ml /c /coff /Cp /nologo /Fl $< /Zi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.