Daily Archive for July 21st, 2010

HL-ZASM

Sorry for no updates, but updates are not supposed to be at regular intervals in summer anyway.

HL-ZASM is a new project for Wiremod. It’s part of one massive ZCPU update I want to carry out, it’s a new compiler that will replace the ZASM.

HL in HL-ZASM stands for “high level”, and it adds support for most of C language features – you can write C code, and mix it with ZASM code without problems. It will compile all the complex expressions, function and variable definitions, various loops and stuff like that.

For example, it can compile the following code:

int test\n"..
void function(int a, int b) {"..
  int lvar\n"..
  lvar = a*(test+b*(100+lvar+a+b));\n"..
  lvar = lvar + 1;\n"..
  lvar = test-lvar*(-a);\n"..
  lvar = function+15;\n"..
}

And then this is how generated output looks like this:

test:
     0 alloc 1
// function(a,b)
function:
     1 enter 1
// lvar = a*(test+b*(100+lvar+a+b))
     4 rstack EAX,EBP:-2
     8 rstack EBX,EBP:-1
    12 add EBX,EAX
    14 rstack EAX,EBP:1
    18 add EAX,EBX
    20 add EAX,100
    23 rstack EBX,EBP:-2
    27 mul EBX,EAX
    29 mov EAX,#0
    32 add EAX,EBX
    34 rstack EBX,EBP:-1
    38 mul EBX,EAX
    40 sstack EBP:1,EBX
// lvar = lvar + 1
    44 rstack EAX,EBP:1
    48 add EAX,1
    51 sstack EBP:1,EAX
// lvar = test-lvar*(-a)
    55 rstack EAX,EBP:-1
    59 neg EAX
    61 rstack EBX,EBP:1
    65 mul EBX,EAX
    67 mov EAX,#0
    70 sub EAX,EBX
    72 sstack EBP:1,EAX
// lvar = function+15
    76 sstack EBP:1,16
    81 leave
    82 ret

Most of the compiler is based on the HybriC project – in fact all of it, but I found many flaws in the original HybriC architecture, which I will fix later.