.386c
cseg segment byte public use16
assume cs:cseg, ds:dseg, ss:sseg
start:
mov ax,dseg
mov ds,ax
lop:
xor si,si ;清零si
mov word ptr ds:,0 ;内存ds:处的值清零
cmp si, ;si的值等于ds:处的值么(0值)
je _exit ;如果等则退出程序
jmp lop ;否则循环判断。
_exit:
mov ax, 4C00h
int 21h
cseg ends
;---------------------------------------------------
dseg segment byte public use16
db 0 dup(1024)
dseg ends
;----------------------------------------------
sseg segment stack
db 100h dup(?)
sseg ends
;----------------------------------------------
end start
程序执行的结果是死循环,而按照是内存地址内容的理解,应该是正常退出程序。用tdb跟踪调试发现cmp一句被编译为 cmp si,00C8,也就是说,被编译器认为是立即数0C8h,而不是代表处存放的值。
再一个例子:
mov ,ax ; XXXX是一个数值地址,比如1234h。
编译报错:error A2001: immediate operand not allowed(不允许立即方式操作数)
也就是说,编译器将认为是立即数,而不是一个内存地址。
我改为mov ds:,ax 就编译通过了。而且正确地存入了该地址。
编译器版本MASM6.11
.386c
cseg segment byte public use16
assume cs:cseg, ds:dseg, ss:sseg
start:
mov ax,dseg
mov ds,ax
lop:
xor si,si ; Clear si
mov word ptr ds:,0 ; Clear the value at memory ds:
cmp si, ; Is the value of si equal to the value at ds: (which is 0)?
je _exit ; If equal, exit the program
jmp lop ; Otherwise, loop and judge.
_exit:
mov ax, 4C00h
int 21h
cseg ends
;---------------------------------------------------
dseg segment byte public use16
db 0 dup(1024)
dseg ends
;----------------------------------------------
sseg segment stack
db 100h dup(?)
sseg ends
;----------------------------------------------
end start
The result of the program execution is an infinite loop, but according to the understanding that is the content of the memory address, it should exit the program normally. When debugging with tdb, it was found that the cmp instruction was compiled as cmp si,00C8, which means that was regarded by the compiler as the immediate number 0C8h, not the value stored at .
Another example:
mov ,ax ; XXXX is a numerical address, such as 1234h.
Compilation error: error A2001: immediate operand not allowed(Immediate operand is not allowed)
That is to say, the compiler regarded as an immediate number, not a memory address.
I changed it to mov ds:,ax and it compiled successfully. And it was correctly stored in that address.
Compiler version MASM6.11