flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Byte counter

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
$ is current address counter
But there's no current byte counter Smile
To write something like:
Code:
rb 510-$$$
dw 0xAA55    

without reference to address changing... Smile

Maybe it's a good idea to add this feature? Smile
Post 09 Jul 2018, 16:40
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6999
Location: Kraków, Poland
This feature is present in fasmg with $% symbol. In fasm 1 there is not way to reliably provide such value because of how the formatter works.

It might, however, be possible to back-port $% into fasm 1 restricted only to "format binary" output. I may consider it.
Post 09 Jul 2018, 17:01
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 451
Location: Belarus
Wouldn’t it break the feature that allows saving generated data into multiple files? I mean, should we count all the bytes or bytes of a specific addressing space?

The original problem is nearly always solved by replacing the said $$$ with ($ – $$) since it’s pretty difficult to put code running from another memory location to the boot sector if you play fairly and read FAT12 without implying the secondary bootloader is the first file written to disk and stuff like that.
Post 09 Jul 2018, 20:40
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6999
Location: Kraków, Poland
DimonSoft wrote:
Wouldn’t it break the feature that allows saving generated data into multiple files? I mean, should we count all the bytes or bytes of a specific addressing space?
As it is defined and implemented in fasmg, it traces the current length of the main output, any auxiliary outputs do not count.
Post 09 Jul 2018, 21:13
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 451
Location: Belarus
I would think about all the possible variations at once since it won’t take long for people to ask more and further (consistent from language point of view) improvements might become more difficult by that time. A language constantly extended with features that are just easy to implement approaches C++ as the number of such features approaches infinity.
Post 09 Jul 2018, 22:35
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6999
Location: Kraków, Poland
DimonSoft wrote:
I would think about all the possible variations at once since it won’t take long for people to ask more and further (consistent from language point of view) improvements might become more difficult by that time. A language constantly extended with features that are just easy to implement approaches C++ as the number of such features approaches infinity.

fasmg was designed mostly to be a sum of all the things requested for fasm 1 over the years that were not always possible within the old framework. How it ended up? Actually, for several years I believed this design was impossible, since many of the goals were conflicting. I finally started working on it in 2014 when I found a way to put all these things together in a way that did not make them fall apart immediately. And it seems to work, at least I'm happy with how it works. But because it was so hard to find not a self-contradicting solution in the first place, it is also not so trivial to extend it further. Features that may look simple and consistent with the rest of language at first look, may show multiple problems upon closer inspection. This is also a reason why I prefer to have things implemented through macros and simpler features whenever possible. When something is "just a macro", it is easier to forgive some of the rough edges it might have. But when something has to be a part of underlying language, it should work well with the rest of it, and in case of design like fasmg this is not an easy task.
Post 09 Jul 2018, 22:54
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
Tomasz, I like many fasm 1 features but some "things implemented through macros" really irritate.
For instance it's very uncomfortable to add WinAPI function definition in source if it absent in standard inc-files. E.g. I need to use this in the end of source to add only one printf function:
Code:
section '.idata' import data readable

library kernel32, 'kernel32.dll',\
        msvcrt, 'msvcrt.dll'

        import_kernel32
        all_api
 
import  msvcrt,\
        printf, 'printf'    
But if I want to add kernel32 function (like GetFirmwareEnvironmentVariable) I need to list ALL kernel32 functions used in source:
Code:
section '.idata' import data readable

library kernel32, 'kernel32.dll'

import  kernel32,\
        CreateFileA, 'CreateFileA',\
        CloseHandle, 'CloseHandle',\
        ExitProcess, 'ExitProcess',\
        . . .
        GetFirmwareEnvironmentVariableA, 'GetFirmwareEnvironmentVariableA'

        api CreateFile
        api GetFirmwareEnvironmentVariable    
Post 20 Aug 2018, 09:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
I can't answer for Tomasz, but if you need to include other DLL files in your code then it is probably a good idea to make a new macro file for each DLL and then add those files as includes to your custom version of win32*.inc.
Post 20 Aug 2018, 10:49
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6999
Location: Kraków, Poland
These import macros are ancient, dating back to 2000, and their syntax was never re-designed to make use of more modern macro features. It was the backward compatibility that was holding them back and their syntax was made in times when fasm's preprocessor was very simple.

However, even if you wouldn't like to create a different set of import macros, with the features of new fasm versions it should be possible to create some kind of "wrapper" macros around the old syntax.

