flat assembler
Message board for the users of flat assembler.

Index > Windows > fasmg fails to compile win32console.asm

Author
Thread Post new topic Reply to topic
yeohhs



Joined: 19 Jan 2004
Posts: 195
Location: N 5.43564° E 100.3091°
yeohhs 16 Jun 2019, 09:48
Compile error is:
Code:
c:\fasmg\mycode>fasmg win32console.asm
flat assembler  version g.ik0iv
win32console.asm [1] macro PE [70] macro include [1] c:\fasmg\include/format/pe.
inc [378]:
        db (NUMBER_OF_SECTIONS-1)*SectionTable.ENTRY_LENGTH dup 0
Processed: db (NUMBER_OF_SECTIONS-1)*SectionTable.ENTRY_LENGTH dup 0
Error: value out of allowed range.
    


Code:
format PE CONSOLE 4.0
entry start

include 'win32axp.inc'
;-------------------------------------------------------------------------------
macro println arg*
   cinvoke printf, '%s', arg
   cinvoke printf, CRLF
end macro

;-------------------------------------------------------------------------------
section '.code' code readable executable
start:
    stdcall getcmdargs
    println arg1
    println arg2
    println arg3

finished:
    invoke  ExitProcess,0

;-------------------------------------------------------------------------------
proc showhelp
     println progtitle
     println arghelptitle
     println arg1help
     println arg2help
     println arg3help
     ret
endp

;-------------------------------------------------------------------------------
proc getcmdargs
    invoke GetCommandLine
    cinvoke strcpy,cmdline,eax

    cinvoke strtok, cmdline,strsep
    mov dword[strtokretval], eax

    cinvoke strtok, NULL,strsep
    mov dword[strtokretval],eax
    if dword[strtokretval] = NULL
        stdcall showhelp
        jmp finished
    else
        cinvoke strcpy, arg1, dword[strtokretval]
    endif

    cinvoke strtok, NULL,strsep
    mov dword[strtokretval], eax
    if dword[strtokretval] = NULL
        stdcall showhelp
        jmp finished
    else
        cinvoke strcpy, arg2, dword[strtokretval]
    endif

    cinvoke strtok, NULL,strsep
    mov dword[strtokretval], eax
    if dword[strtokretval] = NULL
        stdcall showhelp
        jmp finished
    else
        cinvoke strcpy, arg3, dword[strtokretval]
    endif
     jmp okay
finished:
    invoke  ExitProcess,0
okay:
     ret
endp
;-------------------------------------------------------------------------------
section '.data' data readable writeable
    progtitle    db 'Win32 Console Program version 0.0.1 Copyright (c) 2018 by Yeoh HS',0
    arghelptitle db 'Usage: win32console arg1 arg2 arg3',0
    arg1help     db 'arg1 - help for argument #1',0
    arg2help     db 'arg2 - help for argument #2',0
    arg3help     db 'arg3 - help for argument #3',0     
    CRLF         db '',13,10,0
    strfmt       db '%s',0
    cmdline      rb 260
    strsep       db " ",0
    strtokretval rb 1024
    arg1         rb 32
    arg2         rb 32
    arg3         rb 32
;-------------------------------------------------------------------------------
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,\
       strcpy, 'strcpy',\
       strtok, 'strtok',\
       printf, 'printf'
;-------------------------------------------------------------------------------
section '.rsrc' data readable resource from 'win32console.res'

; end of file ==================================================================
    


What am I missing here? Thanks for any help. By the way, the other 64-bit version, Win64console.asm, compiles okay and runs as expected.

P.S. I've the header files from GitHub.
Post 16 Jun 2019, 09:48
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 16 Jun 2019, 11:56
Because of fasmg's extensive use of forward-referencing, sometimes avalanche of errors occurs out of order and the first one is not very informative.

Dumping all errors with "-e1000" switch and digging through them uncovers the main problem:
Code:
win32console.asm [42]:
        if dword[strtokretval] = NULL
Error: missing end directive.    
You should have used .IF instead of IF there, fasmg interpreted this as its regular IF directive and because it was not ended with END IF, it broke all the structure of source, for example subsequent ENDP was not processed at all (because it was inside an IF block with incorrect - and thus considered false - condition).

