修改cx时,TASM检查参数 [英] TASM checking arguments when cx is modified
问题描述
我需要检查是否给出了大量的参数.目前,我的程序知道什么时候没有参数,什么时候给出两个以上的参数.如果给出一个,那是不好的,但是我的程序无法识别它.我不能做简单的检查,因为有一种可能性,当它被允许时(当/?是参数时),并且cx随循环而变化.例如,如果我将其命名为prog/?,则应打印描述,当我将其命名为prog arg1 arg2时,应允许使用它,但不允许prog arg1.我该如何检查?
I need to check whether good amount of arguments is given. Currently my program knows when there are no arguments and when there are more than two arguments given. If one is given, then it is bad, but my program doesn't recognise it. I can't do simple check because there is one possibility when it is allowed (when /? is argument) and cx changes with loop. For example, if I call it prog /?, it should print description, when I call it prog arg1 arg2, it should be allowed, but prog arg1 shouldn't. How can I check that?
mov ch, 0h
mov cl, [es:0080h]
push cx
cmp cx, 0
je print_description
mov bx, 81h
jmp search_help
jmp exit
search_help:
cmp [es:bx], '?/'
je print_description
inc bx
loop search_help
pop cx
cmp cx, 2
jne print_description
mov bx, 82h
mov si, offset input_filename
mov cx, 255
search_input_filename:
mov dl, [es:bx]
inc bx
cmp dl, 20h
je search_output_filename_prep
mov ds:[si], dl
inc si
loop search_input_filename
search_output_filename_prep:
mov si, offset output_filename
search_output_filename:
mov dl, [es:bx]
inc bx
cmp dl, 0Dh
je program
cmp dl, 20h
je print_description
mov ds:[si], dl
inc si
loop search_output_filename
推荐答案
两个错误:
1)我的TASM 5.0不喜欢[ES:xxxx]
.段覆盖必须写为ES:[xxxx]
.
1) My TASM 5.0 doesn't like [ES:xxxx]
. The segment override has to be written as ES:[xxxx]
.
2)ES:[0080h]
包含命令行的长度,不参数的数量.因此,这行不按照您的想法进行操作:
2) ES:[0080h]
contains the length of the command line, not the count of the arguments. Thus this lines don't do what you think:
push cx
...
pop cx
cmp cx, 2
jne print_description
您可以改用我的get_argc
函数.遵循以下测试用例(希望如此):
You can use my get_argc
function instead. Following test case works (hopefully):
LOCALS @@
.MODEL small
.STACK 1000h
.DATA
description db 'description',13,10,'$'
input_filename db 80 DUP ('$')
output_filename db 80 DUP ('$')
.CODE
main PROC
mov ax, @data
mov ds, ax
mov ch, 0h
mov cl, es:[0080h]
cmp cx, 0
je print_description
mov bx, 81h
jmp search_help
jmp exit
search_help:
cmp word ptr es:[bx], '?/'
je print_description
inc bx
loop search_help
call get_argc
cmp ax, 2
jne print_description
mov bx, 82h
mov si, offset input_filename
mov cx, 255
search_input_filename:
mov dl, es:[bx]
inc bx
cmp dl, 20h
je search_output_filename_prep
mov ds:[si], dl
inc si
loop search_input_filename
search_output_filename_prep:
mov si, offset output_filename
search_output_filename:
mov dl, es:[bx]
inc bx
cmp dl, 0Dh
je program
cmp dl, 20h
je print_description
mov ds:[si], dl
inc si
loop search_output_filename
program:
mov dx, OFFSET input_filename
mov ah, 09h
int 21h
call crlf
mov dx, OFFSET output_filename
mov ah, 09h
int 21h
exit:
mov ax, 4C00h
int 21h
print_description:
lea dx, description
mov ah, 09h
int 21h
mov ax, 4C01h
int 21h
main ENDP
get_argc PROC
mov bx, 0
mov di, 80h
mov cx, es:[di]
@@L1:
inc di
mov al, es:[di]
cmp al, 20h
je @@L1
cmp al, 09h
je @@L1
cmp al, 0Dh
je @@done
inc bx
@@L2:
inc di
mov al, es:[di]
cmp al, 20h
je @@L1
cmp al, 09h
je @@L1
cmp al, 0Dh
je @@done
jmp @@L2
@@done:
mov ax, bx
ret
get_argc ENDP
crlf PROC
mov ah, 2
mov dl, 13
int 21h
mov ah, 2
mov dl, 10
int 21h
ret
crlf ENDP
END main
这篇关于修改cx时,TASM检查参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!