设置了阵列A和阵列B. 如果值存在于数组B中,则该过程将获得值V并返回。 如果它确实存储了P中的索引,如果不存在,则在-1中存储-1。 该程序应从以下数据开始:
ARR_B DB 100 DUP()
ARR_A DB 10 DUP ()
V DB ?
P DB ?
以下是我们的所作所为:
TEST1 PROC
; Chek if the variable of V found in ARR_B.
MOV SI,0
MOV DX,0
MOV Flag,0
MOV AL,1H
NEG AL
MOV CX,9H
GO:
MOV DL,ARR_B[SI]
CMP V,DL
JE X
INC SI
LOOP GO
MOV P,AL
JMP END1
X: MOV DX,SI
MOV P,DL
INC FLAG
END1: NOP
RET
TEST1 endp
(以下选项中使用的标志)
答案 0 :(得分:0)
您通常希望使用rep scasb
进行类似的搜索:
test1 proc
mov P, 0ffffh ; for now, assume it won't be found
mov al, V ; what we're going to look for
mov di, offset array_b ; where we're going to look
mov cx, size array_b ; how many items to search
repnz scasb ; do the search
jnz done ; Z flag clear = not found
sub di, offset array_b ; found: compute offset into array_b
mov P, di ; and save it
done:
ret