Why isn’t my ‘show_msg’ function working properly?
org 100h
push str1
call show_msg
pop ax
mov ah, 4Ch
int 21h
show_msg:
mov ah, 9
mov bx, sp ;in 16bit bx is the only register that can act as a pointer (besides di and si)
mov dx, [bx]
int 21h
ret
str1 db 'Hello world!$'
Most probably because
[sp]upon entry to the function contains the address of the return code, which – in case of this program – will be whatever addresspop axat the beginning is under. Try changingmov dx, [bx]tomov dx, [bx+2], which will cause the value of the argument pushed before the entry to the function to be retrieved.