-1

here is an assembly program written in emu8086 esimulator.

.MODEL SMALL
.STACK
.DATA
msg db 10,13,"i am being called from the macro$"

.CODE
MOV AX, @DATA
MOV DS,AX
      
hehe PROC
    MOV DX, OFFSET msg
    MOV AH,09h
    INT 21h
    RET
hehe ENDP
call hehe 
call hehe

MOV AX,4C00h
INT 21h
END

The call statement is called just once but as I tried moving the procedure here and there inside .code I found that the output was because of the procedure itself not by the call function. What am I doing wrong here?

Raymond Chen
  • 43,603
  • 11
  • 89
  • 129
  • 4
    You have your function in the middle of your code path, which is wrong. You're going to be executing it, then returning from it to whatever happens to be on the stack. It should probably come after the main code path. Your function isn't being *called* once, you're just falling into it from the code before. – Thomas Jager May 18 '22 at 11:27
  • 1
    Recall that a small mode executable has its entry point at the beginning of the text section. So the first thin in that section must be the main program code. – fuz May 18 '22 at 16:19
  • Related: [Code executes condition wrong?](https://stackoverflow.com/q/32872539) / [What if there is no return statement in a CALLed block of code in assembly programs](https://stackoverflow.com/q/41205054) (you can look at the first 2 instructions as the beginning of your "main" function, which then falls into something else). CPUs always just execute the next instruction in memory, so don't put code somewhere you don't want execution to fall into it. – Peter Cordes May 18 '22 at 19:54

0 Answers0