flat assembler
Message board for the users of flat assembler.

Index > Main > [solved] Massive HEX to Data Section

Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 21 Jul 2020, 03:50
Hi
I have some HEX data to be included into program. How to do this?
It looks like this:
Code:
2353657474696E67730D0A0923566F6C
756D650D0A09094576616C3A20464C65
76656C3D...    

"db" needs to be separated by comma for each byte. That means:
Code:
   db    23h,53h,65h,74h,74h,69h,6Eh,67h,73h,0Dh,0Ah,09h,23h,56h,6Fh,6Ch
   ...
    

Is there any advice to do that much quickly?[/code]
Post 21 Jul 2020, 03:50
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 21 Jul 2020, 04:32
In fasmg:
Code:
macro T H*
        eval "dbx (lengthof `H)/2:0x",`H
end macro

T 2353657474696E67730D0A0923566F6C
T 756D650D0A09094576616C3A20464C65
T 76656C3D    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup


Last edited by bitRAKE on 21 Jul 2020, 04:37; edited 1 time in total
Post 21 Jul 2020, 04:32
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 21 Jul 2020, 04:33
How is your data stored? In the source file, or on a separate file?
Code:
virtual at 0
  file "my_hex_data.hex"
 my_data::
  ;do your ASCII to binary decoding here
  while ...
    ;..
  end while
end virtual    
Or use a good editor or parser (awk, sed, etc.) to pre-process it and generate the DBs
Post 21 Jul 2020, 04:33
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 21 Jul 2020, 04:44
I should have said the macro assumes big endian. Using BWAP we can produce little endian - which is more common.
Code:
macro t H*
        B = (lengthof `H)/2
        eval "dbx B:0x",`H," bswap B"
end macro

t 2353657474696E67730D0A0923566F6C
t 756D650D0A09094576616C3A20464C65
t 76656C3D    
Post 21 Jul 2020, 04:44
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 21 Jul 2020, 05:05
Data is an ASCII file which I want to put into my program as file buffer to write that file later. Some parts of this buffer should be modificated. I convert it to HEX, don't I need that?
Code:
buff_point equ $
                        T 2353657474696E67730D0A0923566F6C
                        T 756D650D0A09094576616C3A20464C65
                        T 76656C3D
value_point equ $
                        T ...
                        T ...
buff_end equ $
                        db 0 
    

I don't use fasmg as I don't know enough about it. There is no IDE editor for example.
Is any chance to make fasm macro with the same functionality?
Post 21 Jul 2020, 05:05
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 21 Jul 2020, 05:10
Unrelated but important. Use equals =, not equ. equ is textual replacement so it always expands to current address where it is used, not the address where it was defined.
Overclick wrote:
I don't use fasmg as I don't know enough about it. There is no IDE editor for example.
Is any chance to make fasm macro with the same functionality?
See my post above.
Post 21 Jul 2020, 05:10
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 21 Jul 2020, 05:20
revolution wrote:
Unrelated but important. Use equals =

Got it, thanks
About your post: You mean to copy-paste some huge massives of data or inklude files, but I was looking for some simple way, short one, to see and quickly edit HEX too. Macro above is an ideal way for me, just help me with that macro for fasm
Post 21 Jul 2020, 05:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 21 Jul 2020, 05:24
file will include the raw hex for you. No need to copy/paste. That is why I asked how your data was stored.
Post 21 Jul 2020, 05:24
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 21 Jul 2020, 05:29
I need to set up 100+ value points on it. In this way I need to use "file" 100+ times separatelly
Post 21 Jul 2020, 05:29
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 21 Jul 2020, 05:30
Not sure if this will work. Try it;
Code:
macro byteify hash {
        local   ..hash,..length
        virtual at 0
            ..hash:: db hash
            ..length = $/2
        end virtual
        while % <= ..length
                load b_1 byte from ..hash:(%-1)*2
                load b_2 byte from ..hash:(%-1)*2+1
                if b_1 > '9'
                        b_1 = b_1 - 'A' + 10
                else
                        b_1 = b_1 - '0'
                end if
                if b_2 > '9'
                        b_2 = b_2 - 'A' + 10
                else
                        b_2 = b_2 - '0'
                end if
                db b_1 shl 4 + b_2
        end while
}
byteify "2353657474696E67730D0A0923566F6C"    
But that doesn't use file so it would need copy/paste.
Post 21 Jul 2020, 05:30
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 21 Jul 2020, 05:56
Seems it works thanks


Description:
Filesize: 16.7 KB
Viewed: 10230 Time(s)

Capture.PNG


Post 21 Jul 2020, 05:56
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 21 Jul 2020, 07:19
little upgrade for your macro
Code:
..hash:: db `hash     

Allows it to use without quotes
Post 21 Jul 2020, 07:19
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 21 Jul 2020, 08:25
Also, if it is "too slow" you could replace the /2 with shr 1.
Post 21 Jul 2020, 08:25
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 21 Jul 2020, 09:53
Why fasm doesn't allow to use # to stick numeric value? Is there any another trick/macro to make it possible? I understand assembler doesn't sure what exactly value should be, but it can make some memory space where programmer could stick it for own riscs. Am I right?
For example: I have defined names as ID100, ID101 etc. I wish to stic ID with number to reach it, simple, why not? Also I understand variable names needed just for assembling/coding, but what if I save this names in memory by myself? Ok, it's different situation then let's see your macro. It simply works with decimal values but heximal where it needs just one mark "h" to go.
Post 21 Jul 2020, 09:53
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 21 Jul 2020, 10:05
String manipulation in macros is tricky. It can be done, but it is usually more trouble than alternatives.

Show your use case, perhaps there is a better way.
Post 21 Jul 2020, 10:05
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.