首页 > 技术文章 > 关于汇编地址分配的疑惑

idealing 2015-02-02 15:19 原文

使用王爽著的《汇编语言》开始自己的汇编之旅,遇到一些疑惑,记录下来,看以后会不会解惑。

 1 assume cs:codesg,ds:datasg
 2 datasg segment
 3   db 'ibm          '
 4   db 'dec          '
 5   db 'dos          '
 6   db 'vax          '
 7   dw 'agn          ';(其后添不添加dw 0结果都是一样的)
 8 datasg ends
 9 
10 codesg segment
11   start:mov ax,datasg
12      mov ds, ax
13      mov bx, 0
14      mov cx, 4
15   s0: mov ds:[40h], cx
16       mov si, 0
17       mov cx, 3
18   s:  mov al, [bx+si]
19       and al, 11011111b
20       mov [bx+si], al
21       inc si
22       loop s
23 
24       add bx, 16
25       mov cx, ds:[40h]
26       loop s0
27 
28       mov ax, 4c00h
29       int 21h
30 
31 codesg ends
32 end start

一段比较简单的代码(ml.exe /Zm /c ,link16.exe后),在dos里debug

自己的理解:

      ds:系统分配的内存空间首地址(如图15550-1564F是调用函数的一系列操作指令)

      es:未显式分配,则和ds一致

      ss:未显式分配,程序源码段开始地址(datasg)

      cs:程序代码段开始(codesg)

比较困惑的是在datasg结束后,没有直接开始codesg,而是在内存中插入0,算是使codesg对齐么?不懂是不是代码起始地址必须要16字节对齐。

      

推荐阅读