测试EAX中的值是否与数组x86中的任何值相同 [英] Test if value in EAX is the same as any value in a array x86

查看:61
本文介绍了测试EAX中的值是否与数组x86中的任何值相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试eax中生成的随机值是否与我分配的数组中的任何值相同.外循环生成该数组,并将其写入屏幕和数组中.然后,应假设内循环测试该值是否存在于数组中.我知道我没有正确地执行内循环,但是我不确定如何解决它.

I am attempting to test if the random value generated in eax is the same as any value in an array I have allocated. The outer loop generates the array and writes it to the screen and in to the array, The inner loop is then supposed to test if the value exists in the array. I know i am not doing the inner loop correctly but I am not sure how to fix it.

它组装得很好,但是当我尝试运行时,我只会得到一个空白的cmd窗口屏幕.我也在使用Irvine32库.我的代码如下:

It assembles just fine but when I try to run I only get a blank cmd window screen. Also I am using Irvine32 libraries. My code is below:

编辑:到目前为止,我很感谢你们的帮助,但现在我有两个问题.第一个是,当我尝试评估eax中的数字相对于我的数组的唯一性时,我实际上遇到了访问冲突错误.我用于生成数组并对其进行测试的代码如下:

EDIT: I appreciate your guys help so far but now I Have two problems. The first is that when I try to evaluate the number in eax for uniqueness against my array I actually get an access violation error. My code for generating the array and testing it is below:

RandomArray PROC uses EAX

    call Randomize 
    mov esi, OFFSET arr
    mov edi, OFFSET arr
    mov ebx, TYPE arr 
    mov ecx, 15
    L1:
        mov eax, [79 - 19]
        push eax
        call RandomRange
        add eax, 19
        search1:
                 mov edx,[esi]
                 cmp eax,edx                 ; compares the values in the array and the random int
                 je L1                       ; jumps if the values are equal
                 add esi,4                   ; moves to next byte to check again
                 loop search1                ; repeats loop
        mov [esi],eax
        pop eax
        add esi, ebx
        loop L1
    ret
RandomArray ENDP
        pop ecx     
        loop OUTER_LOOP

    jmp FINISHED

    SWAP:
        mov bl, [esi]
        mov dl, [esi+1]
        xchg bl,dl 
        mov [esi],dl 
        mov [esi+1],bl
        jmp CONTINUE 

    FINISHED:
    ret

谢谢您的帮助.

推荐答案

我只有一个空白的cmd窗口屏幕

I only get a blank cmd window screen

search:
    mov ecx,elementcount
    cmp eax,[esi]
    je L1
    add esi,4
    loop search

这是一个无限循环,因为您将在每次迭代中重置计数器ecx.将ecx分配移到循环外,您应该没问题:

This is an infinite loop because you are resetting the counter ecx on each iteration. Move the ecx assignment outside the loop and you should be fine:

mov ecx,elementcount

search:
    cmp eax,[esi]
    je L1
    add esi,4
    loop search


顺便说一句,您可能可以用rep scasd替换该循环,我相信这样做完全相同.不确定它是否在任何方面都更好".


Btw, you could probably replace that loop with rep scasd, which I believe does the exact same thing. Not sure whether it is "better" in any way though.

mov ecx,elementcount
rep scasd
je L1

免责声明:代码未经测试,距离我使用x86 asm已经有几年了:)

Disclaimer: code not tested, and it's been a few years since I did x86 asm :)

这篇关于测试EAX中的值是否与数组x86中的任何值相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