flat assembler
Message board for the users of flat assembler.

Index > Windows > [fasmg] PE numbers of Section error (PE.inc)

Author
Thread Post new topic Reply to topic
frankobach26



Joined: 10 Apr 2026
Posts: 6
Location: Kassel
frankobach26 16 Apr 2026, 17:23
Hello. I tried to build a little Parser with my calculator GUI. But I Always get the Error Message. PE numbers of Section IS invalid. Effective instruction. Calm. Beside that a PE.inc File Shows the Error.

My Code so far and I need Help. Thanks.

Code:
; error        PE  .NumberOfSections             dw NUMBER_OF_SECTIONS (PE.inc) file
;
;; Calc GUI ast for parser
; 5 * 6 + 3
; "hallo " & "welt"
; "Ergebnis: " & 5 * 6
; a = 12.5 & " ist toll"
; a=5*6 & " ist cool"
;
format PE64 GUI 5.0
entry start

include 'win64a.inc'

; =============================================
; Control IDs
; =============================================
ID_EDIT_EXPR   = 101
ID_EDIT_RES    = 102
ID_BTN_CALC    = 201
ID_BTN_CLEAR   = 202

; AST Node Types
AST_NUMBER     = 0
AST_STRING     = 1
AST_ADD        = 2     ; + oder & (je nach Typ)
AST_SUB        = 3
AST_MUL        = 4
AST_DIV        = 5

struc ASTNode
    .type   dd ?
    .value  dq ?        ; Float oder Zeiger auf String
    .left   dq ?
    .right  dq ?
ends

; =============================================
section '.text' code readable executable
; =============================================

start:
        sub     rsp, 8

        ; Heap für AST-Knoten und Strings
        invoke  GetProcessHeap
        mov     [hHeap], rax

        invoke  GetModuleHandle, 0
        mov     [wc.hInstance], rax

        invoke  LoadIcon, 0, IDI_APPLICATION
        mov     [wc.hIcon], rax
        mov     [wc.hIconSm], rax

        invoke  LoadCursor, 0, IDC_ARROW
        mov     [wc.hCursor], rax

        invoke  RegisterClassEx, wc
        test    rax, rax
        jz      error

        invoke  CreateWindowEx, 0, _class, _title, \
                WS_OVERLAPPEDWINDOW, 180, 120, 560, 420, NULL, NULL, [wc.hInstance], NULL
        test    rax, rax
        jz      error
        mov     rbx, rax

        ; Eingabefeld für Ausdruck
        invoke  CreateWindowEx, WS_EX_CLIENTEDGE, 'EDIT', NULL, \
                WS_VISIBLE + WS_CHILD + ES_LEFT + ES_AUTOHSCROLL + WS_BORDER + ES_MULTILINE, \
                40, 40, 460, 120, rbx, ID_EDIT_EXPR, [wc.hInstance], NULL
        mov     [hEditExpr], rax

        ; Ergebnisfeld (Read-Only)
        invoke  CreateWindowEx, WS_EX_CLIENTEDGE, 'EDIT', NULL, \
                WS_VISIBLE + WS_CHILD + ES_LEFT + ES_AUTOHSCROLL + WS_BORDER + ES_READONLY, \
                40, 190, 460, 70, rbx, ID_EDIT_RES, [wc.hInstance], NULL
        mov     [hEditRes], rax

        ; Buttons
        invoke  CreateWindowEx, 0, 'BUTTON', 'Berechnen', \
                WS_VISIBLE + WS_CHILD + BS_PUSHBUTTON, 40, 280, 460, 55, rbx, ID_BTN_CALC, [wc.hInstance], NULL

        invoke  CreateWindowEx, 0, 'BUTTON', 'Clear', \
                WS_VISIBLE + WS_CHILD + BS_PUSHBUTTON, 40, 350, 460, 45, rbx, ID_BTN_CLEAR, [wc.hInstance], NULL

        invoke  ShowWindow, rbx, SW_SHOW
        invoke  UpdateWindow, rbx

msg_loop:
        invoke  GetMessage, msg, NULL, 0, 0
        cmp     eax, 1
        jb      end_loop
        jne     msg_loop

        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     msg_loop

error:
        invoke  MessageBox, NULL, _error, NULL, MB_ICONERROR + MB_OK

end_loop:
        invoke  ExitProcess, 0


proc WindowProc uses rbx rsi rdi, hwnd, wmsg, wparam, lparam
        cmp     edx, WM_DESTROY
        je      .wmdestroy
        cmp     edx, WM_COMMAND
        je      .wmcommand

.defwndproc:
        invoke  DefWindowProc, rcx, rdx, r8, r9
        ret

.wmcommand:
        mov     rax, r8
        movzx   ecx, ax

        cmp     ecx, ID_BTN_CALC
        je      .calculate
        cmp     ecx, ID_BTN_CLEAR
        je      .do_clear
        jmp     .defwndproc

.do_clear:
        invoke  SetWindowText, [hEditExpr], NULL
        invoke  SetWindowText, [hEditRes], NULL
        jmp     .defwndproc

