FASM-将参数传递给外部程序 [英] FASM- passing parameters to an external procedure
问题描述
在将参数传递到主ASM文件之外的过程时遇到麻烦.这是我的代码.它显示了一个主要过程_main(在main.asm中),该过程在另一个源文件(sub.asm)中调用子过程_sub.子过程将打印由主过程指定的字符串.
I am having trouble with passing parameters to procedures outside the main ASM file. Here is my code. It shows a main procedure, _main (in main.asm) which calls a sub-procedure _sub in another source file (sub.asm). The sub-procedure prints a string specified by the main procedure.
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
运行代码时,我得到的是绝对胡说八道的奇怪输出.
When I run the code, I get the curious output of absolute nonsense.
我知道当子过程与主过程位于同一文件中时,子过程才起作用(即,它按预期方式打印字符串),并且我知道子过程实际上已成功调用,就像当将值"79h"移入dx寄存器而不是"[bp + 04h]",则打印字母"y".请有人能告诉我O在做什么错了吗?
I know that the sub-procedure works when the sub-procedure is in the same file as the main procedure (i.e. it prints the string like expected) and i know that the sub-procedure is in fact successfully called, as when the value of '79h' is moved into the dx register instead of '[bp+04h]', the letter 'y' is printed. Please could somebody inform me as to what O am doing wrong?
谢谢.
推荐答案
在评论中添加注释:
;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
这篇关于FASM-将参数传递给外部程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!