ACOE301_Lab7

advertisement
Computer Science and Engineering
Department
Computer Architecture II (ACOE301)
Laboratory Exercise #7
Loops
Student’s Name:
Semester:
Date:
Assessment:
Assessment Point
Weight
Methodology
Presentation and discussion of results
Participation
Assessment Points’ Grade
Comments:
Grade
Computer Architecture II Lab5- ACOE301
Exercise #6: Loops,asciiz, system call
Hint: You can use the lecture notes found in
http://staff.fit.ac.cy/com.tk/ACOE301/Lecture1.ppt
http://staff.fit.ac.cy/com.tk/ACOE301/Lecture2.ppt
Objectives:
The objectives of this experiment is to show students the use of loops, and ascii in MIPS
assembly.
A Caesar Cipher was used back in the days of Caesar to encrypt and decrypt messages. It
was done by shifting the encrypted messages an X number of positions where X was the
key. For example if the message was “hello” and the key was 2 it was encrypted to “jgnnq”.
(i.e., ‘h’ became ‘j”).
Your task is to write the code that decrypts the code by trying a range of possible keys in the
English alphabet (max 25keys). Your code should put the corresponding decrypted
messages and keys in a buffer. E.g., 1tjtc2kkld3like – the numbers 1, 2, and 3 are the keys
and they are followed by the decrypted message/plaintext.
a) Open notepad and enter the following code:
.data
KeyRange: .word 10
Plaintext: .asciiz
“Xliaexivaewewgsphewmgierhwyhhirpcaiwea”
.text
main:
#enter your code here
addi $v0, $0, 10 #exit program
syscall
b) In the .asciiz segment you will find the ciphertext. Read it and then decrypt by
trying a range of keys. Be cautious for the case where the letter loops back (i.e.,
goes back) from the beginning of the alphabet to the end of alphabet. E.g., “b” is
decrypted to “z” with a key of 2. The KeyRange designates the number of keys that
can be tried. For example if Keyrange=2 then your code should try for k=1 and k=2.
c) Save the file as "lab7.s" or "lab7.asm" including the quotes. Make sure the file
is saved as "all files".
d) Run SPIM.
e) From the SPIM menu select "File => Load File". Select the file you created.
f) Run the program and verify its operation. If necessary, single step through the
program or use breakpoints to debug it.
1
Computer Architecture II Lab5- ACOE301
Questions
1. How many instructions did your program contain?
2. How many registers did your program require?
3. What is the decrypted message above?
What is the key?
4. Change the ciphertext to “knqxgvjkuencuu”
What is the decrypted message?
What is the key?
2
Download