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

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

export const opcodes: { [key: number]: string } = {
	0b00000000: "add", // add <dst> <src1> <src2> - dst <- src1 + src2
	0b00000001: "sub", // sub <dst> <src1> <src2> - dst <- src1 - src2

	0b11110000: "hlt", // hlt <?> <?> <?>         - halt program execution
	0b11110001: "hcf", // hcf <?> <?> <?>         - halt and catch fire
}
1

kissa.bsky.social

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)

Instructions

Arithmetic instructions (0-15)

add op1, op2, op3   ; op1 <- op2 + op3    00000000
sub op1, op2, op3   ; op1 <- op2 - op3    00000001
mul op1, op2, op3   ; op1 <- op2 * op3    00000010
div op1, op2, op3   ; op1 <- op2 / op3    00000011
mod op1, op2, op3   ; op1 <- op2 % op3    00000100
and op1, op2, op3   ; op1 <- op2 & op3    00000101
or op1, op2, op3    ; op1 <- op2 | op3    00000110
xor op1, op2, op3   ; op1 <- op2 ^ op3    00000111
shl op1, op2, op3   ; op1 <- op2 << op3   00001000
shr op1, op2, op3   ; op1 <- op2 >> op3   00001001
add1 op1, op2       ; op1 <- op2 + 1      00001010
sub1 op1, op2       ; op1 <- op2 - 1      00001011
mov op1, op2        ; op1 <- op2          00001100

Arithmetic instructions ending in 1101, 1110, 1111 are reserved. Some
candidates:

abs op1, op2        ; op1 <- abs(op2)
sgn op1, op2        ; op1 <- sign(op2)
neg op1, op2        ; op1 <- -op2
add2 op1, op2       ; op1 <- op2 + 2
sub2 op1, op2       ; op1 <- op2 - 2
1
kissa.bsky.social
@kissa.bsky.social
Tomfoolery, nincompoopery, programming
37 followers374 following39 posts