MASM:如何解决错误“不允许立即操作数”

vij*_*ari 0 x86 assembly masm bootloader data-structures

我的汇编程序具有以下结构:

BPB_FAT16   STRUCT                     ; Base BPB_FAT16. Size=0x19=25.
BytesPerSector      DW  0x0200 ; Size of HW sector, usualy 512.
SectorsPerCluster   DB  0x01   ; Valid values 1,2,4,8,16,32,64,128.
ReservedSectors     DW  0x0001 ; NrOfSectors preceding FAT.
NumberOfFats        DB  0x02   ;
RootEntries         DW  0x00E0 ; Max number of YWORD entries in the 
                               ;root dir.
SmallSectors        DW  0x0B40 ; See also .LargeSectors.
MediaDescriptor     DB  0xF0   ; 0xF0 floppy disk, 0xF8 hard disk.
SectorsPerFat       DW  0x0009 ;
SectorsPerTrack     DW  0x0012 ;
NumberOfHeads       DW  0x0002 ;
HiddenSectors       DW 0x00000000
LargeSectors        DW 0x00000000
                               ; Extended BPB_FAT16. Size=0x1A=26.
PhysicalDriveNumber DB 0x00   ; 0x00 floppy disk, 0x80 hard disk.
Reserved            DB 0x00   ;
ExtBootSignature    DB 0x29   ; Or 0x28.
VolumeSerialNumber  DW 1212121 ; Randomly generated number.
VolumeLabel         DB "NO NAME    " ; Space-padded to size=11.
FileSystemType      DB "FAT12   "    ; Space-padded to size=8.
BPB_FAT16 ENDS  ;   Total BPB_FAT16. Size=0x33=51.
Run Code Online (Sandbox Code Playgroud)

我的程序仅显示下面给出的一行代码的两个错误:

Bpb   BPB_FAT16{}
Run Code Online (Sandbox Code Playgroud)

这两个错误是:

error1: missing operator in expression
error2: initializer magnitude too large for specified size
Run Code Online (Sandbox Code Playgroud)

我该怎么办?请指导我。

Mic*_*tch 6

错误消息missing operator in expression可能出现在您使用0x十六进制值前缀的每一行上。MASM 不支持它,它使用h后缀来表示十六进制值。

该错误initializer magnitude too large for specified size是因为值 1212121 无法放入您为VolumeSerialNumber. VolumeSerialNumber在 BPB 中需要是 DD(32 位 DWORD)。

尽管它没有生成错误,但BPB 中的字段HiddenSectors和字段LargeSectors是 32 位 DWORD,因此它们应该使用类型DD而不是DW.

您的结构可以定义为:

BPB_FAT16   STRUCT                   ; Base BPB_FAT16. Size=0x19=25.
BytesPerSector      DW  200h         ; Size of HW sector, usualy 512.
SectorsPerCluster   DB  1h           ; Valid values 1,2,4,8,16,32,64,128.
ReservedSectors     DW  1h           ; NrOfSectors preceding FAT.
NumberOfFats        DB  2h           ;
RootEntries         DW  0E0h         ; Max number of YWORD entries in the
                                     ; root dir.
SmallSectors        DW  0B40h        ; See also .LargeSectors.
MediaDescriptor     DB  0F0h         ; 0xF0 floppy disk, 0xF8 hard disk.
SectorsPerFat       DW  9h           ;
SectorsPerTrack     DW  12h          ;
NumberOfHeads       DW  2h           ;
HiddenSectors       DD  0h
LargeSectors        DD  0h
                                     ; Extended BPB_FAT16. Size=0x1A=26.
PhysicalDriveNumber DB  0h           ; 0x00 floppy disk, 0x80 hard disk.
Reserved            DB  0h           ;
ExtBootSignature    DB  29h          ; Or 0x28.
VolumeSerialNumber  DD 1212121       ; Randomly generated number.
VolumeLabel         DB "NO NAME    " ; Space-padded to size=11.
FileSystemType      DB "FAT12   "    ; Space-padded to size=8.
BPB_FAT16 ENDS  ;   Total BPB_FAT16. Size=0x33=51.
Run Code Online (Sandbox Code Playgroud)

通过这些更改,您的结构现在正好是 51 个字节,这正是您对 FAT16 DOS 4.0 EBPB所期望的。