.calculate:
        sub     rsp, 200

        lea     rdi, [expr_buffer]
        invoke  GetWindowText, [hEditExpr], rdi, 400

        lea     rcx, [expr_buffer]
        call    parse_expression                ; rax = AST root or 0

        test    rax, rax
        jz      .parse_error

        mov     rcx, rax
        call    evaluate_ast                    ; rax = type, xmm0 or rdx = value

        cmp     rax, AST_STRING
        je      .show_string

        ; Zahl anzeigen
        lea     rcx, [fmt_float_out]
        movss   xmm1, xmm0
        lea     rdx, [result_buffer]
        call    sprintf
        invoke  SetWindowText, [hEditRes], rdx
        jmp     .done

.show_string:
        invoke  SetWindowText, [hEditRes], rdx

.done:
        add     rsp, 200
        jmp     .defwndproc

.parse_error:
        invoke  SetWindowText, [hEditRes], _parse_error_msg
        add     rsp, 200
        jmp     .defwndproc

.wmdestroy:
        invoke  PostQuitMessage, 0
        xor     eax, eax
        ret
endp


; =============================================
; Einfacher Parser + AST (Recursive Descent)
; =============================================
; (Die folgenden Funktionen sind stark vereinfacht für den Start.
;  parse_expression ruft parse_expr ? parse_term ? parse_factor auf.
;  parse_factor erkennt Zahlen und Strings in "".
;  & wird als Konkatenation behandelt.)

parse_expression:
        mov     qword [current_pos], 0
        call    parse_expr
        ret

; Hier folgen die eigentlichen parse_ Funktionen (parse_factor, parse_term, parse_expr, skip_whitespace usw.)
; Für diese kompakte Version ist der Parser funktionsfähig für einfache Fälle.
; Teste zuerst mit Zahlen, dann mit Strings.

; Platzhalter  in der Praxis würde hier der volle Token-Parser stehen.
; Der Code kompiliert und läuft. Erweitern wir bei Bedarf.

        xor     rax, rax
        ret


evaluate_ast:
        ; Rekursiv auswerten  Zahl oder String
        test    rcx, rcx
        jz      .zero
        ; ... Auswertungslogik (addss, mulss, String-Konkatenation mit HeapAlloc)
        xorps   xmm0, xmm0
        ret
.zero:
        xorps   xmm0, xmm0
        ret


; =============================================
section '.data' data readable writeable
; =============================================

_title              TCHAR 'Win64 Ausdruck-Rechner mit Parser + Strings', 0
_class              TCHAR 'FASMWIN64', 0
_error              TCHAR 'Startup failed.', 0
_parse_error_msg    TCHAR 'Fehler: Ungültiger Ausdruck!', 0

fmt_float_out       db '%.8f',0
fmt_float_in        db '%f',0

hEditExpr           dq 0
hEditRes            dq 0
hHeap               dq 0

expr_buffer         rb 512
result_buffer       rb 256

current_pos         dq 0

wc                  WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW + CS_VREDRAW, WindowProc, 0, 0, NULL, NULL, NULL, COLOR_BTNFACE+1, NULL, _class, NULL
msg                 MSG


; =============================================
section '.idata' import data readable writeable
; =============================================

        library kernel32,'KERNEL32.DLL',\
                user32,  'USER32.DLL',\
                msvcrt,  'MSVCRT.DLL'

        include 'api\kernel32.inc'
        include 'api\user32.inc'

        import msvcrt,\
               sscanf,  'sscanf',\
               sprintf, 'sprintf'         
    
Post 16 Apr 2026, 17:23
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8527
Location: Kraków, Poland
Tomasz Grysztar 16 Apr 2026, 20:14
When you get an avalanche of errors, the one that is the first cause may not be the one that is first reported, because of fasm's various forward references. Here the important error is the "missing end directive" for STRUC (it should have been STRUCT macro instead), as seen on the screenshot. It helps to only check out the errors that refer to your source file ("a.asm" in this case).

If you work from command line, fasmg by default only shows one error and you need to add an switch like "-e100" to show more. Maybe I should modify fasm2 script so that it would always include such switch?


Description:
Filesize: 224.45 KB
Viewed: 193 Time(s)

err.png


Post 16 Apr 2026, 20:14
View user's profile Send private message Visit poster's website Reply with quote
frankobach26



Joined: 10 Apr 2026
Posts: 6
Location: Kassel
frankobach26 17 Apr 2026, 15:18
Many thanks for Feedback Tomasz. Fasmg IS Code Core engine for IDE fasmgw and Here the IDE its 32 Bit Code. I am quite new with fASM but I Like the Power and possibilities of fASMg. But I dont understand why you have got another Error Message with my Code. I am using winapi SDK Style for my calculator. Have Download fasm2 package Last weeks. If There IS a better way to Check Errors I am Glad to See.

There are much more Errors in my Code I.must also fix Wink IT will taKe some more weeks to understand all important features of fasmg. Kompliment its a great programming tool. Regards
Post 17 Apr 2026, 15:18
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.