0

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

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

子组件:

;//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做错了什么?

谢谢你。

4

1 回答 1

0

对答案发表评论:

;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  
于 2015-01-26T14:47:18.310 回答