Assignment 5(CS 201 Winter 2007)

advertisement
Assignment 5 (CS 201 Winter 2009)
Due Date: April 9, 2009
1. Write a procedure, howlong, that takes a pointer to a null-terminated ASCII
string in register $a0 and returns the length of the string, excluding its null
terminator, in register $v0.
2. Write a program to ask User to input a null ended string and call the above
procedure and display the string and its length
3. Additional pseudoinstructions
The following are some additional pseudoinstructions that one could define for
MiniMIPS. In each case, supply an equivalent MiniMIPS instruction or sequence
of instructions with the desired effect. In parth, mullacc is short for
“multiply-accumulate.”
parta: beqz
reg,L
# if (reg) = 0, goto L
partb: bnez
reg,L
# if (reg) ≠ 0, goto L
partc: bgtz
reg,L
# if (reg) > 0, goto L
partd: blez
reg,L
# if (reg) ≤ 0, goto L
parte: bgez
reg,L
# if (reg) ≥ 0, goto L
partf: double regd, regs
# regd = 2 X (regs)
partg: triple
regd, regs
#regd = 3 X (regs)
parth: mulacc regd, reg1,reg2
# regd = ( regd ) + ( reg1 ) X ( reg2 )
4. Finding max and min
Write a complete MiniMIPS program that accepts a sequence of integers at input
and after the receipt of each new input value, displays the largest and smallest
integers thus far. An input of 0 indicates the end of input values and is not an input
value itself. Note that you do not need to keep all integers in memory.
5. Decimal to hexadecimal conversion
Write a complete MiniMIPS program to read an unsigned integer with up to six
decimal digits from the input and represent it in hexadecimal form at the output.
Note that because the input integer fits in a single machine word,
decimal-to-binary conversion takes place as part of the input process. All you need
to do is to derive the hex representation from the binary word.
6. Substitution cipher
A substitution cipher changes a plaintext message to a ciphertext by substituting
each of the 26 letters of the English alphabet by another letter according to a
26-entry table. For simplicity, we assume that the plaintext or ciphertext does not
contain space, numerals, punctuation marks, or special symbols. Write a complete
MiniMIPS program to read a 26-symbol string defining the substitution table
( first symbol is the replacement for a, second one is for b, and so on ) and then
repeatedly request plaintext inputs, producing the equivalent ciphertext as output.
Each plaintext input is terminated by a period. Input of any symbol other than a
lower case letter or period terminates the program’s execution.
Download