MASM:如何解决错误“不允许立即操作数"? [英] MASM: how to resolve error "immediate operand not allowed"
问题描述
我的汇编程序具有以下结构:
My assembly program has following structure:
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.
我的程序仅对下面给出的一行代码显示两个错误:
My program is showing two errors for only one line of code given below:
Bpb BPB_FAT16{}
这两个错误是:
error1: missing operator in expression
error2: initializer magnitude too large for specified size
我该怎么办?请引导我.
What should I do? Please guide me.
推荐答案
在将0x
前缀用作十六进制值的每一行上都可能出现错误消息missing operator in expression
. MASM不支持该功能,它使用h
后缀表示十六进制值.
The error message missing operator in expression
is likely occurring on every line where you use 0x
prefix for hexadecimal values. MASM doesn't support that and it use the h
suffix to denote hexadecimal values.
错误initializer magnitude too large for specified size
是因为值1212121
不能适合您为VolumeSerialNumber
指定的DW(16位WORD). BPB中的VolumeSerialNumber
必须是DD(32位DWORD).
The error initializer magnitude too large for specified size
is because the value 1212121
can't fit in the DW (16-bit WORD) you specified for VolumeSerialNumber
. VolumeSerialNumber
in a BPB needs to be a DD (32-bit DWORD).
尽管它不会产生错误,但BPB中的字段HiddenSectors
和LargeSectors
是32位DWORD,因此它们应使用类型DD
而不是DW
.
Although it didn't generate an error, the fields HiddenSectors
and LargeSectors
in a BPB are a 32-bit DWORD so they should be using the type DD
instead of DW
.
您的结构本可以定义为:
Your structure could have been defined as:
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.
通过这些更改,您的结构现在正好是51个字节,这就是您期望的FAT16
With these changes your structure is now exactly 51 bytes which is what you'd expect for a FAT16 DOS 4.0 EBPB.
这篇关于MASM:如何解决错误“不允许立即操作数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!