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

Wrong size used

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

0CodErr member
Posts
201
Threads
37
Location
Unknown

Wrong size used

Used dword but must be byte.

enum MyEnum : byte {val1 = 0, val2, val3};
byte MyByte; eax = @MyByte;
mov [eax], val1;
mov [eax], val2;
mov [eax], val3;

Result:

c70000000000         mov    dword ptr [eax], 00h
      c70001000000         mov    dword ptr [eax], 01h
      c70002000000         mov    dword ptr [eax], 02h

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

with no size prefix, the assembler assumes a pointer type and will convert the right operator, in this case:

byte[eax] = val1;

I will however look at changing this to check against the right operand.

EDIT: I have updated the assembler and this is solved for next release.

0CodErr member
Posts
201
Threads
37
Location
Unknown

I think it a bit relevant to this topic:

procedure Test(qword X) {} Test(0);

Result:

00000000  6A00              push byte +0x0
00000002  E800000000        call dword 0x7
00000007  55                push ebp
00000008  8BEC              mov ebp,esp
0000000A  8BE5              mov esp,ebp
0000000C  5D                pop ebp
0000000D  C20800            ret 0x8

Also in 16 bit mode we get wrong opcodes:

00000000  6A00              push byte +0x0
00000002  E80000558B        call dword 0x8b550007
00000007  EC                in al,dx
00000008  8BE5              mov esp,ebp
0000000A  5D                pop ebp
0000000B  C20800            ret 0x8
0CodErr member
Posts
201
Threads
37
Location
Unknown
Also in 16 bit mode we get wrong opcodes:

Actually result was:

00000000  6A00              push byte +0x0
00000002  E80000            call word 0x5
00000005  55                push bp
00000006  8BEC              mov bp,sp
00000008  8BE5              mov sp,bp
0000000A  5D                pop bp
0000000B  C20800            ret 0x8

In post above result was just because i disassembled it in 32 bit mode.

But anyway :)

0CodErr member
Posts
201
Threads
37
Location
Unknown

Also strange warnings:

program RAW_IMAGE 'test';

#set bits 32;

qword a, b;

a = b;
[7,6]: Warning: [666] b passed as value to stack, consider passing by ref in [te st.zir] [7,6]: Warning: [666] a passed as value to stack, consider passing by ref in [te st.zir]
0CodErr member
Posts
201
Threads
37
Location
Unknown

Also there is value was truncated to 32-bit without any warnings:

program RAW_IMAGE 'test';

#set bits 32;

procedure Test(qword X) {}
Test(0x123456789ABCDEF0);

Result:

00000000  68F0DEBC9A        push dword 0x9abcdef0
00000005  E800000000        call dword 0xa
0000000A  55                push ebp
0000000B  8BEC              mov ebp,esp
0000000D  8BE5              mov esp,ebp
0000000F  5D                pop ebp
00000010  C20800            ret 0x8
                
Colin admin
Posts
928
Threads
49
Location
Bulgaria
Also strange warnings:

This is warning you that 2 dwords are being pushed to the stack. (because: 32-bit mode)

Also there is value was truncated to 32-bit without any warnings

Fixed for next release.