BLUE
kissa.bsky.social
@kissa.bsky.social
Tomfoolery, nincompoopery, programming
37 followers374 following39 posts
kissa.bsky.social

A nice, crisp autumn’s day. A good day to write a virtual machine and an assembler for it.

2

DMmarlo.ooo

welcome! love your handle 🐈‍⬛

1
kissa.bsky.social

First we need memory. 64kB will be nice. And the ability to read a word from the memory. Word is 16 bits.

const MEM_SIZE = 256 * 256
const mem = new Uint8Array(MEM_SIZE)

function error(msg: string) {
	throw new Error(msg)
}

function read(addr: number) {
	if (addr < 0 || addr >= MEM_SIZE) {
		error(`read: invalid address ${addr}`)
	}

	return (mem[addr] << 8) + mem[addr + 1]
}

function test() {
	mem[0] = 0x12
	mem[1] = 0x34

	console.log(`0x${read(0).toString(16)}`)
	// => 0x1234
}

test()
1
kissa.bsky.social
@kissa.bsky.social
Tomfoolery, nincompoopery, programming
37 followers374 following39 posts