汇编语言命令参数程序的编写
2008-04-29 09:34:01 来源:WEB开发网四、结束语:
一个月以前我还只是会看别人的汇编程序,自从自己动手写程序后,自己的汇编编程水平有了很大的进步。写程序的过程中遇到问题,然后自己看书自己解决问题,这样学习汇编编程比光看书更有效。我的汇编编程的水平还很菜鸟,我会不断提高自己的水平,同时也希望与广大编程爱好者交流。
附:源程序(PARATEST.ASM)
; ************************************************
; * Program:Use asm language to creat a command *
; * line and parameter program. *
; *==============================================*
; * Designer:Howard Original Place:Wuhan *
; * Creat Date:09/30/1999 *
; * Modification Date:10/05/1999 *
; * Now Version:1.0 *
; * Pass:Tasm 5.0,Tlink 3.1 *
; *==============================================*
; * Modification History *
; *----------------------------------------------*
; * Version 1.0 1.Command line and parameter *
; * 09/30/1999 test program. *
; *----------------------------------------------*
; * Version 1.1 2.Add the spaces parameters jud- *
; * 10/05/19999 gement. *
; ************************************************
;
.model small
.386
.code
org 100h
start:
main proc far
push cs
pop ds ;ds=psp seg address
cld ;cf=0
mov si,81h ;psp+81h is the first parameter char
lea bx,parameter ;parameter address(offset) saved to bx
;unit parameter is used to save the parameter
lodsb ;load a byte from [si] to al,and si=si+1
cmp al,0dh ; Enter?
jz scanexit ;if yes then scan parameter end
cmp al,' '
jz judgespace
lodsb
continue:
push si
cmp al,'/'
jz parascanloop
jmp error ;wrong parameter
judgespace:
lodsb
; call debug ;set break point
cmp al,0dh
je scanexit
cmp al,' '
je judgespace
jne continue
parascanloop: ;saved the parameter to unit parameter
mov [bx],al ;save al to [bx],just save the parameters
lodsb
cmp al,0dh ;Enter?
jz choise ;if yes then jump choise
inc bx
jnb parascanloop ;the next char
scanexit:
lea dx,noparametermsg
call disp
call rettodos
choise:
lea si,parameter
mov al,[si+1] ;load the parameter to al
cmp al,'?' ;judge the parameter and choose ;the different process
jz help
cmp al,'p'
jz print
cmp al,'P'
jz print
jmp error ;wrong parameter
print:
lea dx,message
call disp
call rettodos
help: ;print the help message
lea dx,helpmsg
call disp
call rettodos
error: ;print the error parameter message
lea dx,wrongparamsg
call disp
mov ax,0200h
pop si
dec si
prnwrongparameter:
lodsb
cmp al,0dh
jz retdos
mov dl,al
int 21h
loop prnwrongparameter
retdos:
mov dl,'"'
int 21h
mov dl,'!'
int 21h
call rettodos
main endp
disp proc near
mov ah,09h
int 21h
ret
disp endp
rettodos proc near
mov ah,4ch
int 21h
rettodos endp
;
;set a break point
;debug proc near
; push ax dx
; mov ax,0900h
; mov dx,offset debugmsg
; int 21h
; mov ax,0700h
; int 21h
; pop dx
; pop ax
;debug endp
;debugmsg db 0dh,0ah,'Program stop here,press any key to continue...','$'
noparametermsg db 0ah,0dh,'There is no parameter,enter paratest /? for help.','$'
message db 0dh,0ah,'This is a parameter test program.','$'
wrongparamsg db 0dh,0ah,'The wrong parameter:"','$'
helpmsg db 0dh,0ah,'1.Paratest /?'
db 0dh,0ah,' Print the help message.'
db 0dh,0ah,'2.Paratest /p'
db 0dh,0ah,' Print the test message.','$'
parameter db 2 dup(?)
end start
更多精彩
赞助商链接