flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > Two PE64 examples for beginners |
| Author |
|
|
frankobach26 13 Oct 2026, 18:04
Code: include 'win64a.inc' format PE64 console entry main section '.data' data readable writeable prompt1 db 'please type in first number: ' prompt1_len = $ - prompt1 prompt2 db 'please txpe in second number: ' prompt2_len = $ - prompt2 result_msg db 'result is : ' result_len = $ - result_msg newline db 13, 10 exit_msg db 'Enter to end..' exit_len = $ - exit_msg input1 rb 64 input2 rb 64 buffer rb 32 keybuf rb 8 written dd 0 hOut dq 0 hIn dq 0 section '.text' code readable executable main: sub rsp, 8 invoke GetStdHandle, -11 mov [hOut], rax invoke GetStdHandle, -10 mov [hIn], rax ; Erste Zahl einlesen invoke WriteConsoleA, [hOut], prompt1, prompt1_len, written, 0 invoke ReadConsoleA, [hIn], input1, 64, written, 0 ; Erste Zahl in Integer umwandeln lea rsi, [input1] xor rax, rax .parse1: movzx edx, byte [rsi] cmp dl, '0' jb .first_done cmp dl, '9' ja .first_done imul rax, rax, 10 sub edx, '0' add rax, rdx inc rsi jmp .parse1 .first_done: mov r12, rax ; Zweite Zahl einlesen invoke WriteConsoleA, [hOut], prompt2, prompt2_len, written, 0 invoke ReadConsoleA, [hIn], input2, 64, written, 0 ; Zweite Zahl in Integer umwandeln lea rsi, [input2] xor rax, rax .parse2: movzx edx, byte [rsi] cmp dl, '0' jb .second_done cmp dl, '9' ja .second_done imul rax, rax, 10 sub edx, '0' add rax, rdx inc rsi jmp .parse2 .second_done: mov r13, rax ; Multiplikation mov rax, r12 imul rax, r13 ; Ergebnis in Dezimalstring umwandeln lea rdi, [buffer + 31] mov byte [rdi], 0 mov ebx, 10 .convert: xor edx, edx div rbx add dl, '0' dec rdi mov [rdi], dl test rax, rax jnz .convert ; Ergebnistext ausgeben invoke WriteConsoleA, [hOut], result_msg, result_len, written, 0 ; Ziffernlaenge berechnen lea r8, [buffer + 31] sub r8, rdi ; Ergebnis ausgeben invoke WriteConsoleA, [hOut], rdi, r8d, written, 0 ; Neue Zeile invoke WriteConsoleA, [hOut], newline, 2, written, 0 ; Programm sichtbar offen halten invoke WriteConsoleA, [hOut], exit_msg, exit_len, written, 0 invoke ReadConsoleA, [hIn], keybuf, 8, written, 0 invoke ExitProcess, 0 section '.idata' import data readable writeable library kernel32, 'kernel32.dll' include 'api/kernel32.inc' ; |
|||
|
|
sylware 14 Oct 2026, 11:58
Is PE64 is actually PE+?
|
|||
|
|
Byte_Blast 16 Oct 2026, 04:26
sylware wrote: Is PE64 is actually PE+? PE64 is defined as PE32+ in microsoft documentation, you pretty much still have the correct interpretation so yes. |
|||
|
|
Tomasz Grysztar 16 Oct 2026, 09:04
sylware wrote: Is PE64 is actually PE+? |
|||
|
|
sylware 16 Oct 2026, 11:29
While I am thinking abouth this, for CPU exe and dynamic lib, PE+/ELF64 are so much obsolete.
Baw. |
|||
|
|
Core i7 17 Oct 2026, 08:31
frankobach26, why are you calculating the result manually? There are ready-made APIs for this wsprintf(). As it stands, it’s as if you’re working for the computer, rather than it working for you. And if this is a form, the window should be defined in the resources and invoked—using CreateWindow() for a main window, or DialogBoxParam() for a dialog window.
Code: format pe64 gui 4.0 entry main include 'win64ax.inc' ;------------ section '.data' data readable writeable a dq 365 b dq 2026 buff db 0 ;------------ section '.text' code readable executable main: sub rsp,8 mov rax,[a] imul rax,[b] mov ebx,1000 xor edx,edx div ebx xchg ebx,edx cinvoke wsprintf,buff,<'Our days living on Earth: %d.%d',0>,eax,ebx invoke MessageBox,0,buff,<'Fasm calculation',0>,0 invoke ExitProcess, 0 ;------------ section '.idata' import data readable library kernel32,'kernel32.dll', user32,'user32.dll' include 'api/kernel32.inc' include 'api/user32.inc' sylware, and what’s relevant these days, if not PE+? |
|||
|
|
sylware 17 Oct 2026, 11:38
It is not the point: it is completely obsolete on modern hardware architectures, "relevant" or whatever, We have enough experience to know that now.
ELF64 is as obsolete than PE+, nowadays I use my own ultra simple format (the JSON of exe and dynamic link) which I embed in an ELF64 capsule. This is basically one log2 aligned memory segment with an entry point and that's it. For dynamic libs, you get a "userland syscall" number resolution function offset and that's it. I am still on an another project, but I plan to try to build the system interface dynamic libs with that format (the main issue being c++). We are near zero-format, and does the job beyond good enough (actually, if "something" would require more than that, the problem is that "something"). |
|||
|
|
Core i7 17 Oct 2026, 12:08
Is this a custom project? Do you have any ready-made files for testing, so we can verify their binary structure?
|
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.