如何通过引用向 MASM 传递常见 C 类型

下面的代码示例演示如何通过引用传递变量的类型字符短,和长从 Microsoft C 的某个程序,Microsoft 宏汇编程序 (MASM) 程序。

 

下面的示例包括一个 C 文件和 $ 三个不同的程序集文件。三个程序集文件演示了如何通过变量引用来传递在小型和大型模型中的 MS-DOS 和 Windows NT 链接仅在适当的程序集模块的平面模型中以 C 模块。

请注意若要生成平面模型 Windows NT 版本需要 MASM 6.1 或更高版本和 C/c + + 版本 8.0 32 位编译器随 Visual c + +,32 位版。

   // Filename: CMAIN.C
   // Compile options needed: /c (and /AL for large model)

   #include <stdio.h>
   extern void  MasmSub (char *, short *, long *);

   char charvar = 'a';
   short shortvar = 1;
   long longvar = 32768L;

   void main (void)
   {
      printf ("%c %d %ld/n", charvar, shortvar, longvar);
      MasmSub (&amp;charvar, &shortvar, &longvar);
      printf ("%c %d %ld", charvar, shortvar, longvar);
   }
				

用于 MS-DOS 小写模型版本的示例代码

   ; Filename: MASMSUB.ASM
   ; Assemble options needed for MASM: /MX
   ; Assemble options needed for ML: /c /Cx

   .MODEL small, C      ;.MODEL ... C tells the assembler that
   .286                ; parameters are pushed from right to left.
   .CODE

   MasmSub PROC uses si, / 

      pchar:PTR, / 
      pshort:PTR, / 
      plong:PTR

      mov si, pchar      ;Load SI with the address of the char variable.
      mov BYTE PTR [si], "z"
      mov si, pshort      ;Load SI with the address of the short variable.
      add WORD PTR [si], 9
      mov si, plong      ;Load SI with the address of the long variable.
      add WORD PTR [si], 1  ;Increment the low word of the long variable
                            ;by 1.
      adc WORD PTR [si+2],0 ;Increment the high word.
      ret

   MasmSub ENDP
   END
			
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值