China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 11:53
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Is Tsinghua's "IBM-PC Assembly Language Programming" misleading me? View 2,330 Replies 12
Original Poster Posted 2004-06-04 00:00 ·  中国 湖北 武汉 鹏博士宽带
中级用户
★★
Credits 286
Posts 59
Joined 2003-04-08 00:00
23-year member
UID 1437
Gender Male
Status Offline
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.
Floor 2 Posted 2004-06-10 00:00 ·  中国 河南 洛阳 联通
初级用户
Credits 208
Posts 41
Joined 2004-03-25 00:00
22-year member
UID 21059
Gender Male
Status Offline
Trusting all books is better than having no books
Floor 3 Posted 2004-06-11 00:00 ·  中国 四川 成都 联通
初级用户
Credits 154
Posts 14
Joined 2003-12-30 00:00
22-year member
UID 14671
Gender Male
Status Offline
No, you didn't write it yourself, right?
Floor 4 Posted 2004-06-12 00:00 ·  中国 湖北 武汉 鹏博士宽带
中级用户
★★
Credits 286
Posts 59
Joined 2003-04-08 00:00
23-year member
UID 1437
Gender Male
Status Offline
.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


Floor 5 Posted 2004-07-01 00:00 ·  中国 辽宁 丹东 联通
中级用户
★★
Credits 316
Posts 74
Joined 2004-03-04 00:00
22-year member
UID 19167
Gender Male
Status Offline
No way, then it's just the same as the immediate number
Floor 6 Posted 2004-07-14 00:00 ·  中国 陕西 西安 电信
初级用户
Credits 104
Posts 2
Joined 2004-07-14 00:00
21-year member
UID 28341
Gender Male
Status Offline
Young man, find more problems in your own program!
Floor 7 Posted 2004-07-14 00:00 ·  中国 湖北 武汉 鹏博士宽带
中级用户
★★
Credits 286
Posts 59
Joined 2003-04-08 00:00
23-year member
UID 1437
Gender Male
Status Offline
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.
Floor 8 Posted 2006-05-30 10:58 ·  中国 广东 深圳 福田区 电信
新手上路
Credits 2
Posts 1
Joined 2006-05-30 10:30
20-year member
UID 56245
Status Offline
The book is fine, just add a paragraph prefix and it's okay.
Floor 9 Posted 2009-03-11 22:02 ·  中国 北京 鹏博士宽带
新手上路
Credits 4
Posts 2
Joined 2006-06-29 09:19
19-year member
UID 57725
Status Offline
What the book says is correct. You can take a look at Wang Shuang's book. It's easy to understand.
Floor 10 Posted 2009-03-11 22:09 ·  中国 湖北 武汉 电信
新手上路
Credits 6
Posts 3
Joined 2009-02-19 15:58
17-year member
UID 139283
Gender Male
Status Offline
I just tried it, and what's in the book is correct. The poster should find more reasons in himself
Floor 11 Posted 2009-03-12 11:48 ·  中国 黑龙江 大兴安岭地区 联通
初级用户
★★
Credits 190
Posts 101
Joined 2008-11-23 14:58
17-year member
UID 131841
Gender Male
Status Offline
Reading books should capture their meaning, not just observe their appearance.
Floor 12 Posted 2009-03-12 21:01 ·  中国 福建 厦门 电信
高级用户
★★★
Credits 741
Posts 366
Joined 2007-07-25 19:11
18-year member
UID 94024
Gender Male
Status Offline
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.
Floor 13 Posted 2009-04-28 03:13 ·  IANA 局域网IP(Private-Use)
初级用户
Credits 26
Posts 12
Joined 2009-04-25 22:52
17-year member
UID 143791
Gender Male
Status Offline
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.
Forum Jump: