[MASM]Another 'cannot use 16-bit register with a 32-bit address' error

六月ゝ 毕业季﹏ 提交于 2019-12-21 17:57:28

问题


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

.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 .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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!