问题
I'm learning assembly language with MASM assembler and I get stuck when I tried to assemble a simple file using this command :ml /c test.asm
and the test.asm file looks like :
.386
.model flat
.code
MOV BP,WORD PTR[BP+4]
END
then the problem comes:
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: test.asm
test.asm(4) : error A2155: cannot use 16-bit register with a 32-bit address
the question is ,
32-bit address?I didn't tell the assembler to use a 32-bit address.
and How can I get my code passed?
回答1:
I've done some researches and here is what I've learned
.MODELdirective
- enables use of simplified segments
- controls the name of the code segment
- controls the default distance for procedures.
the syntax is :
.MODEL memorymodel, options-optionaland memorymodel can be
TINY, SMALL, COMPACT, MEDIUM, LARGE, HUGE,or FLATFlat model is similar to tiny model in that all code and data go in a single 32-bit -addressable block of memory.
To write a flat model program, specify the .386 or .486 directive before.
so the directive .386is optional if I don't want to use flat model (look here)
here are some references
1 .MODEL
2 Logical Segments and Memory Model Directives
来源:https://stackoverflow.com/questions/27097644/masmanother-cannot-use-16-bit-register-with-a-32-bit-address-error