16bit Asm – read.com

A clone of the type command. Usage: [inline]read FULLFILENAME[/inline]:
Commented FASM Code:

org 100h
use16
xor bx,bx
mov bl,byte [0080h]   ;Get length of sargs
mov byte [bx+81h],00  ;Terminate args with NUL Byte
mov ah,3dh            ;Open file function
mov dx,0082h          ;Points to asciiz filename
int 21h               ;Do it
mov bx,ax             ;Copy file handle into BX
read:
mov ax,3f00h          ;Read file function
mov cx,0001h          ;Read 1 byte
mov dx,bchar          ;Store read byte into bchar
int 21h               ;Do it
cmp ax,0000           ;Check if nothing read (EOF)
je exit               ;Exit if at EOF
push bx               ;Save BX
mov bx,bchar          ;BX = Address of read byte
mov dl,byte [bx]      ;Read byte pointed by BX into DL
mov ax,0200h          ;Print character function
int 21h               ;Do it
pop bx                ;Restore BX
jmp read              ;Read next byte from file
exit:
mov ax,3e00h          ;Close file function (BX=fhandle)
int 21h               ;Do it
mov ax,4c00h          ;Exit function
int 21h               ;Do it
bchar db 00h

Here’s a batch file to automatically make the file using debug.exe:

@echo off
echo Creating read.com . . .
if 1==1 (
echo e 100 31 DB 8A 1E 80 00 C6 87 81 00 00 B4 3D BA 82 00
echo e 110 CD 21 89 C3 B8 00 3F B9 01 00 BA 3C 01 CD 21 83
echo e 120 F8 00 74 0E 53 BB 3C 01 8A 17 B8 00 02 CD 21 5B
echo e 130 EB E2 B8 00 3E CD 21 B8 00 4C CD 21 00 00 00 00
echo r cx
echo 003D
echo n read.com
echo w
echo q
)>>build.dbg>nul
debugnul
del build.dbg>nul
echo.
echo read.com created in "%cd%".
pause >nul

Debug.exe code:

C:\>debug
-a 0100
XXXX:0100 XOR BX,BX
XXXX:0102 MOV BL,[0080]
XXXX:0106 MOV BYTE PTR [BX+0081],00
XXXX:010B MOV AH,3D
XXXX:010D MOV DX,0082
XXXX:0110 INT 21
XXXX:0112 MOV BX,AX
XXXX:0114 MOV AX,3F00
XXXX:0117 MOV CX,0001
XXXX:011A MOV DX,013C
XXXX:011D INT 21
XXXX:011F CMP AX,+00
XXXX:0122 JZ 0132
XXXX:0124 PUSH BX
XXXX:0125 MOV BX,013C
XXXX:0128 MOV DL,[BX]
XXXX:012A MOV AX,0200
XXXX:012D INT 21
XXXX:012F POP BX
XXXX:0130 JMP 0114
XXXX:0132 MOV AX,3E00
XXXX:0135 INT 21
XXXX:0137 MOV AX,4C00
XXXX:013A INT 21
XXXX:013C DB 00
XXXX:013D
-R CX
CX 0000
:003D
-N READ.COM
-W
Writing 003D bytes.
-q

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: