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?
I've done some researches and here is what I've learned
.MODEL
directive
- enables use of simplified segments
- controls the name of the code segment
- controls the default distance for procedures.
the syntax is :.MODEL memorymodel, options-optional
and memorymodel can be TINY, SMALL, COMPACT, MEDIUM, LARGE, HUGE,or FLAT
Flat 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 .386
is 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