flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
adroit 23 Mar 2010, 03:17
What exactly does the BP register do?
_________________ meshnix |
|||
![]() |
|
revolution 23 Mar 2010, 03:25
MeshNix wrote: What exactly does the BP register do? |
|||
![]() |
|
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
|
|||
![]() |
|
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? |
|||
![]() |
|
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:
|
|||
![]() |
|
Tyler 23 Mar 2010, 04:15
revolution wrote:
It's always gonna compile? ![]() |
|||
![]() |
|
revolution 23 Mar 2010, 04:21
Standard modern meme. Think of it like this: "That ain't, never, going ..."
|
|||
![]() |
|
Fanael 23 Mar 2010, 07:20
Tyler wrote:
|
|||
![]() |
|
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 |
|||
![]() |
|
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 ![]() But I miss SWAP (XCHG) memory with memory ![]() |
|||
![]() |
|
revolution 23 Mar 2010, 10:47
Yeah, I forgot about push and pop.
|
|||
![]() |
|
adroit 23 Mar 2010, 16:58
Very complicated stuff. The bp points to a stack frame, when you set it to sp.
|
|||
![]() |
|
vid 23 Mar 2010, 17:51
Do you understand how stack works? If not, then learn working with stack first (PUSH, POP, CALL, RET)
|
|||
![]() |
|
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 |
|||
![]() |
|
vid 23 Mar 2010, 20:22
now proceed to CALL and RETN
![]() |
|||
![]() |
|
Tyler 23 Mar 2010, 22:20
Fanael wrote:
The southern US(NC included) dialect is one of those dialects, I was just screwin' around. edfed wrote:
I agree, but like I said, if you want a good example look at vid's. |
|||
![]() |
|
adroit 23 Mar 2010, 22:56
Another question, how does one use a reserved variable?
example: Code: buffer rb 128 |
|||
![]() |
|
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 |
|||
![]() |
|
adroit 24 Mar 2010, 02:30
Thanks zhak
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.