Hacker News new | ask | show | jobs
by norswap 3769 days ago
Pretty cool. I'd like to know more about the design decisions. Why registers? Why those specifically? And more.
1 comments

Alright. Even though its not really needed, and complicates things more, I was oddly attracted to the variable length instructions. I realize this would be a bit less attractive if it wasn't _my_ project, but I wanted to anyways. My basic design was one byte for the instruction (could be divided into two nibbles, one for the type, one for the actual instruction), and one byte for the registers. This allowed me 255 instructions max, and max 16 registers.

I then just started listing off the registers I needed. I could try to make up my own method of keeping track of the stack, base and instruction pointers, but I didn't really care enough. I also liked the _cdecl method of function calling in assembly, so I kept with that design as well. This meant a return register. The rest were split between caller and callee save registers, and I tried to give them a decently easy to remember mnemonic. Compare that to x86! I also realized I needed a null register which would indicate no register was used for operations (ie a `mov *(0x0), %ret` where there is no register for the first argument). I think I'll enforce this convention to make %null a little more useful. Unless the user tries really hard, I'll prevent anything from changing the contents of null from 0, making it useful for comparisons, and popping unwanted data.