Saturday, 12 January 2013

Day 12 : Reference Implementation

Today, I 'ave been mostly .... writing the 'C' reference implementation.

This isn't an actual working emulator version - none of the system calls or the hardware will be there, it's a working emulation core.  That's about 90% done. L8R: Finished it.

Once I've done that, I'll write reference program which runs code and checks it actually works, using a system call #255 (which won't normally exist) as a sort of assert-false. This I can then run on the CP1610 based interpreter and any others to check they actually work.

The assert code will be something like this.

     mov r0,#-1    ; put $FF in R0 (e.g. system call 255, $FF)
. (later on - this code checks the indexed indirection and the
.  add instruction, partially)
     mov r14,#5    ; put +5 in r14
     mov r3,#10    ; put 10 in r3 (so r(r3+4) == r14) holds 5
     mov r1,#-5    ; load r1 with -5
     add r1,4(r3)  ; add the contents of r3+4 to r1 e.g. r14 or 5
     sysnz         ; fail if zero flag clear(+5 + -5 == 0)
     syscc         ; fail if carry clear (carry set in 8 bit)
     sysmi         ; fail if sign flag set (result is zero)

Just for clarity the 4(r3) notation means take the contents of r3 (e.g. 10), add 4 to them, making 14 and use that register. It's a long winded way of pointing to r14 (add r1,r14 would do the same thing)

The failure works as follows

     mov r0,#-1    ; puts -1 (e.g. 255 in 8 bit) into R0
     xor r1,r1     ; clear r1 - xor updates S and Z flags
     sysnz         ; that will clear Z so this condition will 
                   ; succeed causing the system function 255 to
                   ; be called which will report a failure

No comments:

Post a Comment