I'm having troubles with creating simple multimodule program in DOS.
What I want is to create procedure which increments ax with 5 and call it from main procedure. 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:
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. 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.
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.
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.
TASM assembles call mytmp
as an indirect call according to a value in mytmp
. It doesn't know that mytmp
is a procedure.
Change
extrn mytmp
to
extrn mytmp:PROC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.