Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / General Discussion

Ideas for internal macros

A community discussion post from the original code:zIRON forum.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

Ideas for internal macros

So far Ziron has some internal macros such as $substr, $strindex etc.... does anyone have ideas or requests for additional macro functions?

Replies

0CodErr member
Posts
201
Threads
37
Location
Unknown

Builtin functions -- are useful things :)

I think that would be good to have converting functions like $int2str, $uint2str, $hex2str, $bin2str, etc...

Also think that would be useable add integer logarithm base 2 function. Currently we can do:

const BIT_CONST = 1 << 6;
test eax, MY_CONST3;
jnz bit_set;

We will able to do like:

bt eax, $log2(MY_CONST3)
jc bit_set
0CodErr member
Posts
201
Threads
37
Location
Unknown

Maybe would be useable to have directive which set default type of value in registers i.e. signed|unsigned.

Then can be written:

if (eax => ebx){}
while (ax < bx){}

instead of

if ([int32]eax => ebx){}
while ([int16]ax < bx){}

it will make code more readable.

Colin admin
Posts
928
Threads
49
Location
Bulgaria
Maybe would be useable to have directive which set default type of value in registers i.e. signed|unsigned

This actually was supposed to work, but I think i broke it in some earlier release.

eax as int32;

//etc...

I will correct this.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

Fixed continuous casting:

eax = -5 as int32;

if (eax < 1) {
	eax = 512;
}

eax as dword;
if (eax < 1) {
	eax = 512;
}

as for $str2int etc, these can be written as direct macros, when i rewrite RTL i will include a macro include file for system macros, if you have ideas for more or have any you would like to submit, let me know.

$int2str = inline function ($i) {
	$return tokentext($i);
}

$str2int = inline function ($i) {
	$return $_e($i);
}
0CodErr member
Posts
201
Threads
37
Location
Unknown

Above I asked you about integer logarithm base 2 function

Is it possible to add this builtin macro?

Colin admin
Posts
928
Threads
49
Location
Bulgaria

I will add log2 but as you know it is usually a floating point result, I will instead improve a few things in the macro system and then write a macro based version of log2. I will get back to you soon.

Edit: Actually I implemented log2 and log2i for next release, but I will still improve macro system anyways :)

0CodErr member
Posts
201
Threads
37
Location
Unknown

Seems log2i is not works.

program RAW_IMAGE 'test';

#set bits 32;

const i00 = 1 << 0;
const i01 = 1 << 1;
const i02 = 1 << 2;
const i03 = 1 << 3;
const i04 = 1 << 4;
const i05 = 1 << 5;
const i06 = 1 << 6;
const i07 = 1 << 7;
const i08 = 1 << 8;
const i09 = 1 << 9;
const i10 = 1 << 10;
const i11 = 1 << 11;
const i12 = 1 << 12;
const i13 = 1 << 13;
const i14 = 1 << 14;
const i15 = 1 << 15;
const i16 = 1 << 16;

$echof 'log2i(', i00, ') = ', $log2i(i00);
$echof 'log2i(', i01, ') = ', $log2i(i01);
$echof 'log2i(', i02, ') = ', $log2i(i02);
$echof 'log2i(', i03, ') = ', $log2i(i03);
$echof 'log2i(', i04, ') = ', $log2i(i04);
$echof 'log2i(', i05, ') = ', $log2i(i05);
$echof 'log2i(', i06, ') = ', $log2i(i06);
$echof 'log2i(', i07, ') = ', $log2i(i07);
$echof 'log2i(', i08, ') = ', $log2i(i08);
$echof 'log2i(', i09, ') = ', $log2i(i09);
$echof 'log2i(', i10, ') = ', $log2i(i10);
$echof 'log2i(', i11, ') = ', $log2i(i11);
$echof 'log2i(', i12, ') = ', $log2i(i12);
$echof 'log2i(', i13, ') = ', $log2i(i13);
$echof 'log2i(', i14, ') = ', $log2i(i14);
$echof 'log2i(', i15, ') = ', $log2i(i15);
$echof 'log2i(', i16, ') = ', $log2i(i16);
$echo received invalid parameters!
program RAW_IMAGE 'test';

#set bits 32;

const i00 = 1 << 0;
const i01 = 1 << 1;
const i02 = 1 << 2;
const i03 = 1 << 3;
const i04 = 1 << 4;
const i05 = 1 << 5;
const i06 = 1 << 6;
const i07 = 1 << 7;
const i08 = 1 << 8;
const i09 = 1 << 9;
const i10 = 1 << 10;
const i11 = 1 << 11;
const i12 = 1 << 12;
const i13 = 1 << 13;
const i14 = 1 << 14;
const i15 = 1 << 15;
const i16 = 1 << 16;

dword d00 = $log2i(i00);
dword d01 = $log2i(i01);
dword d02 = $log2i(i02);
dword d03 = $log2i(i03);
dword d04 = $log2i(i04);
dword d05 = $log2i(i05);
dword d06 = $log2i(i06);
dword d07 = $log2i(i07);
dword d08 = $log2i(i08);
dword d09 = $log2i(i09);
dword d10 = $log2i(i10);
dword d11 = $log2i(i11);
dword d12 = $log2i(i12);
dword d13 = $log2i(i13);
dword d14 = $log2i(i14);
dword d15 = $log2i(i15);
dword d16 = $log2i(i16);
Unexpected EOF