Sunday, October 28, 2007

I have just spent most of today (sunday) working on my assembly programming assignment..its finished by the way.....lol, I just have to write another version of the code that runs faster. It was just a matrix multiplication code in C that we had to rewrite in MIPS 64 Assembly. The hardest part for me was knowing how to calculate the index in a 2-d array in assembly. I finally figured it out, so check this out:

consider a simple 2-d array a[i][j]. To get the element at this location, we simply use the formula:

(i * max_index_of_i +j)<<3.

We need to shift by 3, because in assembly, we are just stepping through an array, and each element occupies 8 bits.
So this principle is shown in MIPS64 assembly code to reference p[i][k] in a 3x3 array.

daddi $t7, $r0, 3 ; $t7=3

dmul $t6, $t0, $t7 ; $t6=i*3

dadd $t6 , $t6, $t2 ; i*3 +k


dsll $t4, $t6, 3 ; $t4=(i*3+k)<<3 multiply by 3

daddi $t8, $r0, p ; get base address of p

dadd $t8, $t8,$t4 ; $t8 has the address of p[i][k]

lw $t9, 0($t8) ; $t9 has the value of p[i][k]

Now I am getting back to debugging. See you later!

Wednesday, October 24, 2007

We finally finished the first assignment of the compiler construction project, which was to make the reference compiler recognize records. We were able to compile the test file, record.ast, and it generated the right c-code. Today, we simply ported the code from the old compiler to the new one. The new one had some new assert statements, to check if the right subtype was being used, and all, but it didn't take so long.
We now began the testing phase. We have this Java applet called diagnostix which is able to evaluate the quality of our test suite, and it showed us that our test cases detected 3/5 bugs the compiler should guard against...not bad for our first day of testing, and we are way ahead of schedule.
An interesting case we had was checking that a record name could not be used as a variable name, and also checking that it is illegal in our compiler to check for equality of two records.
Later, thats all for today.

Thursday, October 18, 2007

Compiler construction

I am currently working on the compiler construction course with my greek partner, and its one of the baddest courses in my msc program. We basically have a reference compiler written in C, called asterix, and we are meant to make the compiler recognize record structures. The code generation part has to generate c-structs for the records. For the second assignment, we are meant to change the entire back end code generator from producing C code to assembly.
So far so good, things are alright, we were able to compile a simple record program, and our compiler was able to generate C structs, which was a relief.
Now we need to implement the dot (.) operator so that it is possible to do stuff like this:

record foo is
begin
a:int;
end

Now, our extended compiler should be able to handle statements like

f:foo /*record declaration */

f.a:=2.

But unfortunately, we still get a segmentation fault, which we might tackle tomorrow.
Well more news later, and Im still thesis hunting.