假设你的D盘下有text.txt文件,并有内容,开个命令提示窗口,执行例如test.exe d:\text.txt,后面的d:\text.txt就是参数,就可以输出文本中的内容,汇编源代码如下:
  assume cs:code,ds:data
lenofid=128
space=" "
tab=09h
eof=1ah
data segment
fname db lenofid dup(?)
error db "required parameter missing!!",0
error1 db "file not find",07h,0
error2 db "reading error",07h,0
buffer db ?
data ends
code segment
start:cld
  mov si,80h
  lodsb
  or al,al
  jnz getfid1
fiderr:mov ax,seg error
  mov ds,ax
  mov si,offset error
  call dmess
  jmp over
getfid1:mov cl,al
  xor ch,ch
getfid2:lodsb
  cmp al,space
  jz getfid3
  cmp al,tab
  jnz getfid4
getfid3:loop getfid2
  jmp fiderr
getfid4:dec si
  mov ax,seg fname
  mov es,ax
  mov di,offset fname
  rep movsb
  xor al,al
  stosb
   
  mov ax,data
  mov ds,ax
  mov dx,offset fname
  mov ax,3d00h
  int 21h
  jnc open_ok
   
  mov si,offset error1
  call dmess
  jmp over
open_ok:mov bx,ax
cont: call readch
  jc readerr
  cmp al,eof
  jz type_ok
  call putch
  jmp cont

readerr:mov si,offset error2
  call dmess

type_ok:mov ah,3eh
  int 21h

over:mov ah,4ch
  int 21h

readch proc
mov cx,1
mov dx,offset buffer
mov ah,3fh
int 21h
jc readch2
cmp ax,cx
mov al,eof
jb readch1
mov al,buffer
readch1:clc
readch2:ret
readch endp 
   
dmess proc
dmess1:mov dl,[si]
  inc si
  or dl,dl
  jz dmess2
  mov ah,2
  int 21h
  jmp dmess1
dmess2:ret
dmess endp
   
putch proc
  push dx
  mov dl,al
  mov ah,2
  int 21h
  pop dx
  ret
putch endp
code ends
end start