flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
asmcoder 08 Jul 2009, 08:00
[content deleted]
Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total |
|||
![]() |
|
Pirata Derek 08 Jul 2009, 11:27
This is an example of using ENTER instruction:
Please, check how many simple is... Code: Format PE GUI 5.0 entry start section '.code' code readable executable start: pushd 3 pushd 2 pushd 1 call PROCEDURE ; the same of STDCALL ....,1,2,3 ret ; nesting level = 0 PROCEDURE: enter 3*4,0 ; 3 parameters of 4 bytes (dword) mov eax,[ebp+8+4*0] ; first parameter mov ebx,[ebp+8+4*1] ; second parameter mov ecx,[ebp+8+4*2] ; third parameter nop leave ret 3*4 ; relase 12 bytes of stack use: ENTER (number of bytes to reserve),(nesting level) ![]() |
|||
![]() |
|
LocoDelAssembly 08 Jul 2009, 16:17
thimis, it is correct. ENTER and LEAVE can be simulated like this:
Code: ; enter X, 0 push ebp mov ebp, esp sub esp, X ; leave mov esp, ebp pop ebp |
|||
![]() |
|
asmcoder 08 Jul 2009, 16:42
[content deleted]
Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total |
|||
![]() |
|
bitRAKE 08 Jul 2009, 16:47
LocoDelAssembly's simulation only works for ENTER #,0 (most common case). The second parameter for ENTER copies data from address pointed to by EBP onto the stack - up to 31 dwords can be copied.
Having a common tail on procedures eases code reuse. Usually smaller code is generated because accessing local/parameter data from ESP requires one byte more than EBP. Can be faster because EBP remains constant throughout procedure - ESP has dependencies with PUSH/POP/CALL. Useful for recursion or stack based procedures where local stack use is dynamic - LEAVE restores parent frame. Here is a symbolic framework to ease use of ENTER/LEAVE. Let FASM calculate all the constants and ease changes, imho. Code: MyWndProc: enter .frame,0 virtual at ebp-.frame .hBrush rd 1 .pt PT .rect RECT .atom rw 1 .frame = NOT 3 AND ($-$$+3) rb $$+.frame-$ ; dword stack alignment .EBP rd 1 ; value on entry .RET rd 1 ; to caller ; parameters from caller: .hWnd rd 1 .uMsg rd 1 .wParam rd 1 .lParam rd 1 .params = $-.hWnd end virtual cmp [.uMsg],WM_CREATE . . . leave retn .params |
|||
![]() |
|
LocoDelAssembly 08 Jul 2009, 17:44
asmcoder, your idea requires too many precious registers for something that can be done safely by just using EBP (PROC macro does this). And to avoid issues by miscalculating offsets you can simply use bitRAKE's proposal (though, your idea still made possible to fuck offsets).
|
|||
![]() |
|
eskizo 09 Jul 2009, 13:15
LocoDelAssembly,
Code: push ebp mov ebp, esp sub esp, 12 ; dword a, b, c; mov dword [ebp-4], eax mov dword [epb-8], ebx mov dword [ebp-12], ecx ; a = eax; b = ebx; c = ecx; ... mov esp, ebp pop ebp Is this correct? Do I have to use retn x in this code? thanks |
|||
![]() |
|
pal 09 Jul 2009, 13:36
That code will work yes as you restore esp. You can add an add esp,12 in there if you want to. The ret is fine, but make sure you add it in there to return from any procedure.
|
|||
![]() |
|
LocoDelAssembly 09 Jul 2009, 13:48
eskizo, yes. Don't forget to RETN 4*args_passed (it is not part of LEAVE but necessary to return control to the caller).
|
|||
![]() |
|
Borsuc 09 Jul 2009, 15:03
it has a typo, epb instead of ebp somewhere
![]() _________________ Previously known as The_Grey_Beast |
|||
![]() |
|
Picnic 09 Jul 2009, 18:01
Quite hepful posts. Thank you all guys.
|
|||
![]() |
|
pal 09 Jul 2009, 20:19
No args are passed so it would be retn 4*0 or just retn. The values he allocates are on the stack locally.
|
|||
![]() |
|
eskizo 10 Jul 2009, 13:26
Well, this is a very helpful post for begginers, then:
Code: nop call Something nop .. Something: push ebp mov ebp, esp sub esp, 8 ; dword a, b; xor eax, ebx mov [ebp-4], eax ... add eax, 0x1234 mov [ebp-8], eax ... mov esp, ebp pop ebp ret I think this is OK too. But could someone give me an "Arguments passing" example (easy to understand) ? thankyou guys! |
|||
![]() |
|
revolution 10 Jul 2009, 13:32
eskizo wrote: But could someone give me an "Arguments passing" example (easy to understand) ? thankyou guys! |
|||
![]() |
|
Pirata Derek 11 Jul 2009, 11:20
The package below contains the macros for PROC32 that creates procedures using the ENTER instruction.
also contains the NEW version of FASM assembled that has the ENTER instruction! (Disassemble FASM.exe to check them) ![]()
|
|||||||||||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.