我在将参数传递给主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做错了什么?
谢谢。
答案 0 :(得分: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