A simple example I made on the spot:
Code:
macro simport library_label*,label*,string
{
    match ,string \{ define library_label#.collection label,`label \}
    match any, string \{ define library_label#.collection label,string \}
}

macro import library_label*,list*&
{
    common
        local all
        define all ,
        irpv a ,library_label#.collection \{ all equ all a, \}
        match alist, all \{ import library_label alist list \}
}     
Use it like:
Code:
simport kernel32,GetFirmwareEnvironmentVariableA
api GetFirmwareEnvironmentVariable    
And then generate imports as usual, the additional functions are going to be inserted there.
Post 20 Aug 2018, 19:03
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
Maybe Tomasz can make some macros that will help to add new functions and new dlls?
Something like this:
Code:
impapi kernel32,\
    GetFirmwareEnvironmentVariableA, 'GetFirmwareEnvironmentVariableA'

implib msvcrt,'msvcrt.dll'
impapi msvcrt,\
    printf, 'printf',\
    scanf, 'scanf'    
Post 20 Aug 2018, 19:14
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6999
Location: Kraków, Poland
Jin X wrote:
Maybe Tomasz can make some macros that will help to add new functions and new dlls?
See my post above.
Post 20 Aug 2018, 19:38
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
Tomasz, great, thanks!
But how can I add new library using macros like this?
E.g. printf from msvcrt.

p.s. Please add these macros to fasm 1 includes.
Post 21 Aug 2018, 09:44
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6999
Location: Kraków, Poland
Jin X wrote:
Tomasz, great, thanks!
But how can I add new library using macros like this?
E.g. printf from msvcrt.

p.s. Please add these macros to fasm 1 includes.
OK, here's a version with "slibrary" added:
Code:
macro simport library_label*,label*,string
{
    match ,string \{ define library_label#.collection label,`label \}
    match any, string \{ define library_label#.collection label,string \}
}

macro import library_label*,list&
{
    common
        local all
        define all
        irpv a ,library_label#.collection \{ all equ all , a \}
        match a, list \{ all equ , list all \}
        match complete, all \{ import library_label complete \}
}

macro slibrary library_label*,string
{
    match ,string \{ define import_library library_label,`library_label#'.DLL' \}
    match any, string \{ define import_library library_label,string \}
}

macro library list&
{
    common
        local all
        define all
        irpv a, import_library \{ all equ all , a \}
        match complete, list all \{ library complete \}
        irpv a, import_library \{ match library_label=,string, a \\{ import library_label \\} \}
}    
Use it like:
Code:
        slibrary msvcrt
        simport msvcrt,sprintf    
This was quickly patched-up, I may need to look at it a few times more before I consider including it in the official package.
Post 21 Aug 2018, 21:32
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
Thanks a lot !!!
Post 24 Aug 2018, 05:28
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
So, if we define simport as:
Code:
macro   simport library_label*, [label*, string]    
we'll import many functions by one macro calll:
Code:
simport msvcrt, printf,, getch,'_getch', scanf    
Smile


Last edited by Jin X on 24 Aug 2018, 06:03; edited 2 times in total
Post 24 Aug 2018, 05:59
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
Can we convert a string to uppercase to generate 'MSVCRT.DLL' string (instead of 'msvcrt.DLL') on slibrary msvcrt call?
Post 24 Aug 2018, 06:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
Jin X wrote:
Can we convert a string to uppercase to generate 'MSVCRT.DLL' string (instead of 'msvcrt.DLL') on slibrary msvcrt call?
Looking at the macro it appears as though you can do this:
Code:
slibrary msvcrt,'MSVCRT.DLL'    
Post 24 Aug 2018, 06:42
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 54
Location: Russia
revolution wrote:
Looking at the macro it appears as though you can do this:
Code:
slibrary msvcrt,'MSVCRT.DLL'    
I see. But this macros allows to omit dll name string. Therefore I thought that it would be great if dll name string converted to upper case automatically. Yeah we can use library MSVCRT (upper case name id) as a variant.
Post 24 Aug 2018, 07:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
Jin X wrote:
Therefore I thought that it would be great if dll name string converted to upper case automatically.
You can do this by iterating through each byte of the string, but you need to modify the macro that instantiates the string. That is in that other files that come with the fasm download.
Post 24 Aug 2018, 07:14
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-2018, Tomasz Grysztar.

Powered by rwasa.