Microprogramming Contest Ideas
To help you in getting started, the following are some ideas for possible
new Mac-1 instructions. Of course, it would show more creativity to design
your own new instruction. But, if you need ideas, read on.
- LODI Load indirect (Loads the AC with the value pointed to by mem[x]. That is,
ac = mem[mem[x]]. Note that this is indirection via a main memory location x,
whereas PSHI and POPI do indirection via the AC.)
- STOI Store indirect (Stores the AC value into the location pointed to by mem[x].
That is, mem[mem[x]] = ac.)
- PSHX x Push indexed (Pushes onto the stack the item at mem[ac + x]. The AC is used as
the index register here.)
- POPX x Pop indexed (Pops the top item from the stack, placing it into mem[ac + x].)
- Perhaps you could invent an instruction to make it easier to return
an answer via a reference parameter. The current method of using
PUSH, LODL x, POPI is long and clumsy. Could you invent one instruction to replace this mess?
- LADL Load address local (Loads the AC with the address x items below the top
of stack.) Note that this loads the address, not the value at the address.
For example, if SP contains 60 and x (the low order 8 bit of the instruction)
is 4, then 60 + 4 = 64 is loaded into the AC. This instruction makes it possible
for a function other than main to call another function that has a reference parameter.
The calling function needs to be able to push the desired address for this reference parameter.
LADL provides a way to do this. (When main calls a function, the compiler knows the address
to push, but if some other function calls a second function, the desired address is not
directly known. However, it can be located by moving a set distance from the SP value.
That is what LADL does for us.)
- RETV Return with value (much like a RETN, but first pops the function
name value from the top of the stack into the AC) This would make it
easier to return an answer via the function name.
- SKPZ Skip on zero (if AC = 0, skip over the next instruction)
- SKPP Skip on positive (if AC > 0, skip over the next instruction)
- SKPG Skip on negative (if AC < 0, skip over the next instruction)
- SKPN Skip on nonzero (if AC != 0, skip over the next instruction)
- REPC x Repeat constant (pops a number n from the stack and uses it to
execute the next x lines of code n times; x is the low-order 8 bits
of the instruction). There are other ways to design useful instructions for loops.
- MULD x Multiply direct (like add direct, uses repeated addition to
multiply) Question: Will you handle negative numbers?
- MULL x Multiply local (like add local)
- MULS Multiply (a stack-based multiply: pops 2 items, then pushes the product)
- DIVD x Integer divide direct (like add direct, uses repeated subtraction to
divide) It might be possible to arrange one of these division
instructions to also leave the remainder in some convenient location.
- DIVL x Integer divide local (like add local)
- DIVS Integer divide (a stack-based divide: pops 2 items, then pushes the integer quotient)
- RSHT x Right shift (by the number of bits given in the low-order 8 bits of the instruction).
- LSHT x Left shift (by the number of bits given in the low-order 8 bits of the instruction).
- Other versions of shift instructions could be used. For example, the number of bits by
which to shift could be somewhere on the stack, with local addressing used to get this number.
- ROTL Rotate left (so that the bit falling off the left end becomes the new rightmost bit).
- ROTR Rotate right (so that the bit falling off the right end becomes the
new leftmost bit). This might be challenging to implement.
- ADDC x Add constant (Add to the AC the constant in the low-order 8 bits
of the instruction. Note that this uses immediate addressing.)
- SUBC x Subtract constant (similar)
- MULC x Multiply constant (similar)
- DIVC x Integer divide constant (similar)
- ANDL x And local (Boolean AND the AC with the item x locations down from the top of stack)
- ORLO x Or local (similar)
- XORL x Exclusive Or local (similar)
- LDDP x Load direct if positive (loads the AC with memory[x] if AC > 0)
- LDDZ x Load direct if zero (loads the AC with memory[x] if AC = 0)
- LDDG x Load direct if negative (loads the AC with memory[x] if AC < 0)
- LDDN x Load direct if nonzero (loads the AC with memory[x] if AC != 0)
- LDDO x Load direct opposite (loads the AC with -memory[x])
- MOVB x Move block of length x. Pops 2 numbers from the stack, call the first one start and the second destination.
It then copies memory[start] through memory[start + x - 1] to memory[destination] through memory[destination + x - 1].
- LDO Load ones (loads the accumumlator with 16 1's).