flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > Simple listing macro for fasmg

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6876
Location: Kraków, Poland
With the new VIRTUAL features it becomes very easy to alter the macros so that they write the listing into a separate file:
Code:
Listing? = 1 namespace Listing base = $$ offset = $ virtual at 0 HexDigits:: db '0123456789ABCDEF' end virtual virtual as 'lst' Text:: end virtual end namespace macro ? line& line rmatch =nolist?, line Listing? =: 0 else rmatch =list?, line restore Listing? else if Listing namespace Listing if ~ $$ eq base base = $$ offset = $$ end if bytes = $ - offset if $ - bytes < $$ bytes = $ - $$ end if offset = $ address = (offset scale 0)-bytes virtual Text repeat 8 load digit:byte from HexDigits:((address) shr ((%%-%) shl 2)) and 0Fh db digit end repeat db ': ' end virtual if bytes < 0 bytes = 0 end if while bytes > 0 if bytes > 8 bytes_in_row = 8 else bytes_in_row = bytes end if if $ - bytes + bytes_in_row <= $@ readable_bytes = bytes_in_row else if $ - bytes >= $@ readable_bytes = 0 else readable_bytes = bytes_in_row - ($ - $@) end if load data:readable_bytes from $ - bytes virtual Text repeat readable_bytes load digit:byte from HexDigits:(data shr ((%-1) shl 3 + 4)) and 0Fh db digit load digit:byte from HexDigits:(data shr ((%-1) shl 3)) and 0Fh db digit,' ' end repeat repeat bytes_in_row - readable_bytes db '?? ' end repeat if bytes > bytes_in_row db 13,10,' ' end virtual bytes = bytes - bytes_in_row else end virtual break end if end while virtual Text repeat 8-bytes db ' ' end repeat db `line,13,10 end virtual end namespace end if end rmatch end macro macro nolist? end macro macro list? end macro postpone nolist end postpone
Post 15 Oct 2017, 15:08
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6876
Location: Kraków, Poland
I had to update the above macro, because after I corrected LOAD directive to be more consistent with how it handles uninitialized data (some time ago already) the address-based variant of this macro no longer worked correctly.

The new version now writes "??" when there are an uninitialized bytes.
Post 11 Jul 2018, 14:54
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1603
Location: Ukraine
Thanks! This variant works with new DATA macro for x51, but if there is a way to print listing into the console output (it is more convenient to me). It could be better a separate macro.
Post 11 Jul 2018, 17:18
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6876
Location: Kraków, Poland
shoorick wrote:
Thanks! This variant works with new DATA macro for x51, but if there is a way to print listing into the console output (it is more convenient to me). It could be better a separate macro.
Well, it is enough to remove all that "virtual Text" stuff and replace DB back with DISPLAY:
Code:
Listing? = 1 namespace Listing base = $$ offset = $ virtual at 0 HexDigits:: db '0123456789ABCDEF' end virtual end namespace macro ? line& line rmatch =nolist?, line Listing? =: 0 else rmatch =list?, line restore Listing? else if Listing namespace Listing if ~ $$ eq base base = $$ offset = $$ end if bytes = $ - offset if $ - bytes < $$ bytes = $ - $$ end if offset = $ address = (offset scale 0)-bytes repeat 8 load digit:byte from HexDigits:((address) shr ((%%-%) shl 2)) and 0Fh display digit end repeat display ': ' if bytes < 0 bytes = 0 end if while bytes > 0 if bytes > 8 bytes_in_row = 8 else bytes_in_row = bytes end if if $ - bytes + bytes_in_row <= $@ readable_bytes = bytes_in_row else if $ - bytes >= $@ readable_bytes = 0 else readable_bytes = bytes_in_row - ($ - $@) end if load data:readable_bytes from $ - bytes repeat readable_bytes load digit:byte from HexDigits:(data shr ((%-1) shl 3 + 4)) and 0Fh display digit load digit:byte from HexDigits:(data shr ((%-1) shl 3)) and 0Fh display digit,' ' end repeat repeat bytes_in_row - readable_bytes display '?? ' end repeat if bytes > bytes_in_row display 13,10,' ' bytes = bytes - bytes_in_row else break end if end while repeat 8-bytes display ' ' end repeat display `line,13,10 end namespace end if end rmatch end macro macro nolist? end macro macro list? end macro postpone nolist end postpone


Last edited by Tomasz Grysztar on 11 Jul 2018, 18:18; edited 1 time in total
Post 11 Jul 2018, 17:34
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1603
Location: Ukraine
Very nice! It works! Thanks!

_________________
UNICODE forever!
Post 11 Jul 2018, 18:15
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6876
Location: Kraków, Poland
And here is a new version of the first listing variant, the one that lists file offsets and not addresses, modified to generate .LST file:
Code:
define Listing namespace Listing offset = $%% virtual at 0 HexDigits:: db '0123456789ABCDEF' end virtual virtual as 'lst' Text:: end virtual end namespace macro ? line& line namespace Listing undefined_bytes = $% - $%% defined_bytes = $%% - offset if $ - undefined_bytes - defined_bytes < $$ defined_bytes = $ - undefined_bytes - $$ end if offset = $%% virtual Text repeat 8 load digit:byte from HexDigits:((offset-defined_bytes) shr ((%%-%) shl 2)) and 0Fh db digit end repeat db ': ' end virtual column = 0 source = `line while defined_bytes load data:byte from : $% - undefined_bytes - defined_bytes virtual Text if column = 8 column = 0 db source,13,10,' ' source = '' end if load digit:byte from HexDigits:data shr 4 db digit load digit:byte from HexDigits:data and 0Fh db digit,' ' end virtual defined_bytes = defined_bytes - 1 column = column + 1 end while virtual Text repeat 8-column db ' ' end repeat db source,13,10 end virtual end namespace end macro
Post 14 Jul 2018, 12:48
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1603
Location: Ukraine
why not replace those obsolete macros above to not puzzle new ones who wish to use them? also, it would be better to incorporate such usefull macros directly into the fasmg package as "include" folder (I do this at my PC) to keep them together, ready and up to date! Wink

here is my include folder:
Code:
bin.inc hex.inc @@.inc listing.inc listingx.inc proc.inc shownum.inc struct.inc switch.inc union.inc utf8.inc
- all of them are macros of the similar name


Description:
Download
Filename: include.zip
Filesize: 4.91 KB
Downloaded: 8 Time(s)

Post 14 Jul 2018, 16:58
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6876
Location: Kraków, Poland
shoorick wrote:
why not replace those obsolete macros above to not puzzle new ones who wish to use them? also, it would be better to incorporate such usefull macros directly into the fasmg package as "include" folder (I do this at my PC) to keep them together, ready and up to date! Wink
I guess I considered them a bit too complex for the simple examples that I wanted in the basic package. But the x86 examples grew into a much more complex beasts anyway, adding a few more includes there probably wouldn't hurt. But I'm also going to include some variants of these macros in other examples in the future (including the file format tutorials that I'm starting now). My idea was to have an additional library of examples, leaving the basic package with just a couple for demonstration.
Post 14 Jul 2018, 17:51
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:  
Goto page Previous  1, 2

< 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 © 2004-2018, Tomasz Grysztar.

Powered by rwasa.