r/AskComputerScience • u/AnimusFoxx • Dec 08 '22
I am working on an 8-bit computer using logic gates. This is the Instruction ASet Architecture I'm developing for it. 32 instructions, with a 5-bit opcode for each. I'm having trouble coming up with ideas for the extra one [01110]. Might I get some help in this sub?
5
u/ghjm MSCS, CS Pro (20+) Dec 09 '22
You might find it more convenient if some of these instructions were organized in a way that makes the decoder logic easier. For example, when loading or storing a value to RAM, you will need to assert an address and also a high or low on the R/W pin. If the load RAM and store RAM instructions were, say, 00010 and 00011, then you can do a four bit comparison to determine that this is a memory operation, then just drive the R/W pin directly from the last bit of the instruction.
You also seem to be missing a number of addressing modes. There's a "load pointer," which I take to be an indexed addressing mode, but there's no equivalent store operation.
And last but not least, a number of these instructions are redundant. You don't need increment and decrement operations if you have add immediate and subtract immediate; you don't need all those logical operators (if you have AND and NOT then you don't need a dedicated NAND, etc).
Note: I don't know anything about Minecraft. These suggestions are based on actual computers.
1
u/AnimusFoxx Dec 09 '22
Interesting suggestions. I see your point about eliminating INC and DEC, also youre right I am missing the store pointer instruction. It looks like there's a fair amount of condensing I can do. Much of this is new to me so I greatly appreciate it. I'm having trouble understanding how I can condense the bitwise operations. Somebody else said I only need NOT and INC and can discard the rest. How do I achieve all of the bitwise ops with only those?
2
u/ghjm MSCS, CS Pro (20+) Dec 09 '22
1
u/AnimusFoxx Dec 09 '22
What do those instructions do?
2
u/ghjm MSCS, CS Pro (20+) Dec 09 '22
PUSH takes the value from a register, writes it to the location pointed to by the stack pointer (which is another register), and decrements or increments the stack pointer depending on which way you want the stack to grow. POP retrieves the current value from the top of the stack and increments or decrements the stack pointer.
You need a stack if you want to be able to call functions. You might do this with a CALL instruction like on x86, which writes the IP to the stack, decrements the stack pointer, and transfers control to the address parameter to the instruction. Then there's a RET instruction that pops the return address from the stack and jumps to it.
Interrupts are external conditions that cause the CPU to run a particular piece of code, called an interrupt handler. For example, you might get an interrupt when a character is ready for input from a serial device. Receiving an interrupt is like a CALL instruction - the CPU automatically pushes the current IP to the stack and jumps to the handler. Typically you don't want interrupts to interrupt interrupt handlers, so the CPU has a mask that blocks further interrupts until the handler returns. The IRET instruction is like RET but it also clears this mask.
SWI - software interrupt - allows calling an interrupt handler from code. This instruction is called INT on x86, and was used for system calls - INT 21 was a system call on MS-DOS, and INT 80 was a syscall on Linux.
Interrupt handlers also need PUSH and POP instructions, because they need to make use of registers to do anything, but any registers whose values they change must be restored before the IRET, to avoid breaking user code. As a result, an interrupt handler looks like several PUSH instructions, then some functionality (maybe an IN), then several POP instructions and an IRET.
2
u/AnimusFoxx Dec 08 '22
There's a typo in the title - ASet should be Set. I'm building this computer in Minecraft, and thus is my first CPU build ever, so the instruction can't be anything too fancy.
2
u/ReginaldDouchely Dec 08 '22
Well, since it's in minecraft, you've got the opportunity to implement halt and catch fire, but with real in-game fire
2
1
u/tilrman Dec 09 '22
I think you may have your "load" and "store" terms swapped in some places.
You have an instruction to copy the contents of a register to RAM at the address stored in another register. You could add the complementary instruction to copy a value from RAM at the location of one register into another register. (Or maybe you lack the former and have the latter.)
1
u/AnimusFoxx Dec 09 '22
That's an idea! I may use this. It seems obvious now that you say it, but hey, I'm a bit bone headed sometimes.
And yeah I do have those terms swapped by accident. Thanks for pointing that out
1
1
u/Poddster Dec 09 '22
Make that instruction the EXTEND instruction. If present it means you go into a second byte's worth of instruction. Chain them as necessary. (Though traditionally you'd have it as 0b11111 or something).
Or perhaps a modifier that turns any instruction using registers into one using immediate? That way you can get rid of all of the duplicate instructions.
1
u/Ventigon Jan 19 '23
I earlier found a nice book called "But How Do It Know" and it made me loving that kind of thing. It is so cool when you know what this guy is talking about. Maybe I could... Get some advantages from this post as I have no ideas what to add in a computer haha Nice work, looks cool
8
u/not_from_this_world Dec 08 '22 edited Dec 08 '22
Might as well leave it alone. Isn't more OP making it harder to build anyways? You have plenty of room to step up the challenge, virtual memory, parallelization, more bits, etc... You may save instruction space to those instead of rebuilding eveything.
I can see you already stretched out with a bunch of NOT(OP) but didn't brother making a simple NOT, I know you will use NAND for the NOT but if you need to have one more OP then might add the NOT as well.
Also an unrelated tip: in literature of load–store architecture the processor loads from memory and stores to memory, your circuit is working the other way around.