Microprogramming Contest
Due anytime on Thurs, May 3
This is both a homework assignment and a contest. As a homework assignment it
counts as three regular homework assignments! Thus it is the
most important assignment. As a contest, a winner or winners will be
named to try to honor those with the most creative and useful entries.
The homework grade will be based primarily on correctness; the contest will be
judged more on creativity and usefulness. There will be a small prize for the winner
(probably awarded at the final exam).
The task is multifaceted: you are to design, implement, document, and test
a new Mac-1 instruction. Try to aim for something useful and creative.
Place everything in a file called mic037.txt. At the bottom of this file
place comments describing your new instruction. In particular,
give a 4-letter mnemonic for your new instruction,
the binary encoding of it, its meaning in the usual Pascal-like pseudocode,
and an explanation in words of what it does, including any constants or values that it uses.
Thus, your description should give the opcode name, any parameters it takes, the meaning of
the instruction, how it is encoded in binary, examples of usage (if not clear from the description),
etc. The description should be a high-level description telling the Mac-1 programmer what this
instruction does overall, not a detailed list of what the microcode does. Be sure to say where
your instruction gets its data (if any) and where it places its answer (if any).
If you really want to you may add 2 instructions, but no more than that.
Try to add an instruction that does something that the existing ones do not do,
or uses a new addressing mode, or supports some high-level programming construct, etc.
See below for some ideas.
To implement your new Mac-1 instruction you must modify the
microprogram interpreter (near the end). There are some bit combinations
available for your new instruction. For example, 1111 1101 xxxx xxxx could
be used as long as you distinguish it from 1111 1100 xxxx xxxx in the
decoding. Change the microprogram interpreter so that it correctly decodes
both your new instruction and all of the old ones. You also have to include
the microcode to execute your new instruction.
Suggestion: the easiest way to begin on this is to copy an example that
added a new instruction. Thus you might begin by copying mic022.txt.
Devise a reasonable Mac-1 test program to check out your new instruction.
Be sure to include a test of the nearby instructions, INSP and DESP, in case
there are errors in your decoding. At the bottom of your file include the assembler version
of your test program in the comment section. Also include in this comment section the MAL code
(with line numbers) for those lines of the microprogram interpreter which you changed (or which you added).
Name your program file mic037.txt. Follow my format for such a file and place
your Mac-1 code and documentation
at the bottom of the file. Put your name as a comment at the
top of the file. Remember that this is an individual assignment. Do not
work together on this one. This one is your chance to show me what you can do.
See me if you need assistance. Copy your file to your hw330-1 folder to submit your homework.
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.
- 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 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 Divide local (like add local)
- DIVS Divide (a stack-based divide: pops 2 items, then pushes the
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 right becomes the
leftmost bit)
- ROTR Rotate right (so that the bit falling off the left becomes the
rightmost bit)
- 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 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)
- NOTA Not (Boolean not, invert all bits in the AC)