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

There's a bug in the above code. Reading at address 65535 should work, and let's make it so that the memory wraps (in practice rarely happens, but details matter)

index.test.ts:
✓ read word from memory [0.06ms]
12 |
13 | test("read at memory boundary", () => {
14 | 	mem[MEM_SIZE - 1] = 0x98
15 | 	mem[0] = 0x76
16 |
17 | 	expect(read(MEM_SIZE - 1)).toBe(0x9876)
    ^
error: expect(received).toBe(expected)

Expected: 39030
Received: NaN
1

kissa.bsky.social

I guess we need negative numbers too. Maybe all numbers should be signed for now, let's deal with the unsigned/signed complexity later.

test("read negative word", () => {
	mem[0] = 0xff
	mem[1] = 0xff

	expect(read(0)).toBe(-1)
})

test("boundary between negative and positive", () => {
	mem[0] = 0x7f
	mem[1] = 0xff
	mem[2] = 0x80
	mem[3] = 0x00

	expect(read(0)).toBe(32767)
	expect(read(2)).toBe(-32768)
})
1
kissa.bsky.social
@kissa.bsky.social
Tomfoolery, nincompoopery, programming
37 followers374 following39 posts