简体   繁体   English

多模块汇编程序

[英]Multimodule assembler program

I'm having troubles with creating simple multimodule program in DOS. 我在DOS中创建简单的多模块程序遇到麻烦。

What I want is to create procedure which increments ax with 5 and call it from main procedure. 我想要的是创建一个将ax递增5并从主过程调用它的过程。 But every time I start debugging I get strange problem with infinite one-instruction cycle: 但是每次我开始调试时,我都会遇到一个无限的单指令周期问题:

add [bx:si], al

Down here is my first file: 这是我的第一个文件:

;(tmp1.bat)
.model small
.386
extrn mytmp

.code
org 100h
start:
  mov ax, 5
  push ax
  call mytmp
  pop ax
  mov dl, al
  mov ah, 06h
  int 21h
  ret
end start
end

And the second file: 第二个文件:

;(tmp2.bat)
.model small
.386
public mytmp

.code
mytmp: 
  pop ax
  add ax, 5
  push ax
  ret
END

What am I doing wrong? 我究竟做错了什么? PS compiling from DOS: 从DOS进行PS编译:

tasm tmp1.bat
tasm tmp2.bat
tlink /t tmp1.obj tmp2.obj

This code: 这段代码:

pop ax
add ax, 5
push ax
ret

Is completely nonsensical and causes a crash. 是完全荒谬的,并导致崩溃。 You are popping the return address from the stack, adding 5 to it, putting it back in the stack, and returning. 您正在从堆栈中弹出返回地址,向其添加5,然后将其放回堆栈中,然后返回。 So, the function returns to the original intended return address plus five, which is an arbitrary location five bytes after the location where the call was supposed to return. 因此,该函数返回到原始预期的返回地址加5,这是调用应返回的位置之后五个字节的任意位置。

Apparently, that's in the middle of some instruction, so the disassembler gets confused, and it is showing you that you are about to execute add [bx:si], al which is a nonsensical, non-existent instruction. 显然,这是在某些指令的中间,因此反汇编程序会感到困惑,并且向您显示您将要执行add [bx:si], al这是一个毫无意义,不存在的指令。

So, whatever it is that you thought you were trying to achieve with those 3 instructions in your mytmp: function, it is wrong, and you should not be doing it. 因此,无论您认为要使用mytmp:函数中的这3条指令来实现什么,它都是错误的,并且您不应该这样做。

TASM assembles call mytmp as an indirect call according to a value in mytmp . TASM根据mytmp的值将call mytmp汇编为间接调用。 It doesn't know that mytmp is a procedure. 它不知道mytmp是一个过程。

Change 更改

extrn mytmp

to

extrn mytmp:PROC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM