flat assembler
Message board for the users of flat assembler.

Index > Main > What is the BP register?

Author
Thread Post new topic Reply to topic
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 23 Mar 2010, 03:17
What exactly does the BP register do?

_________________
meshnix
Post 23 Mar 2010, 03:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20593
Location: In your JS exploiting you and your system
revolution 23 Mar 2010, 03:25
MeshNix wrote:
What exactly does the BP register do?
It stores binary data. It can't dance the cha-cha-cha, it is not that clever.
Post 23 Mar 2010, 03:25
View user's profile Send private message Visit poster's website Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 23 Mar 2010, 03:40
lol. But i mean? I know it is called the FRAME REGISTER and it can be used for sorting parameters and local variable
Post 23 Mar 2010, 03:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20593
Location: In your JS exploiting you and your system
revolution 23 Mar 2010, 03:42
It is just another register. There is nothing special about it other than in 16bit code it is one of the few available address registers, and uses SS as default segment. Nothing to write home about though.
Post 23 Mar 2010, 03:42
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 23 Mar 2010, 03:46
It's used to store the location of the stack while you manipulate (e)sp.
Code:
called_from_c: ; args: void *base, short limit
push ebp ; store the caller's ebp
mov ebp, esp ; store your esp
mov word[limit], [esp + 8] ; retrieve "short limit"
mov dword[base], [esp + 10] retrieve "void *base"
lgdt[gdtr]
...
mov esp, ebp ; restore your stack
pop ebp ; restore callers stack
ret
gdtr:
limit rw 1
base rd 1
    

vid's example(hosted here, on the examples page) of mixing c and asm has many better examples of how ebp is used. Am I right, revolution?(that this is the conventional use of ebp)
And doesn't "enter" and "leave" mess with ebp?
Post 23 Mar 2010, 03:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20593
Location: In your JS exploiting you and your system
revolution 23 Mar 2010, 04:07
In a conventional stdcall or ccall procedure ebp is often used to address the stack. But that is only by convention. One can easily use any other register if one wants to.


Tyler wrote:
Code:
mov word[limit], [esp + 8]    
That ain't never going to compile. Memory to memory move instructions, except for movs{bwdq}, are not supported by x86.
Post 23 Mar 2010, 04:07
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 23 Mar 2010, 04:15
revolution wrote:

That ain't never going to compile. [...]

It's always gonna compile? Razz
Post 23 Mar 2010, 04:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20593
Location: In your JS exploiting you and your system
revolution 23 Mar 2010, 04:21
Standard modern meme. Think of it like this: "That ain't, never, going ..."
Post 23 Mar 2010, 04:21
View user's profile Send private message Visit poster's website Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 23 Mar 2010, 07:20
Tyler wrote:
revolution wrote:

That ain't never going to compile. [...]

It's always gonna compile? Razz
In some languages (and even in some dialects of English) double negative resolves to a negative. However, in so-called "Standard English" it's just plain ugly, awkward and wrong.
Post 23 Mar 2010, 07:20
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 23 Mar 2010, 08:53
this ain't never going to work well too.

there is a very big miss of codes and datas.

maybe a GDT operation is not a very good example to understand the useage of BP.

BP means Base Pointer.

it means, Base for parameters on the stack, because some calling conventions (not always C based) use stack to pass parameters.

then, use this code to play with params:

Code:
;below code is not sure, because i never play with stack
;but the idea is there.
;
;ss_esp: dd retpointer,retvalue,param1,param2
;
mov ebp,esp
push eax ebx
mov eax,[ebp+8] ;not sure of this offset
imul eax,[ebp+12] ;not sure of this offset
mov [ebp+4],ebx ;not sure of this offset
pop ebx eax
ret
    
Post 23 Mar 2010, 08:53
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 23 Mar 2010, 09:47
revolution wrote:
Memory to memory move instructions, except for movs{bwdq}, are not supported by x86.


Wrong: MOVS, PUSH and POP (POPE) have been there since 8086 Wink

But I miss SWAP (XCHG) memory with memory Sad
Post 23 Mar 2010, 09:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20593
Location: In your JS exploiting you and your system
revolution 23 Mar 2010, 10:47
Yeah, I forgot about push and pop.
Post 23 Mar 2010, 10:47
View user's profile Send private message Visit poster's website Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 23 Mar 2010, 16:58
Very complicated stuff. The bp points to a stack frame, when you set it to sp.
Post 23 Mar 2010, 16:58
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Mar 2010, 17:51
Do you understand how stack works? If not, then learn working with stack first (PUSH, POP, CALL, RET)
Post 23 Mar 2010, 17:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 23 Mar 2010, 19:23
I have a basic knowledge of the stack.

The stack is a memory location where it is accessed by pop and push.
SP points to the top of the stack
Post 23 Mar 2010, 19:23
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Mar 2010, 20:22
now proceed to CALL and RETN Smile
Post 23 Mar 2010, 20:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 23 Mar 2010, 22:20
Fanael wrote:

In some languages (and even in some dialects of English) double negative resolves to a negative.

The southern US(NC included) dialect is one of those dialects, I was just screwin' around.
edfed wrote:

maybe a GDT operation is not a very good example to understand the useage of BP.

I agree, but like I said, if you want a good example look at vid's.
Post 23 Mar 2010, 22:20
View user's profile Send private message Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 23 Mar 2010, 22:56
Another question, how does one use a reserved variable?

example:
Code:
buffer rb 128    
Post 23 Mar 2010, 22:56
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 23 Mar 2010, 23:56
it just reserves 128 bytes of memory starting at address of label 'buffer'.
you could write it as

buffer db 128 dup (0)

which means that variable buffer is 128 bytes long and initialized to all zeroes (came from masm syntax)

this can be used if you allocate virtual memory, for example,

virtual at 0x1000
buffer rb 128
end virtual

this code won't place 128 bytes in your binary file, but it will correctly resolve address of the variable.

by the way, fasm comes with a very good tutorial. you can find answers to such questions there
Post 23 Mar 2010, 23:56
View user's profile Send private message Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 24 Mar 2010, 02:30
Thanks zhak
Post 24 Mar 2010, 02:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.