flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
redsock 11 Oct 2014, 20:34
Your question #1 doesn't really make sense, rsp is basically just another general purpose register, so its value after a "sub rsp, 8" depends on what it was beforehand
![]() As for your second and third question, see the below example. Compile with: fasm example.asm && ld -o example example.o Then run with: gdb ./example Code: format ELF64 db 1, 2, 3 ; intentional misalignment public maligned maligned: push rbp mov rbp, rsp ; framepointers to make gdb happy int3 ; breakpoint nop leave ; restore stackframe ret public _start _start: sub rsp, 3 ; intentionally misalign the stack int3 ; breakpoint nop call maligned ; jump off into misaligned function mov eax, 60 ; exit xor edi, edi ; return code syscall Hope that helps ![]() will show that both maligned and _start functions are both not aligned by 16. |
|||
![]() |
|
gens 11 Oct 2014, 21:28
2. i made myself a macro
Code: macro fcall routine, op1, op2, op3, op4, op5, op6 { if op6 eq else if op6 eqtype rax+3 lea r9, [op6] else mov r9, op6 end if if op5 eq else if op5 eqtype rax+3 lea r8, [op5] else mov r8, op5 end if if op4 eq else if op4 eqtype rax+3 lea rcx, [op4] else mov rcx, op4 end if if op3 eq else if op3 eqtype rax+3 lea rdx, [op3] else mov rdx, op3 end if if op2 eq else if op2 eq rsi else if op2 eqtype rax+3 lea rsi, [op2] else mov rsi, op2 end if if op1 eq else if op1 eqtype rax+3 lea rdi, [op1] else mov rdi, op1 end if call [routine] } it's not perfect by any stretch it doesn't do floats, that in the amd64 abi go in xmm registers it doesn't do more then 6 parameters ( every over 6 should go on the stack ) and if you do something like "fcall call, rsi, rdi" it will first put mov rsi, rdi then mov rdi, rsi making them bout what was in rdi the first 2 things i could easily put it, but the 3'rd problem gets complicated note that the kernel calling convention is slightly different edit: on more thing if you do "fcall call, rdi" it will make it mov rdi, rdi i should put that in too 3. is the info too put in the elf header interpreter (linker/loader) tells what to use to fill the... forgot what the section is called, anyway it's for shared library call addresses needed tells the the linker what shared libraries to check for calls import tells what functions to declare in the section that i cant remember the name of you can only have one import declaration, so use \ to skip newlines ![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.