flat assembler
Message board for the users of flat assembler.
Index
> Main > [solved] Massive HEX to Data Section |
Author |
|
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 |
|||
21 Jul 2020, 04:32 |
|
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 |
|||
21 Jul 2020, 04:33 |
|
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 |
|||
21 Jul 2020, 04:44 |
|
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? |
|||
21 Jul 2020, 05:05 |
|
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. |
|||
21 Jul 2020, 05:10 |
|
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 |
|||
21 Jul 2020, 05:20 |
|
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.
|
|||
21 Jul 2020, 05:24 |
|
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
|
|||
21 Jul 2020, 05:29 |
|
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" |
|||
21 Jul 2020, 05:30 |
|
Overclick 21 Jul 2020, 05:56
Seems it works thanks
|
||||||||||
21 Jul 2020, 05:56 |
|
Overclick 21 Jul 2020, 07:19
little upgrade for your macro
Code: ..hash:: db `hash Allows it to use without quotes |
|||
21 Jul 2020, 07:19 |
|
revolution 21 Jul 2020, 08:25
Also, if it is "too slow" you could replace the /2 with shr 1.
|
|||
21 Jul 2020, 08:25 |
|
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. |
|||
21 Jul 2020, 09:53 |
|
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. |
|||
21 Jul 2020, 10:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.