灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2763回复:0

汇编语言多文件程序设计

楼主#
更多 发布于:2011-12-30 18:05
变量的共享

        关键字externdef跟C语言中的extern相似。在定义与引用模块(源文件)中的声明的一致的。

声明格式:

        EXTERNDEF [[langtype]] name:type [[, [[langtype]] name:type]]...

MSDN Remars:

        If name is defined in the module, it is treated as PUBLIC. If name is referenced in the module, it is treated as EXTERN. If name is not referenced, it is ignored. The type can be ABS, which imports name as a constant. Normally used in include files.



函数的共享

        函数在调用之前必须使用proto语句提前声明。否则MASM会提示" error A2190:INVOKE requires prototype for procedure"。要在本模块中使用其它模块中的文件时,只需在调用模块作个proto声明就行了。



程序示例:


;-------------------main.asm--------------------------
.386
.model stdcall, flat
option casemap:none

fn  proto
externdef string:byte

.data
string  db  'hello world!', 0

.code
start:
   invoke fn
   ret
end start

;-------------------fn.asm--------------------------
.386
.model stdcall, flat
option casemap:none

include msvcrt.inc
includelib msvcrt.lib

externdef string:byte

.code

fn  proc
   invoke crt_printf, offset string
   ret
fn  endp

end

#------------------makefile------------
main.exe:main.obj fn.obj
   link /subsystem:console /nologo main.obj fn.obj
.asm.obj:
   ml /c /coff /nologo {1}lt;
clean:
   del *.obj
====================================================

dll模块中的数据调用:

include               保证编译时通过

includelib 保证链接时通过

dll文件               保证运行时正常

喜欢0 评分0
游客

返回顶部