编写汇编程序以用作字典。用户输入单词,程序检查该单词是否存在。TASM,16 位。程序非常适合数组的前两个元素,但如果我提供数组balls.
的第 3 个元素,即使选择了数组的下一个元素,(在 上验证emu8086
,bx
变为 007ch
,->参考代码<-),repe cmpsb
一次尝试后仍然完成检查。与数组的前两个元素一起正常工作。这是我的代码程序首先检查长度,然后检查位。提供句点 ( . )时结束长度检查。
.model large
.data
arrayele db 00d ;to count if all elements of the array have been compared with
count db 00d ;length of input count
nl db 10d,13d,'$' ;newline
mne db "Not Equal$" ;message if not equal
me db "Equal$" ;message if equal
buf db 99,?,99 dup(?) ;buffer where the input will be saved
w0 db "hello$" ;word 0-5
w1 db "which$"
w2 db "balls$"
w3 db "table$"
w4 db "chair$"
w5 db "apples$"
words dw offset w0,offset w1 ;the array
dw offset w2,offset w3
dw offset w4,offset w5
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;take user input
mov ah,0ah
mov dx,offset buf
int 21h
;print new line
mov ah,09h
mov dx,offset nl
int 21h
;load input to di
mov di,offset buf
add di,2
;//saving length to a variable
repeat:
mov al,[di]
inc count
cmp al,"."
je lenchck
inc di
jmp repeat
;//end saving
lenchck:
dec count ;as full stop (period) (.) is also included in the count
stringmatch1:
mov cx,0 ;reset register
mov arrayele,0 ;reset variable
stringmatch:
mov di,offset buf ;loading input to di
add di,2
;loading array element to si
mov bx,0
mov bl,byte ptr words
mov si,bx ;end loading array element to si
mov cl,count
repe cmpsb
je equal
inc arrayele
inc words ;next word in the array
mov bx,0 ;loading it
mov bl,byte ptr words
mov si,bx ;end loading
cmp arrayele,06d ;compare to check if all elements have been compared with
jg wrong
jmp stringmatch
wrong: ;load notequal message
mov dx,offset mne
jmp print
equal:
mov dx,offset me ;load equal message
print:
mov ah,09h ;print it
int 21h
mov ah,4ch ;exit the program
int 21h
main endp
end main