Author Topic: problem with parameters to a func by bp reg  (Read 16919 times)

nobody

  • Guest
problem with parameters to a func by bp reg
« on: July 17, 2008, 05:53:56 PM »
hi can you help me finding what the problem when i m running this programe

this is printing text string on screen where cursor func point the cursor but error i am getting is this

Error:

L:\nasm>nasm -o video.com video.txt
video.txt:4: error: comma or end of line expected



[org 0x100]

segment .text                     ;segment where code start loosing control(cs)
call cursor 10,20  <
mov dx,msg
mov ah,9
int 21h

mov ax,4C00h
int 21h



cursor:                              ;func to throw cursor on the consol

push bp
mov bp,sp



mov dh,[bp+4]                       ;passing col value using stack frame pointer
mov dl,[bp+6]                       ;passing row value
mov ah,02h
xor bh,bh
int 10h

mov sp,bp
pop bp

ret



segment .data                               ;Data area(ds)

msg db "dude why dont u print on the consol !! $"

nobody

  • Guest
Re: problem with parameters to a func by bp reg
« Reply #1 on: July 17, 2008, 07:08:03 PM »
Aha!


got it now


[org 0x100]

segment .text                     ;segment where code start loosing control(cs)

push 40      ;<< have to give argument to the stack before calling the func m i ryt here??
push 40      ;<<

call cursor

nobody

  • Guest
Re: problem with parameters to a func by bp reg
« Reply #2 on: July 17, 2008, 07:22:28 PM »
The actual "call" instruction takes only one parameter - the function to be called, "cursor" in this case. Try:

push 20
push 10
call cursor

Sometimes a macro is used to "encapsulate" pushing parameters and calling the function. Often called "invoke", but it *can* be named "call" (a really bad idea, IMO!). Nasm doesn't have any such thing "built in", you'd have to %include "mymac.inc" or so. Since you don't, you have to do it "raw" (a *much* better idea, IMO, at least until you understand what the macro is doing).

A subroutine *can* end with "ret 4" (in this case) which would remove the parameters from the stack. This would be the "stdcall" convention (used by Windows API, for example). Since you don't do that, you probably want:

push 20
push 10
call cursor
add sp, 4

to return the stack to its original condition. Won't hurt to proceed with a "corrupted" stack in this case, but it'll "byte" you eventually...

The error message is a little "generic" - in this case "end of line" is expected, you've already got "too many" commas...

Hope that helps.

Best,
Frank

nobody

  • Guest
Re: problem with parameters to a func by bp reg
« Reply #3 on: July 17, 2008, 07:49:33 PM »
Hi

Yeah indeed it does,


but i am stuck with this code here i wanted to make func sum that will return me sum in variable sum1 but it does not work


my code is:



org 100h


push 20
push 10


call sum
add sp,4

mov [sum1],ax

xor ax,ax

mov ah,9
mov dx,msg
int 21h

mov ah,40h
mov bx,1
mov cx,2
mov dx,sum1
int 21h


mov ax,4c00h
int 21h

sum:

push bp
mov bp,sp

sub sp,2
xor bx,bx
add bx,[bp+4]
add bx,[bp+6]
mov ax,bx

mov sp,bp
pop bp
ret



segment .data

msg db "The sum is : $"

sum1  db 0,0




output i get is this:


P:\nasm>sum
The sum is : ?

can u suggest where m i wrong pls

Thanks !!