~fkfd/p1s-lc2k

LC2K simulator written in LC2K

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~fkfd/p1s-lc2k
read/write
git@git.sr.ht:~fkfd/p1s-lc2k

You can also use your local clone with git send-email.

#p1s-lc2k

TL;DR: I wrote a simulator for an ISA with its own assembly language.

LC2K is a Fisher-Price instruction set architecture (ISA) we teach in the course EECS 370: Intro to Computer Organization at the University of Michigan. Part of project 1 is writing a simulator for LC2K in C. However, one day it randomly occurred to me that it is possible to simulate LC2K in LC2K.

If you haven't taken 370, the following will not make sense. In that case, just open p1s.as, admire its beauty, close the tab, and go on with your life.

#Build & Run

To build this, you will need:

  • p1s (C version)
  • p2a
  • p2l
  • p2 Makefile
  • Some test cases (.as files)

Obviously I cannot provide any of them.

Printing memory is slow, so you may want to comment out invocations to printState in simulator.c except for the last one.

Then, just run ./test.sh <TESTCASE>.as. The script does the following:

  • Compile assembler, linker, and simulator (.c -> ELF)
  • Assemble simulator (p1s.as -> p1s.mc)
  • Assemble testcase (<TESTCASE>.as -> <TESTCASE.mc>)
  • Glue together p1s.mc and <TESTCASE>.mc into test.mc so that p1s.mc begins at address 0 and <TESTCASE>.mc begins at address 256
  • Run simulator (the C version) against test.mc

Note that I put little thought into error handling in test.sh.

#Performance

The simulator takes ~1500 cycles to simulate one LC2K instruction.

Test case Cycles (C) Cycles (LC2K) LC2K / C
spec.as (p1) 17 26110 1536
fib(11) (p2r, mine) 5679 8776469 1545

I believe that most of the cycles are spent on right-shifting the instructions. This can be optimized, but it does not mean I am going to. Cope.

Do not follow this link