【问题标题】:Access Write Violation When Accessing the Value of a Register in assembly x86在汇编 x86 中访问寄存器的值时访问写冲突
【发布时间】:2014-12-06 04:57:28
【问题描述】:
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

大家好,只是好奇为什么这段代码不起作用?什么是使它工作的替代方法,我只是在玩寄存器,并在填充数组时尝试了一些类似的代码,但我在这一点上卡住了。

提前致谢!

【问题讨论】:

  • 它不是访问寄存器的值,而是试图访问无效的内存地址。 [eax] 是通过 eds:eax 左右的内存访问。在您的情况下,eax 寄存器在指向内存中错误页面的数据段中包含不正确的偏移量。
  • @AlexanderVX 那么我该如何修改内存中那个位置的值呢?基本上,我想永久修改 p1 和 p2,但不直接将值移动到这些变量中。
  • 只有在地址正确的情况下才能修改某个地址的值。您的代码的意图尚不清楚。我猜 Gunner 的答案更接近你想要的,但我看到的只是简单的错误。

标签: assembly x86 access-violation masm cpu-registers


【解决方案1】:

不确定您在做什么,但由于您似乎想要取消引用内存地址,因此您必须使用 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

【讨论】:

  • 是的,这很有帮助!谢谢!
猜你喜欢
  • 1970-01-01
  • 2011-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-23
  • 2011-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多