首页 > 解决方案 > masm程序集如何访问结构变量

问题描述

DPT 是这样定义的结构:

DPT STRUC
rSrtHdUnld DB 1; Bits 0-3: SRT step rate time, bits 4-7: head unload time.
rDmaHdLd   DB 1; Bit  0: 1=use DMA, bits 2-7: head load time.
bMotorOff  DB 1; 55-ms increments before turning disk motor off.
bSectSize  DB 1; Sector size (0=128, 1=256, 2=512, 3=1024).
bLastTrack DB 1; EOT (last sector on a track).
bGapLen    DB 1; Gap length for read/write operations.
bDTL       DB 1; DTL (Data Transfer Length) max transfer when length not set.
bGapFmt    DB 1; Gap length for format operation.
bFillChar  DB 1; Fill character for format (normally 0f6H).
bHdSettle  DB 1; Head-settle time (in milliseconds).
bMotorOn   DB 1; Motor-startup time (in 1/8th-second intervals)
DPT ENDS ; Size=11.   

在 MASM 中组装时,我使用了以下语法:

MOVB [DI-SIZEOF DPT]+[DPT.bHdSettle],15

MASM 显示以下错误:

syntax error : [

标签: assemblystructmasm

解决方案


我不确定movb应该是什么,但我认为这是一个错字,你的意思是mov.

您可以像这样编写指令:

mov (DPT PTR [DI-SIZEOF DPT]).bHdSettle,15

或者,如果您在一个PROC想要通过多个结构访问的地方,di您可以告诉汇编器暂时假设di指向 a DPT

ASSUME di:PTR DPT
mov [di-SIZEOF DPT].bHdSettle,15
.....
ASSUME di:NOTHING

推荐阅读