中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-10-31 08:48
47,815 topics / 349,930 posts / today 0 new / 48,290 members
DOS开发编程 & 发展交流 (开发室) » Is Tsinghua's "IBM-PC Assembly Language Programming" misleading me?
Printable Version  2,642 / 12
Floor1 Loff Posted 2004-06-04 00:00
中级用户 Posts 59 Credits 286
I believe many people learn DOS assembly by reading this book?
When introducing addressing modes inside, it explains that the sentence mov ax, is: assign the content at ds: to ax, that is, if the value at ds: is 3020, then after executing this sentence, ax = 3020H.
Recently, when debugging a DOS program, I found that instructions in the form of mov xx,, add xx, (where there are all numbers) are all interpreted by the assembler as mov xx,xxxxh, that is, directly give the value inside the square brackets to the register! That is, after mov ax, is executed, ax = 2000H. Don't believe it? You can compile a few sentences yourself, and then load them into the debugger to check the code in memory, and you will find that after executing this sentence, ax = 2000h.
Unless there is a problem with my machine or the programming software (masm6.11, tasm5, Tdebug). Otherwise, please tell me how to understand this addressing mode.
Floor2 拉菲尔 Posted 2004-06-10 00:00
初级用户 Posts 41 Credits 208
Trusting all books is better than having no books
Floor3 晓欣 Posted 2004-06-11 00:00
初级用户 Posts 14 Credits 154
No, you didn't write it yourself, right?
Floor4 Loff Posted 2004-06-12 00:00
中级用户 Posts 59 Credits 286
.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


Floor5 boblhh9999 Posted 2004-07-01 00:00
中级用户 Posts 74 Credits 316
No way, then it's just the same as the immediate number
Floor6 Arbiter Posted 2004-07-14 00:00
初级用户 Posts 2 Credits 104
Young man, find more problems in your own program!
Floor7 Loff Posted 2004-07-14 00:00
中级用户 Posts 59 Credits 286
Got it, in the source code, the form like is recognized by the MASM compiler as an immediate number (different from what the book says). Only and correspond to the memory value. However, in the debugger, is seen as a memory value, which is different from the source code.
Floor8 buffon Posted 2006-05-30 10:58
新手上路 Posts 1 Credits 2
The book is fine, just add a paragraph prefix and it's okay.
Floor9 pijiudu Posted 2009-03-11 22:02
新手上路 Posts 2 Credits 4
What the book says is correct. You can take a look at Wang Shuang's book. It's easy to understand.
Floor10 cabinsummer Posted 2009-03-11 22:09
新手上路 Posts 3 Credits 6
I just tried it, and what's in the book is correct. The poster should find more reasons in himself
Floor11 Qtwdftxvt Posted 2009-03-12 11:48
初级用户 Posts 101 Credits 190
Reading books should capture their meaning, not just observe their appearance.
Floor12 netwinxp Posted 2009-03-12 21:01
高级用户 Posts 366 Credits 741
1. The BYTE declared in your data segment is used as WORD, so you need to add WORD PTR to restrict it.
2. mov memory, immediate data is acceptable, but it is not in the 8086 instruction set, so you need to add the.386 pseudo-instruction at the beginning of the program and declare the type of the memory variable, such as mov word ptr [0C8h], 0.
Floor13 MarsKeeper Posted 2009-04-28 03:13
初级用户 Posts 12 Credits 26
The result of `mov ax,[2000H]` on TASM is the same as that on MASM. The content of AX is 2000H.

Both reasons of the 12th floor are wrong, and the example given is correct.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023