|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
使用简化段定义,.data 的数据段不是从16的倍数地址开始了吗?
比如:
.model small
.data
dw 1234h
.code
start:
mov ax,@data
mov ds,ax
mov bx,0
mov ax,[bx] ;取不到1234h
mov ax,4c00h
int 21h
nop
nop
end start
谢谢解答!
明白您的担忧,如果您需要确保 `.data` 段始终在16字节对齐的地址,请考虑以下几种解决方法:
1. **使用标准段定义**:
使用标准段定义可以明确设定对齐方式,从而达成您的目标。
- .model small
- .stack 100h
- data segment para 'DATA'
- dw 1234h
- string db 'Meaningless string$'
- data ends
- code segment
- assume ds:data, cs:code
- start:
- mov ax, data
- mov ds, ax
-
- ; 防止因代码占用内存导致问题,通过添加额外指令
- add ax, ax ; 一些额外的占位指令
- nop
- xor ax, ax
- mov bx, 0
- mov ax, [bx] ; 从数据段地址0位置读取值
- ;增加编译后的代码长度
- mov ah, 9
- lea dx, string
- int 21h
- mov ax, 4c00h
- int 21h
- code ends
- end start
复制代码
2. **使用 ORG 指令**:
如果您的汇编器支持,可以使用 `ORG` 指令来确定 `.data` 段的偏移。
- .model small
- .stack 100h
- .data
- org 100h ; 指定数据地址偏移
- dw 1234h
- string db 'Meaningless string$'
- .code
- start:
- mov ax, @data
- mov ds, ax
- ; 防止因代码占用内存导致问题,通过添加额外指令
- add ax, ax ; 一些额外的占位指令
- nop
- xor ax, ax
- mov bx, 0
- mov ax, [bx] ; 从数据段地址0位置读取值
- ;增加编译后的代码长度
- mov ah, 9
- lea dx, string
- int 21h
- mov ax, 4c00h
- int 21h
- end start
复制代码
3. **手动对齐**:
在使用简化段定义时,如果需要手动保证对齐,可以添加填充数据。
- .model small
- .stack 100h
- .data
- db 16 dup(?) ; 填充到16字节对齐
- dw 1234h
- string db 'Meaningless string$'
- .code
- start:
- mov ax, @data
- mov ds, ax
- ; 防止因代码占用内存导致问题,通过添加额外指令
- add ax, ax ; 一些额外的占位指令
- nop
- xor ax, ax
- mov bx, 0
- mov ax, [bx] ; 从数据段地址0位置读取值
- ;增加编译后的代码长度
- mov ah, 9
- lea dx, string
- int 21h
- mov ax, 4c00h
- int 21h
- end start
复制代码
这些方法中,使用标准段定义是最可控和明确的方式。如果一定要使用简化段定义,请使用手动对齐的方法进行填充。希望这能解决您遇到的问题。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
|
|