Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Bugs and Fixes

Wrong opcodes

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

Replies

0CodErr member
Posts
201
Threads
37
Location
Unknown

This is for testing http://pastebin.com/W7Txw8ap

It contains commented part / /, because it cannot be compiled

Operand size mismatch! Code: bt ax, imm

And also something wrong with test

test eax,0xc3f70012

instead of

 test ax

Also (this was not included in file above):

sbb ax, 0x1234

Result:

00000000  6683D834          sbb ax,byte +0x34

I reported only about some errors. Also there are similar errors. And better if you check all output.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

I have rewrote test and bt(s/r) instruction handlers and solved both of those issues, I will take a look at sbb tomorrow.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

My mistake, I missed a 16 bit check on one of the functions I rewrote. Thanks for fast report, it will be updated on next beta or release.

I have also fixed sbb, it was a problem with word based values being sometimes truncated into bytes.

0CodErr member
Posts
201
Threads
37
Location
Unknown
# Registers support very basic assignment expressions using + and - e.g. eax = edx + ecx - ebx;
program RAW_IMAGE 'test';

#set bits 32;

eax = dl + dh + dx;

Result:

00000000  0FB6C2            movzx eax,dl
00000003  03C6              add eax,esi
00000005  03C2              add eax,edx

But not every expression such as in your example so very basic.

And support such expressions can make parsing and code generation more complex.

I suggest to support only expressions which can be directly translated.

For example not so clear how translate this:

eax = ~ebx + ~ecx

even this

eax = ebx + eax

because not clear which value of eax we will add? Which was before calculations or after

eax = ebx

?

But as for simple expressions that really good thing :)

for example:

eax = ebx | ecx
eax = ebx & ecx
eax = ebx ^ ecx
eax = ebx >> cl
eax = edx << cl
eax = ebx - ecx
eax = ebx + ecx
Colin admin
Posts
928
Threads
49
Location
Bulgaria

Yes I plan to only have very basic assignment expressions because of inefficient code generation without loss of registers.

Assignment expressions work from left to right.

so eax = eax + ebx + ecx - esi will go from left to right

eax = eax;
add eax, ebx
add eax, ecx
sub eax, esi

as for

eax = dl + dh + dx;

I have added the appropriate error message. Thanks.

0CodErr member
Posts
201
Threads
37
Location
Unknown

Ok, how it would be in my example above?

eax = ebx + eax

This way:

mov eax, ebx
add eax, eax

And now compare some high level example:

a = b + a

Here in result 'a' really will be as sum of 'a + b'

While in our registers expression we get that 'eax' will be 'ebx * 2' but not 'ebx + eax'

Assignment expressions work from left to right.

What about operator precedence? As I know in constant expressions it does matter. And it may cause conflict with constant expressions and reg|mem expressions.

Yet example:

eax = ebx & ecx + edi - ebp | edx ^ esi
eax = -~-~ebx

Maybe better need to completely define in documentation which expressions are 'simple'. And if expression not simple then we just say 'error: expression too complex'