在我的代码开始时,我试图这样做:
mov [eax],0
并得到了一个段错误。
我想我之前必须初始化 eax,但我不知道该怎么做。
编辑:更一般地说,我想使用32位寄存器来计算事物。无论是哪一个。
帮助??
非常感谢:)
mov [eax],0
将零移动到值 eax
寻址的内存。(在 C 术语中,*eax = 0;
.)您正在写入您无权写入的地址。
mov eax,0
将零移动到eax
.(在 C 术语中,eax = 0;
.)这是你想做的吗?
如果将指令的通用寄存器放在括号[]之间,则汇编器会将寄存器解释为地址寄存器,并将寄存器的值解释为指令指向的偏移地址,以及地址的段部分。
例:
BLUB dd 0FFFFFFFFh ; a 32 bit value is stored in a memmory location
; Loading the segment part of the address into a segmentregister
; Note: an instruction of "mov segmentregister,immediate value" does not exist
; and so we have to use an all purpose register, or a memory location for to
; load the segment part of an address into a segmentregister
mov ax,SEG BLUB ; load the segment-address into the AX-Register
mov ds,ax ; load the segment-address form AX into DS-Register
mov eax,OFFSET BLUB ; load the offset part of the address into EAX
; load the value where the address-pair of DS:EAX is pointing to into EBX
mov ebx,[eax]
但是,如果我们只想使用某个寄存器进行计算,那么我们可以简单地将即时值加载到通用寄存器中。
例:
mov al,0FFh ; low byte of AX
mov ah,0FFh ; high byte of AX
mov ax,0FFFFh ; low word of EAX
mov eax,0FFFFFFFFh ; dword