Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameters to a procedure

Status
Not open for further replies.

JavaDude32

Programmer
Aug 25, 2001
180
0
0
US
Okay, what I wish to do is pass some parameters to a procedure of mine, but I'm getting an invalid operation error at runtime, the code I have is:

;...
.MODEL SMALL
.STACK 64
.DATA
CURPOS DW 0928H
LPOS2 DW 1030H
LPOS3 DW 1134H
LINE1 DB 'BLAH.',0DH,0AH,'$'
LINE2 DB 'BLAH BLAH',0DH,0AH,'$'
LINE3 DB 'BLAH BLAH BLAH',0DH,0AH,'$'
BLUE DB 17
;-----------------------------------------------------
.CODE
MAIN PROC FAR
MOV AX,@data
MOV DS,AX
MOV ES,AX

MOV DH,BYTE PTR BLUE
PUSH DX
CALL CLRSCR
MOV AX,4C00H
INT 21H
MAIN ENDP
MAKEPOS PROC NEAR
POP DX
MOV AX,0200H
MOV BH,00H
INT 10H
RET
MAKEPOS ENDP
PRTLINE PROC
POP DX
MOV AX,0900H
INT 21H
RET
PRTLINE ENDP
CLRSCR PROC
POP BX
MOV AX,0600H
MOV CX,0000H
MOV DX,184FH
INT 10H
RET
CLRSCR ENDP
END MAIN

I think I have it narrowed down to the popping the stack value into the BX register, but I don't know why this is causing an error. Any help would be very much appreciated, thanks.

Sincerely,
JavaDude32
 
NOTE!!!

PUSH and POP use the stack.

CALL also uses the stack.

You have
PUSH DX
CALL CLRSCR
.
.
.
POP BX

So you PUSH DX, CALL pushes a return address on the stack, then POP BX pops off that address. :)

This is the "proper Microsoft sanctioned" way to do it:
CLRSCR proc
push bp
mov bp,sp
mov bx,[bp+4] ;warning! assumes near call, and 16-bit code.
.
.
.
pop bp
ret 2 ; have ret pop off the pushed word.
CLRSCR endp


"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Thanks a lot, I never even thought about the CALL pushing the return address on the stack although I knew it had to. Ret takes an argument to determine amount of popped values then I assume? Just that one question.
 
That's the number of bytes to pop off IIRC. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top