Source code for Hangman
About a month ago, I asked the audience (you!) for a solution to the hang man game presented on this website. Of course, as we all know, the solution was Count Rushmore.
Now that the project deadline is over, I can also share some source code with you. I am not entirely sure whether I am allowed to distribute the compiler's source code, since there will be another compiler construction course next year, but I can give you the source code to programs conforming to the vier programming language the and the generated assembler code with it.
You will need the DLX Simulator to run the assembler programs.
Hangman game
Download: hangman.vier and hangman.asm.gz.
Run with ./risc-emu -mem=16777216 hangman.asm.
Screenshot:
_______
|/ |
| (_)
| |
| |
| /
|
___|___
_ o u n t r u s h _ o r e
Enter your guess:
Pascal triangle
Download: pascal.vier and pascal.asm.
Run with ./risc-emu pascal.asm
Screenshot:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1
Fun with Lists
Download: listfun.vier and listfun.asm.gz.
Run with ./risc-emu -mem=16777216 listfun.asm
Screenshot:
4 7 1 6 2 3 5 5 3 2 6 1 7 4 16 49 1 36 4 9 25 -4 -7 -1 -6 -2 -3 -5
Memory structure
Here is some ASCII art on how the memory is organized. The global memory layout is as follows (you may recognize it in the assembler code. Read from bottom to top):
Memory Layout:
. .
. .
| |
+-------------------------------+
| BEQ 0 start |
| initialisation du glaneur de |
| cellules, du pointer de pile |
init: | et des VMTs |
+-------------------------------+
| SYSCALL 0 0 SYS_EXIT |
start: | expression principale |
+-------------------------------+
| |
| code des méthodes |
| |
+-------------------------------+
| | ^
| tables virtuelles de méthodes | |
| | |
+-------------------------------+ | direction de l'exécution
0 | BEQ 0 init | |
+-------------------------------+ |
The stack frame layout for each method call is as follows (read from top to bottom):
Stack frame layout. Each cell is 1 word. +----------------+ <-- FP | this | +----------------+ | arg 1 | | +----------------+ | | arg 2 | | +----------------+ `.' . . . . +----------------+ | return address | +----------------+ <-- SP
For each instance of an object, memory is allocated on the heap as follows (read from bottom to top):
Object layout (heap). Each cell is 1 word. +----------------+ <-- (objectSize + 1) * WORD_SIZE | Field n | +----------------+ . . ^ . . | +----------------+ | | Field 1 | | +----------------+ | VMT Addr | +----------------+ <-- address returned by SYS_GC_ALLOC
Comments
Post a comment
Posting is disabled due to excessive spamming.
Last modified on 31.07.2008 at 12:30 GMT

that's MY triangle!
:-)