2014-12-06 44 views
0
compare PROTO, p1:DWORD, p2:DWORD 
.code 
compare proc p1:DWORD, p2:DWORD 
    mov eax, p1 
    mov edx, p2 
    mov eax, [eax] ;Getting an access violation here 
    mov edx, [edx] ; Would probably get one here too, why? 
    sub eax, edx 
    ret 
compare endp 
main PROC 
    LOCAL thesize:DWORD 
    mov thesize, 3 
    mov fill, 5 
    INVOKE compare, thesize, thesize 

    ret 
main ENDP 

嘿家伙,只是好奇为什么这段代码不工作?什么是使其工作的另一种方法,我只是玩弄寄存器,并在填充数组时尝试了类似的代码,但是我在这一点上陷入困​​境。在程序集x86中访问寄存器的值时发生访问写入冲突

在此先感谢!

+0

它不访问寄存器的值,而是尝试访问无效的内存地址。 [eax]是通过eds:eax等进行的内存访问。在你的情况下,eax寄存器在数据段内包含一个不正确的偏移量,指向内存中的错误页面。 – AlexanderVX 2014-12-06 05:25:57

+0

@AlexanderVX如何修改内存中那个位置的值呢?基本上,我想永久修改p1和p2,但不要直接将值移动到这些变量中。 – user2738003 2014-12-06 05:35:10

+0

只有在地址正确的情况下,才能修改某个地址的值。你的代码的意图不明确。我想枪手的答案更接近你想要的,但我看到的只是普通的错误。 – AlexanderVX 2014-12-06 07:13:03

回答

1

不知道你在做什么,但是因为它看起来像你想取消引用一个mem地址,所以你必须使用addr作为本地变量来获取/传递该地址。

main PROC 
    LOCAL thesize:DWORD 
    mov thesize, 3 

; INVOKE compare, thesize, thesize 
; same as: 
; push 3 
; push 3 
; call compare 

    ; this is what you want: 
    invoke compare, addr thesize, addr thesize 
; same as: 
; lea  eax, thesize 
; push eax 
; push eax 
; call compare 
    ret 
main ENDP 
+0

是的,这帮了很大的忙!谢谢! – user2738003 2014-12-06 10:48:43