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!

Inline Assembly - How to use EBP(BP)

Status
Not open for further replies.

dxd

Technical User
Jan 27, 2000
474
0
0
US
Not really sure whether here or Assembly is the correct forum for this....I am sure some one will let me know if off topic!

Anyway, I have about zilch in Assembly experience....just letting you know so I don't get dogged out too bad!!
I am looking to write some code in C++ that is calling a 32bit BIOS function. The function itself is handled through a Ring 0 driver and I have used it before with the standard general purpose registers...both ins and outs.

However, this one particular function call winds up using BP to store the number of bytes I am attempting to read from an internal buffer.

I have done so much searching on the inet that my head is spinning [spin2] ...All that I know is you should save EBP(BP) "push ebp", "mov ebp, esp" before and then pop it after.

I have tried a number of variations and can't seem to get it right.

According to the spec of this particular Bios call, I need BP to = "bytes to read"...in my case this would be 10h.

Can anyone give me some pointers....if not appropriate for this forum I'll dump it in Assembly.

TIA Doug
dxd_2000@yahoo.com

 
My assembler is a bit rusty so I apologise if I've gotten the + and - the wrong way round. When you enter a routine, the routine needs to know

1) where you have come from so it can return there
2) what parameters you are passing through the stack
3) what local variables you have on the stack

sp the stack pointer is not safe to use since it changes everytime you do a push or a pop. Normally the routine starts as

push bp
mov bp,sp

This saves the stack pointer to the base pointer. The base pointer can now be used as a point of reference. For instance, to add 4 bytes on the stack for local variables

add sp,4

To move the first byte in al

mov al,byte ptr [bp+1]

Note that ptr means parameter but almost everyone I know reads it as pointer.

To get the parameters, use

mov ax,[bp - 2]

When you've finished, like new and delete, you just reverse whatever you did.

sub sp,4
pop bp

The thing is, if you are doing this in C++, the code for all this stuff is generated for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top