Changing these IF/ELSE/ENDIF to .IF/.ELSE/.ENDIF fixes the main, structural problem. What remained uncovered a small bug in the CCALL macro - I have just fixed it, please update.
Post 16 Jun 2019, 11:56
View user's profile Send private message Visit poster's website Reply with quote
yeohhs



Joined: 19 Jan 2004
Posts: 195
Location: N 5.43564° E 100.3091°
yeohhs 16 Jun 2019, 12:35
Tomasz Grysztar wrote:

Dumping all errors with "-e1000" switch and digging through them uncovers the main problem:


Woo hoo! Very Happy Thank you very much. I used the -e1000 switch and managed to resolve another problem.

Code:
c:\fasmg\mycode>fasmg -e1000 win32console.asm
flat assembler  version g.ik0iv
5 passes, 1.3 seconds, 5632 bytes.

c:\fasmg\mycode>
    


Revised:
Code:
format PE CONSOLE 4.0
entry start

include 'win32axp.inc'
;-------------------------------------------------------------------------------
macro println arg*
   cinvoke printf, '%s', arg
   cinvoke printf, CRLF
end macro
;-------------------------------------------------------------------------------
section '.code' code readable executable
start:
    stdcall getcmdargs
    println arg1
    println arg2
    println arg3

.finished:
    invoke  ExitProcess,0

;-------------------------------------------------------------------------------
proc showhelp
     println progtitle
     println arghelptitle
     println arg1help
     println arg2help
     println arg3help
     ret
endp

;-------------------------------------------------------------------------------
proc getcmdargs
    invoke GetCommandLine
    cinvoke strcpy,cmdline,eax

    cinvoke strtok, cmdline,strsep
    mov dword[strtokretval], eax

    cinvoke strtok, NULL,strsep
    mov dword[strtokretval],eax
    .if dword[strtokretval] = NULL
        stdcall showhelp
        jmp .finished
    .else
        cinvoke strcpy, arg1, [strtokretval]
    .endif

    cinvoke strtok, NULL,strsep
    mov dword[strtokretval], eax
    .if dword[strtokretval] = NULL
        stdcall showhelp
        jmp .finished
    .else
        cinvoke strcpy, arg2, [strtokretval]
    .endif

    cinvoke strtok, NULL,strsep
    mov dword[strtokretval], eax
    .if dword[strtokretval] = NULL
        stdcall showhelp
        jmp .finished
    .else
        cinvoke strcpy, arg3, [strtokretval]
    .endif
     jmp .okay
.finished:
    invoke  ExitProcess,0
.okay:
     ret
endp
;-------------------------------------------------------------------------------
section '.data' data readable writeable
    progtitle    db 'Win32 Console Program version 0.0.1 Copyright (c) 2018 by Yeoh HS',0
    arghelptitle db 'Usage: win32console arg1 arg2 arg3',0
    arg1help     db 'arg1 - help for argument #1',0
    arg2help     db 'arg2 - help for argument #2',0
    arg3help     db 'arg3 - help for argument #3',0     
    CRLF         db '',13,10,0
    strfmt       db '%s',0
    cmdline      rb 260
    strsep       db " ",0
    strtokretval rb 1024
    arg1         rb 32
    arg2         rb 32
    arg3         rb 32
;-------------------------------------------------------------------------------
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,\
       strcpy, 'strcpy',\
       strtok, 'strtok',\
       printf, 'printf'
;-------------------------------------------------------------------------------
section '.rsrc' data readable resource from 'win32console.res'

; end of file ==================================================================

    
Post 16 Jun 2019, 12:35
View user's profile Send private message Visit poster's website Reply with quote
yeohhs



Joined: 19 Jan 2004
Posts: 195
Location: N 5.43564° E 100.3091°
yeohhs 16 Jun 2019, 12:43
Tomasz Grysztar wrote:
What remained uncovered a small bug in the CCALL macro - I have just fixed it, please update.


Thanks, I got the update from GitHub.
Post 16 Jun 2019, 12:43
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.