@kissa.bsky.social
Tomfoolery, nincompoopery, programming
People in Bluesky vs. people in Place Previously Known As Twitter
November 7, 2023 at 3:50 PM
Actually need to implement a bunch of arithmetic instructions and test them somehow efficiently. Here's a start.
October 19, 2023 at 8:15 PM
Here's the whole set of immediate instructions. This makes me reconsider the design, not only because of the effort of testing all of that stuff but also because I don't want to type "SHLAB" when I just want to do a 1-bit left shift. Maybe it's time to write some programs first and reconsider this.
October 19, 2023 at 9:11 AM
Good two hours reserved for today, let's continue with immediate instructions. Since we have augmented mode too, there's quite a bunch of these.

Instructions that logically take only 1 argument don't make sense, such as INC/DEC, and some potential ones like NEG, NOT, CLR. Except for MOV.
October 19, 2023 at 8:08 AM
Next, we want "augmented assignment" forms of those instructions (such as "a += b"), and then also immediate forms taking either a 8-bit or a 16-bit operand. The complexity is quickly getting out of hand. But let's start with the augmented ones:
October 18, 2023 at 12:57 PM
Got a cup of coffee and made a plan for arithmetic instructions. Note the absence of unsigned operators like logical shift right, because who needs those when all words are signed?

Note that mov is considered one of the arithmetic opcodes (it's similar in structure to e.g. neg, just does nothing)
October 18, 2023 at 12:26 PM
Day 3 and can't decide whether to take a nap or get a coffee. Good 2 hours to go and some code needs written. Maybe should expand this poor opcode list today
October 18, 2023 at 11:01 AM
Writing tests is more convenient by allowing write8() to take multiple arguments:
October 17, 2023 at 9:12 PM
Let's make things a bit more consistent. Left: before, right: after
October 17, 2023 at 7:51 PM
And here is the core of the virtual machine:
October 17, 2023 at 9:31 AM
To read and write bytes we introduce readOperand() and writeOperand(), which are used to do the heavy lifting. We also need a function to read and sign-extend a byte, read8s(). Extra write function is not needed, write8 works for signed bytes as well.
October 17, 2023 at 9:27 AM
hi() and lo() set the 7th bit of the operand, which turns on byte addressing (as opposed to word addressing, which is the default)
October 17, 2023 at 9:18 AM
After a bit of byte wrangling, we can now write and read bytes (which, upon reading, are sign-extended)
October 17, 2023 at 9:13 AM
Added some printf debugging machinery to find out why my second add instruction didn't run, can you guess why?
October 17, 2023 at 8:37 AM
Day 2 of virtual machine hacking, think I’ll do byte addressing now
October 17, 2023 at 8:19 AM
What we have now is direct addressing, e.g. [0x1234]. This extends the design with indirect addressing using either immediate or an index register, allowing things like [pc + 5] and [p + i]. Also byte addressing is supported with syntax [0x1234].b
October 16, 2023 at 1:40 PM
Operands are now simply 8 bits and denote memory addresses 0x00 to 0xff. I have a slightly more complex design in mind but let's get some syntax defined first. This also details how to address lower and higher parts of registers:
October 16, 2023 at 1:26 PM
We also accidentally implemented jumping, which can be done by adding values to PC
October 16, 2023 at 9:49 AM
And our first program that performs the operation A = B + C and then halts. And another that causes the machine to catch fire. Time for lunch!
October 16, 2023 at 9:39 AM
Time to implement our first machine language. Introducing instructions ADD, HLT and HCF (Halt and Catch Fire). All have 3 operands for simplicity, though only ADD uses them. Operands are simply memory addresses (or registers, since they are mapped to addresses 0-31)
October 16, 2023 at 9:35 AM
Added 8-bit reading and writing. 16-bit reads and writes are signed, but 8-bit reads and writes are unsigned (no sign extension when reading). That might be reconsidered later if needed
October 16, 2023 at 8:55 AM
Initial plans for registers: we'll have 4 general purpose registers (A B C D), 4 index registers (I J X Y), four address registers (P Q SP PC). And a bunch of reserved ones just in case we need some more. These 16 registers are mapped to memory addresses 0-31.
October 16, 2023 at 8:39 AM
The boring part related to reading and writing should be mostly done now.
October 16, 2023 at 8:05 AM
Implementation starting to a look a bit hairy already
October 16, 2023 at 7:44 AM
I guess we need negative numbers too. Maybe all numbers should be signed for now, let's deal with the unsigned/signed complexity later.
October 16, 2023 at 7:42 AM