flat assembler
Message board for the users of flat assembler.
Index
> Main > switching from NASM to FASM Goto page Previous 1, 2 |
Author |
|
Tomasz Grysztar 16 Oct 2014, 13:29
str8c wrote: Thanks for that, although I am still a bit confused on how you can use the value of 'len' before it has been set (it seems to be treated like a label, while the other variables are not). str8c wrote:
It's quite straightforward and transparent - the preprocessor does not need to know whether the starting characters of label have any special meaning to the assembler which processes them later, it just blindly reproduces them. If fasm's assembly language introduces some new class of labels, started with "@" or "!", or some other character, the behavior of fasm's preprocessor is still going to be adequate and predictable. But I do agree that dots are sometimes ugly, it does bother me a bit from time to time. In a simple case like this one you may try to do something about it with an additional macro, like: Code: macro .local [name] { local .name define name .name } macro str [string] { common .local asDst,dst local pos, len, a, esc, val asDst:: dst rb len virtual at 0 db string pos = 0 esc = 0 repeat $ load a byte from %-1 if a >= '0' & a <= '7' if esc > 0 if esc < 4 esc = esc + 1 val = val * 8 + a - '0' else esc = 0 store byte val at asDst:dst+pos store byte a at asDst:dst+pos+1 pos = pos + 2 end if else store byte a at asDst:dst+pos pos = pos + 1 end if else if a = '\' if esc > 0 store byte '\' at asDst:dst+pos pos = pos + 1 esc = 0 else esc = 1 val = 0 end if else if esc > 0 esc = 0 store byte val at asDst:dst+pos pos = pos + 1 end if store byte a at asDst:dst+pos pos = pos + 1 end if end if end repeat if esc > 1 store byte val at asDst:dst+pos pos = pos + 1 end if len = pos end virtual } |
|||
16 Oct 2014, 13:29 |
|
str8c 16 Oct 2014, 14:08
Tomasz Grysztar wrote: The macro itself may contain the complete "ecosystem" of labels. For instance, you can take some piece of code (containing both global and local labels) and wrap it up in a macro. To make it re-usable you then need only to insert a "local" directive with the names of global labels to make them unique every time the macro is called. It may require more work to implement, but this behaviour would be preserved if "local" meant that the label (and its sub labels) should only have an effect on the current label inside the macro, even when it is "global" level label. Tomasz Grysztar wrote:
I like this, but is there a nice way to prevent it from contaminating the name space? I can only think of something like this, which isn't very nice (something with fixes maybe?): Code: local asDst, dst .local asDst, dst |
|||
16 Oct 2014, 14:08 |
|
Tomasz Grysztar 16 Oct 2014, 16:55
str8c wrote:
Code: macro .with [name] { common irpv previous,.with \{ restore previous restore .with \} forward local .name match any,name \{ define name .name define .with name \} } macro str [string] { common local pos, len, a, esc, val .with asDst,dst asDst:: dst rb len virtual at 0 db string pos = 0 esc = 0 repeat $ load a byte from %-1 if a >= '0' & a <= '7' if esc > 0 if esc < 4 esc = esc + 1 val = val * 8 + a - '0' else esc = 0 store byte val at asDst:dst+pos store byte a at asDst:dst+pos+1 pos = pos + 2 end if else store byte a at asDst:dst+pos pos = pos + 1 end if else if a = '\' if esc > 0 store byte '\' at asDst:dst+pos pos = pos + 1 esc = 0 else esc = 1 val = 0 end if else if esc > 0 esc = 0 store byte val at asDst:dst+pos pos = pos + 1 end if store byte a at asDst:dst+pos pos = pos + 1 end if end if end repeat if esc > 1 store byte val at asDst:dst+pos pos = pos + 1 end if len = pos end virtual .with } |
|||
16 Oct 2014, 16:55 |
|
Tomasz Grysztar 16 Oct 2014, 17:00
revolution wrote: One extra function that I occasionally find missing (and perhaps inline macros could provide) is string manipulation for label names. For example: stripping a leading character is something I've never been able to do. Perhaps my knowledge is just lacking but it appears that it can't be done. We have the concatenate operator (#) but no equivalent extractor operator. |
|||
16 Oct 2014, 17:00 |
|
revolution 16 Oct 2014, 17:26
Tomasz Grysztar wrote: ... would probably require some very cryptic syntax (even for fasm's standards). |
|||
16 Oct 2014, 17:26 |
|
tthsqe 16 Oct 2014, 20:13
I think this thread is hitting on something I was trying to do earlier. If I am understanding correctly this is not possible with fasm's current syntax?
Code: macro log2(a) { local result=-1 while a result=result+1 a = a shr 1 end while return result } and then use it like mov eax,dword[index] shl rax,log2(sizeof.MYSTRUCT) ; assume sizeof.MYSTRUCT is a power of 2 add rax,qword[ArrayOfStructs] |
|||
16 Oct 2014, 20:13 |
|
JohnFound 16 Oct 2014, 20:47
tthsqe, no, this is not FASM syntax and will not be compiled at all. There is no "inline macros" in FASM.
But, as explained in the above posts, the same problem can be solved with another code. More FASM-style. Read the whole thread for details. |
|||
16 Oct 2014, 20:47 |
|
cod3b453 17 Oct 2014, 09:08
I've been using the attached macros by baldr to do single inline macros:
Code: @! shl edx,! @log2 (1000) ! Code: struc @imm8 [x] { local c local y common c = 0 forward c = c + 1 common c = 8 / c y = 0 forward y = (y shl c) or x common . equ y } @! pshuflw xmm4,xmm2,! @imm8 2,0,1,3 !
|
|||||||||||
17 Oct 2014, 09:08 |
|
l_inc 17 Oct 2014, 14:23
Tomasz Grysztar
Quote: Much more useful would be some extended variant of MATCH (MATCHX?) that would be able to cut through the tokens I've been going to suggest you to reuse numbers for the pattern argument of the match directive (instead of introducing a new matchx), and to defend the resulting insignificant compatibility break with a similar break introduced by the rept computation capability, but then I came across a little inconsistency in the rept computation processor: Quote: define 2 3 This code displays "2", but it's displayed only once, even though the same symbol x is used. I'm sure, I've already came across this inconsistency when this topic appeared, but I failed to reproduce the problem afterwards. We can have even more fun with that: Code: define 3 2define 4 3define 6 4define 5 6define y 4define x yrept x n : x { display '0'+n,13,10 } The output "3 6 4 7" makes me think that the redefinitions affect not only the way the initial value of n is calculated, but also the very incrementation process. _________________ Faith is a superposition of knowledge and fallacy |
|||
17 Oct 2014, 14:23 |
|
Tomasz Grysztar 17 Oct 2014, 15:43
l_inc wrote: I'm sure, I've already came across this inconsistency when this topic appeared, but I failed to reproduce the problem afterwards. section 2.3.5 wrote: (...) each value used in such expression must either be a directly specified number, or a symbolic constant with value also being an expression that can be calculated by preprocessor (...) l_inc wrote: The output "3 6 4 7" makes me think that the redefinitions affect not only the way the initial value of n is calculated, but also the very incrementation process. Code: define 3 2 define 4 3 define 6 4 define 5 6 define y 4 define x y rept x n : x { display `n,' evaluates to ','0'+n,13,10 } |
|||
17 Oct 2014, 15:43 |
|
l_inc 17 Oct 2014, 16:09
Tomasz Grysztar
Oh, I'm sorry. You're right. I've missed again, that the symbols are expanded once more. It's a kind of a situation, when I'm facing the same problem multiple times and can resolve it only a subset of those times. _________________ Faith is a superposition of knowledge and fallacy |
|||
17 Oct 2014, 16:09 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.