Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Requests and Feedback

Augmented assignment

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

0CodErr member
Posts
201
Threads
37
Location
Unknown

Augmented assignment

Currently supported:

eax += ebx;
eax -= ebx;
eax++;
eax--;
eax >> 0; eax << 1; eax >> 2; // ... etc

And yet not supported:

eax << cl;
eax &= ebx;
eax |= ebx;
eax ^= ebx;
~eax; 
-eax;

Also pay attention that in const expression someone could write:

const MY_CONST = -~0x12345678;

or

const MY_CONST = ~-0x12345678;

or even

const MY_CONST = -~-~-~-~0x12345678;

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

I am avoiding to add the ability to write complex expressions to keep the simple assembly readability. But I will consider to add some of these. such as eax != ... etc.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

OK, i have implemented the following:

  eax != ecx;  // mov eax, ecx; not eax
  eax != eax;  // not eax
  eax &= ecx;  // and eax, ecx
  eax ^= ecx;  // xor eax, ecx
  eax |= edx;  // or eax, edx

They will be available on todays release.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

I never planned for Ziron to resemble C, but I am happy to add ~ as an additional not operator.

0CodErr member
Posts
201
Threads
37
Location
Unknown

Why we should pay attention to this?

You write

eax != ecx;  // mov eax, ecx; not eax

This is something more complicated than others.

In the first post I suggested the

-eax

it's like

neg eax

.

If we do like

eax != ecx

then we get

eax -= ecx

.

But we already have "-=" operator. If we do make an exception for this then our language will be less orthogonal than it could be.

If we want to use more complicated expressions then i think we also should use something like this:

eax = ebc | ecx // mov eax, ebx // or eax, ecx
Colin admin
Posts
928
Threads
49
Location
Bulgaria

!= is for not equal.

eax != eax is eax = not eax

eax != ecx is eax = not ecx

Maybe I misunderstand your question.

program PE32_CUI 'Sample';

#include 'platform_def.zir';
#include 'console.zir';

ebx = 500;
ecx = 100;

ebx -= ecx;

print('ebx -= ecx: ', ebx, '\r\n');

ebx = 500;
ecx = 100;

ebx != ebx;

print('ebx != ebx: ', ebx, '\r\n');

ebx = 500;
ecx = 100;

ebx != ecx;

print('ebx != ecx: ', ebx, '\r\n');

wait_key();
ExitProcess(0);

Output:

ebx -= ecx: 400
ebx != ebx: 4294966795
ebx != ecx: 4294967195
Press any key to continue

!= and -= are not the same.

as for -eax, i missed that one, added now for next release.

0CodErr member
Posts
201
Threads
37
Location
Unknown

I mean that if we support more complex expressions then right variant is

eax = !ecx

or

eax = ~ecx

but not

eax != ecx