【问题标题】:FASM- passing parameters to an external procedureFASM-将参数传递给外部过程
【发布时间】:2014-08-20 06:40:50
【问题描述】:

我在将参数传递给主 ASM 文件之外的过程时遇到问题。这是我的代码。它显示了一个主过程 _main(在 main.asm 中),它调用另一个源文件(sub.asm)中的子过程 _sub。子过程打印主过程指定的字符串。

main.asm:

;subprocedure test- main.asm
org 100h
include 'sub.asm' ;file of sub-procedure
_main: ;main method
    mov dx, string ;move string to dx register
    push dx ;push dx onto the stack
    call _sub;calls sub-procedure
    pop dx ;restores value of dx
    int 20h;exit program
ret ;end of main method
string db 'Some text $' ;string to be printed  

sub.asm:

;//subprocedure test- sub.asm
_sub: ;//subprocedure
    push bp ;push bp onto the stack
    mov bp, sp ;move sp into bp
    mov dx, [bp+04h] ;move string into dx register
    mov ah, 09h ;prepare for print string
    int 21h ;print string
    mov sp, bp ;mov bp into sp
    pop bp ;restore value of bp
ret ;end of sub-procedure   

当我运行代码时,我得到了绝对废话的奇怪输出。

我知道当子程序与主程序在同一个文件中时子程序有效(即它打印预期的字符串)并且我知道子程序实际上已成功调用,就像什么时候一样'79h' 的值被移动到 dx 寄存器中,而不是 '[bp+04h]',字母 'y' 被打印出来。请有人告诉我 O 做错了什么?

谢谢。

【问题讨论】:

  • 错误可能在于您如何组装和链接,但您没有提供该详细信息。此外,反汇编创建的二进制文件并检查是否可以发现任何内容。 *哦,我看到你使用include。好吧,这应该和将它放在同一个文件中一样好。但它可能会弄乱您程序的入口点。将include 放在main 函数之后。
  • 谢谢@Jester - 我已将“包含”移至主程序之后,并且代码运行良好。请问为什么会这样(我的意思是它如何弄乱程序的入口点)?
  • org 100h 判断,我假设您正在编写一个dos .com 文件。它没有入口点信息,只是从地址100h 开始执行,这是您文件中的第一件事。无论您在开头放置什么,都将是起点。甚至不需要标签。
  • 哦-我现在明白了。谢谢@Jester。这个问题让我困惑了好几个小时;-)

标签: assembly stack procedure fasm


【解决方案1】:

把 cmets 变成一个答案:

;subprocedure test- main.asm
org 100h
_main: ;main method
    mov dx, string ;move string to dx register
    push dx ;push dx onto the stack
    call _sub;calls sub-procedure
    pop dx ;restores value of dx
    int 20h;exit program
ret ;end of main method
include 'sub.asm' ;file of sub-procedure
string db 'Some text $' ;string to be printed  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    相关资源
    最近更新 更多