flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
duanebonas6822 26 Sep 2025, 16:54
Just for anyone that might read, im just looking at macros, can anyone just confirm, do the C header files syntax like ( [ { . -equal the same as- FASM macro ( [ { . , Like do they do the same thing, Just differant syntax and differant languages sometimes do other stuff, And also do things like double quotes and quotes inside quotes work the same and as well the \ extended type syntax, Just if im gonna try macros i need to know the syntax match lol
|
|||
![]() |
|
duanebonas6822 26 Sep 2025, 17:22
Just reading on some forum there saying:
This code is not converted to assembly because it is a function-like macro: #define MAX(x,y) (x>y ? x : y) ?? So how am i meant to define these header equivalents in FASM, That means things like above. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #define NCCHANNEL_INITIALIZER(r, g, b) \ (((uint32_t)r << 16u) + ((uint32_t)g << 8u) + (b) + NC_BGDEFAULT_MASK) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Are Function based, so how am i ment to define options like this, Does anybody know about this ?? Thanks And if FASM doesnt use preprocessor based stuff, these macros have no meaning, says, causes nothing else but a simple textual replacement within your code, Does this mean that all libraries with C headers like the function based macros wont work, somebody must have few answers, ill check back tomorrow. ok |
|||
![]() |
|
bitRAKE 26 Sep 2025, 23:18
C preprocessor macros are just textual replacements, but can result in compile-time and/or run-time code. This can make conversion rather complex!
Assemble macros do textual replacement, but they don't do code generation. We can look at an example to make this more concrete (using fasmg/fasm2 syntax): Code: #define NCCHANNEL_INITIALIZER(r, g, b) \ (((uint32_t)r << 16u) + ((uint32_t)g << 8u) + (b) + NC_BGDEFAULT_MASK) Code: macro NCCHANNEL_INITIALIZER dst, r, g, b mov dst, ( (r shl 16) + (g shl 8) + (b) + NC_BGDEFAULT_MASK ) end macro ![]() Code: ; assuming memory locations and 32-bit register destination macro NCCHANNEL_INITIALIZER dst, r, g, b movzx dst, byte r shl dst, 16 ; reg8hi.dst and reg8lo.dst are helper equates defined elsewhere mov reg8hi.dst, byte g mov reg8lo.dst, byte b or dst, NC_BGDEFAULT_MASK end macro |
|||
![]() |
|
duanebonas6822 27 Sep 2025, 17:53
Thanks for reply, ive tested few examples and seem to be working already, just 1 last thing do u know how i can define these about the last example i need for making boxes:
#define NCBOXDOUBLEW L"╔╗╚╝═║" #define NCPLANE_OPTION_VSCROLL 0x0020ull ; (tryed full 16 digits but didnt work still) which the L just means Wide char but i defoe need these symbols or cannot draw to screen, cheers |
|||
![]() |
|
bitRAKE 27 Sep 2025, 18:19
Typically, in assembly, we would just put the constant data somewhere and reference the label:
Code: NCBOXDOUBLEW du "╔╗╚╝═║" assert $ - NCBOXDOUBLEW = 6*2 ; confirm UCS-2, single word characters ... movzx eax, word [NCBOXDOUBLEW + eax*2] ; translate from index[0-5] to box character fasm[g|2] uses "du" to output wide characters (UTF-16 word sequences) from the byte string in the code. (Requires "include 'encoding/utf8.inc'", or other encodings of source code supported as well. Take a look at the type implementation - I've learned so much from reading the code of fasm?.) _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. |
|||
![]() |
|
duanebonas6822 28 Sep 2025, 11:22
fixed deleted
Last edited by duanebonas6822 on 28 Sep 2025, 16:47; edited 1 time in total |
|||
![]() |
|
duanebonas6822 28 Sep 2025, 14:17
Mate just 1 more question i have successfully converted most of my stuff with:
But the below wont work NCSTYLE_MASK du "0xffffu" Im defining as this tho without the u: NCSTYLE_MASK du "0xffff" Only works with NCSTYLE_MASK dw "0xffff" Doesnt the (u) at end mean its 0xffffu is an unsigned hexadecimal number that would typically be defined using DW (Define Word) for a 16-bit value Do you know why its not working with dw, as i need word ??? Cheers mate UPDATE, Says on google: DW (Define Word): Allocates space for and defines a 16-bit word of data is also a word so how is dw correct if So what is the correct 0x hex size for ull unsigned long long NCOPTION_INHIBIT_SETLOCALE du "0x0001" ; (UINT64 = 0x0000000000000001) + (UINT32 = 0x00000001) So is the above incorrect for unsigned long long Confusing a bit |
|||
![]() |
|
duanebonas6822 28 Sep 2025, 15:02
fixed deleted
Last edited by duanebonas6822 on 28 Sep 2025, 16:46; edited 1 time in total |
|||
![]() |
|
duanebonas6822 28 Sep 2025, 16:22
fixed deleted
Last edited by duanebonas6822 on 28 Sep 2025, 16:46; edited 1 time in total |
|||
![]() |
|
duanebonas6822 28 Sep 2025, 16:45
OMG , Ive figured it out its OK. I knew it was summet simple
NCALPHA_HIGHCONTRAST dq 0x0000000000000001 <<-- (WORKS) NCALPHA_HIGHCONTRAST dq "0x0000000000000001" <<-- (FAILS) Why is the "" brackets only for dw du type words and no " " for 0x when used as ints. I shudda knew this and it doesnt work outside of data section when using dq but does when using du/dw. WEIRD. SORTED - SORTED -SORTED |
|||
![]() |
|
bitRAKE 28 Sep 2025, 19:37
Only use quotes when you need the string of bytes in the source code - all numerical values should be used directly. (EVAL is kind of a special case because a string of bytes is presented to the assembler for processing.)
Quotes work with the data directives when the string of bytes can be translated into that data type: Code: mov eax, 'FAIL' jz @F mov eax, 'pass' @@: stosd Code: dq "01234567" Code: db "▰▱" ; utf-8, six bytes du "▰▱" ; utf-16, four bytes macro ▰▱ reg* ; fasm treats all extended bytes as text local temp virtual du "▰▱" ; let the translation take place ; error if we didn't: include 'encoding/utf8.inc' assert $ - $$ = 4 load temp:4 from $$ end virtual mov reg, temp end macro ![]() Generally, you'll want to leave the quotes off where possible. _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.