【问题标题】:ASM-creating a procedure [closed]ASM-创建一个程序[关闭]
【发布时间】:2013-03-12 22:33:53
【问题描述】:

设置了数组 A 和数组 B。 该过程将获得一个值 V 并返回该值是否存在于数组 B 中。 如果它确实 - 将索引存储在 P 中,如果没有,则将 -1 存储在 P 中。 该程序应以以下数据开头:

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

(用于以下选项的标志)

【问题讨论】:

  • 请您格式化您的问题以便阅读。
  • 这里有问题吗?

标签: assembly x86


【解决方案1】:

您通常希望使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    相关资源
    最近更新 更多