代写C C++ Java Python 视频讲解客服在线客服在线

代做国外C C++ Java程序 Python QQ 2365427650 Email 2365427650@qq.com 免费咨询编程问题

« ICS 51 MIPS tutorMIPS assembler »

ICS 51 MIPS Tutor

In this assignment, you will create a set of leaf functions that work with 1D arrays of integers and characters using
different types of loops.
The goal of this assignment is:
Practice the use of conditional and unconditional branch instructions through the use of different types of loops
Practice writing MIPS functions calls
Experience working with function arguments and function return values
Work with 1D arrays of different data types, eg. integers, and characters
More experience working with bitwise and shifting instructions
Improve your understanding of MIPS assembly instructions and writing MIPS assembly
You MUST implement all the functions in the assignment as defined.
🤔 If you are having difficulties implementing these functions, write out the pseudo-code or implement the functions
in a higher-level language first. Once you understand the algorithm and what steps to perform, then translate the
logic to MIPS.
ICS 51 - Introduction to Computer Organization
Copyright 2022 - Prof.
Jennifer Wong-Ma
This content is protected and may not be shared uploaded or distributed🤔When writing your program, try to comment as much as possible. Try to stay consistent with your formatting. It is
much easier for your TA and the professor to help you if we can figure out what your code does quickly
Getting Started
Download hw2_basecode.zip. This file contains hw2_netid.asm and multiple hw2_main files, which you can
use to test for the assignment. At the top of your hw2_netid.asm program, in the comments, put your name
and netid.
# Your full name
# Netid.
How to test your functions
To test your functions, simply open the provided hw2_main file which tests your functions in MARS. Next,
assemble and run the main file. Mars will take the contents of the file referenced with the .include at the end
of the file and add the contents of your hw2_netid.asm file before assembling it.
The main files only call each function with ONE of the sample test cases and print the return value(s) to the
output. You will need to modify the arguments passed to the functions to test with the other cases.
It is highly advised to write your own main programs (new individual files) and create your own data
arrays (in the main files) to test each of your functions thoroughly. Your assignment will not be graded
using the examples provided!
Make sure to initialize all of your values within your functions! Never assume registers or memory will
hold any particular values!
Any modifications to the main files will not be graded. You will only submit your hw2_netid.asm file to
Gradescope.
There is no need to define a .data section within your homework. Your functions should not refer to
any labels directly.
To make sure that your code is self-contained, try assembling your hw2_netid.asm file by itself in MARS. If
you get any errors (such as a missing label), this means that you need to refactor (reorganize) your code,
possibly by moving labels you inadvertently defined in the main file to hw2_netid.asm.
Part 1: Basic Leaf Functions for 1D Character Arrays
As explained in the lab, the notation (int,int) for return values is our way of specifying the ability to return
2 values in MIPS. This tuple represents returning values in the registers ($v0, $v1).
A. (int, int) countSpecial(char[] str)
This function counts the punctuation and non-printable characters within str. String str is unmodified
by the function. A punctuation character is defined as any character in range [0x21,0x7E] except the
alphabet and numbers. A non-printable character is in the range [0x00,0x1F].
Function parameter and return value summary:
ICS 51 - Introduction to Computer Organization
Copyright 2022 - Prof. Jennifer Wong-Ma
This content is protected and may not be shared uploaded or distributedstr: starting address of null-terminated ASCII character string
returns: (number of punctuation characters, number of non-printable characters)
Examples:
Code
Return Value
countSpecial("ICS51 Rules!!!")
(3,0)
countSpecial("\n")
(0,1)
countSpecial("~What's\thappening??")
(4,1)
countSpecial("*\r1\n2\t3\b4\f5\v6\x0F+")
Read more about Escape Characters
'\r' carriage return
'\n' new line
'\t' tab
'\b' backspace
'\f' form feed
This string can't be entered in Mars as shown. Use str2 provided in testing main
(2,7)
C syntax is used when describing all functions in the document.
Arguments specified with [] denote the passing of the STARTING ADDRESS of the array in
memory. As the size of the array is unknown to your code, it must be either hard-coded (eg.
[5]) or the size is passed as an argument.
In all other cases (eg. int n, char c, etc), the VALUE is passed directly to the function.
B. int replace(char[] str, char toReplace, char replaceWith)
This function finds each occurrence of the ASCII character toReplace in null-terminated
str and replaces it with the ASCII character replaceWith.
Function parameter and return value summary:
str : starting address of null-terminated ASCII character string of any length.
toReplace : ASCII character to find occurrences of in str.
replaceWith : ASCII character to replace the toReplace character in str with.
returns : the number of replacements made
Return -1 for error in any of the following cases:
toReplace is the null terminator, 0x00
toReplace is not a valid ASCII character, ASCII character value > 0x7F.
replaceWith is not a valid ASCII character, ASCII character value > 0x7F.
We WILL NOT test the function with an invalid str argument address.
The function MUST modify str in place, ie. in memory where it was originally stored.
Examples:
ICS 51 - Introduction to Computer Organization
Copyright 2022 - Prof. Jennifer Wong-Ma
This content is protected and may not be shared uploaded or distributedFunction Call
Return Value
Resultant str
replace("Funny Bunny", ‘F’,‘B’)
1
"Bunny Bunny"
replace("Funny Bunny", ‘n’,‘z’)
4
"Fuzzy Buzzy"
replace("Funny\tBunny", ‘\t’,‘_’)
1
"Funny_Bunny"
replace("ICS51 Rules!!!", ‘!’,‘\0’)
3
"ICS51 Rules"
replace("Funny Bunny", 0x80, ‘A’)
-1
unmodified
replace("Funny Bunny", ‘F’, 0xFF)
-1
unmodified
replace("Funny Bunny", ‘\0’, 0xE1)
-1
unmodified
Part 2: Basic Leaf Functions for 1D Integer Arrays
C. int isMul2(int[] array, int len, int n)
This function finds the index, starting from 0, of the first value in array which is a multiple of 2n.
Function parameter and return value summary:
array: starting address of array of n integer values
len: integer number of elements stored in array
n: integer value representing exponent value
returns : index of first value
Return -1 for error in any of the following cases:
value in array is < 0
no value in array which is a multiple of 2n
n not in range [0,29]
len < 1
Examples:
array
len
n
Return Value
[10,20,30,40,50,60,70,900]
8
0
0
[101,50,1,200]
4
1
1
[2,4,8,16,32,64]
6
4
3
[101,50,1,202]
4
3
-1
[7,9,11,-3,5,-7,11,-21]
8
3
-1
D. int countFactor(int[] values, int len, int k, int[] factors)
This function determines for each value in values if it is evenly divisible by k. If the value is divisible
by k, the quotient is stored in the corresponding index of factors. If the value is not divisible by k,
0x80000000 (largest negative number) is stored in factors. The function returns the number of
values in values which were evenly divisible by k.
Function parameter and return value summary:
values: starting address of values of len integer values
len: integer number of elements stored in values
ICS 51 - Introduction to Computer Organization
Copyright 2022 - Prof. Jennifer Wong-Ma
This content is protected and may not be shared uploaded or distributedk: integer number to determine if factor
factors: starting address of factors array, guaranteed to hold len integer values
returns : number of values which are evenly divisible by k, or -1 on error.
Return -1 for error in any of the following cases:
len 0
k 0
Examples:
values
len
k
Return
Value
factors
[11,2,33,4,10,0,-10]
7
2
5
[0x80000000,1,0x80000000,2,5,0,-5]
[0,2,0,7,0]
5
1
5
[0,2,0,7,0]
[0,2,0,7,0]
3
7
2
[0,0x80000000,0]
[7,9,11,-34,-121,-11]
6
11
3
[0x80000000,0x80000000,1,0x80000000,
-11,-1]
[1,2,3,4]
-4
1
-1
unmodified
🤔 Sub-arrays can be searched if len is a value less than the actual size of the array or if the starting
address passed to the function is greater than values[0].
Part 3: More Advanced Leaf Functions
E. (int, int) findLenStrings(String[] array, int len)
This function finds the indexes, counting from 0, of the shortest and longest strings in array with len
elements. In the case of a tie, the lowest index is returned.
Consider the 5 strings shown in the example below. Each string is a null-terminated array of characters
(tan). The starting address of each string is stored in an array of integer addresses (blue). The starting
address of the blue array is passed as the first argument to the function, findLenStrings.
The shortest string is "B" referenced by the address stored in array[2]. The longest string is "HeLLO!"
referenced by the address stored in array[1]. The function returns (2,1).
Function parameter and return value summary:
array: starting address of array of len addresses of character strings
len: integer number of elements stored in array
returns: (index of shortest string , index of longest string)
ICS 51 - Introduction to Computer Organization
Copyright 2022 - Prof. Jennifer Wong-Ma
This content is protected and may not be shared uploaded or distributedReturn (-1,-1) for error in any of the following cases:
len 0
We WILL NOT test the function with an invalid addresses in array.
Examples:
array
len
Return Value
Example shown above
2
(0,1)
Example shown above
1
(0,0)
["ICS51", "is", "fun", "!!!!"]
4
(1,0)
["123","","456789","ABCDEF"]
4
(1,2)
["ICS51", "is", "fun!!!!"]
-2
(-1,-1)
The null cipher is a basic form of cryptography where the message is hidden in plain sight in a seemingly
normal message. For this function, you will encrypt a message using a modified version of the null cipher
with the following rules:
A null-terminated cipher text string is all lowercase letters where the message will be hidden.
Each word of the cipher text string is separated by a single space character.
A code sequence is a sequence of integers which indicates which letter in each word of the cipher text is
used to encode the message.
Example: [1, 5, 0, 5, 2, 1, 4, 0, 0, 1, 4, 3, 1] means first letter of first word, fifth letter of second
word, no letter in 3rd word, …..
If the cipher text is longer than the code sequence, simply ignore the rest of the words.
If a word in the cipher text does not contain the letter to encode from the message text, 0 is
entered in the code sequence.
The message that is encoded must be in lowercase and contain no spaces.
For example, say we want to encode the word "love" into the cipher text shown below. For each letter in the
message, search each word to see if it contains the letter. If it does, record the index in the code sequence
index. If it does not contain the letter, record 0. Skip to the next word in the ciphertext to look for the
letter/next letter in the message. The resultant codeseq created is [1,0,0,2,2,0,0,5]
"live, laugh, and love every day -clay walker"
F. int encodeNullCipher(char[] ciphertext, int[] codeseq, char[] message);
This function encodes as many characters of message as possible using the ciphertext to determine
the character index per word. Index values are placed in codeseq. Words in the ciphertext are delimited
with 1 space character (0x20). The function returns the number of message characters which were
encoded using the ciphertext (ie. the number of non-zero indices stored in codeseq).
The ciphertext array is unmodified in memory by the function.The codeseq array is modified in
ICS 51 - Introduction to Computer Organization
Copyright 2022 - Prof. Jennifer Wong-Ma
This content is protected and may not be shared uploaded or distributedmemory by the function. The codeseq array is not initialized to 0 and each entry must be modified for
each word found in the ciphertext.
The function assumes (do not need to check for these cases):
the length of the codeseq array is equal to the number of words in ciphertext
message and ciphertext do not contain upper case characters
message does not contain any spaces
ciphertext does not have 1+ adjacent space characters between words
Punctuation and numbers in the message can be encoded.
Function parameter and return value summary:
ciphertext: Starting address of the ASCII character string representing the ciphertext
(null-terminated).
codeseq: Starting address of integer array for the code sequence to decode with.
message: Starting address of ASCII character string to encode
returns : number of characters in message encoded or -1 on error.
Return -1 for error in any of the following cases:
ciphertext has length of 0 (empty string)
message has length of 0 (empty string)
Examples:
Correct encoding
Function Call
Return Value
encodeNullCipher(ciphertext_addr, codeseq_addr, "welovemips")
10
ciphertext
"whenever students program lovely code very late at night, my brain
explodes! *sigh sigh sigh*"
codeseq
[1, 5, 0, 1, 2, 1, 4, 0, 0, 1, 4, 3, 2, 0, 0]
Partial encoding - not enough words in ciphertext
Function Call
Return Value
encodeNullCipher(ciphertext_addr, codeseq_addr, "iamme")
4
ciphertext
“it always seems impossible, until it isn't."
codeseq
[1, 1, 4, 2, 0, 0, 0]
Partial encoding - punctuation can be encoded
Function Call
Return Value
encodeNullCipher(ciphertext_addr, codeseq_addr,"read.")
5
ciphertext
“dr. seuss said, you’re off to grrrr-eat places, today is your day. your
ICS 51 - Introduction to Computer Organization
Copyright 2022 - Prof. Jennifer Wong-Ma
This content is protected and may not be shared uploaded or distributedmountain is waiting, so get on your way.”
codeseq
[0, 0, 0, 5, 0, 0, 7, 3, 3, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Submitting your Homework
Upload hw2_netid.asm to Gradescope under the assignment, “Homework 2”
(Don’t forget to replace netid with your netid! For example: If your netid is panteate, then you would name your
submission hw2_panteate.asm)
Grading
Your homework submission will be tested using MARS ONLY. This ensures that your implementation is fairly graded
with the course instruction set.
It is the responsibility of the student to ensure that the assignment assembles in MARS and in Gradescope. Assignments
that do not assemble or run in Gradescope (with MARS) will be assigned a grade of 0.
Typically, 50% of your assignment grade will be awarded for passing the basic tests provided in Gradescope with the
assignment. The remaining 50% of the assignment grade will be allocated based on additional tests run after the
deadline. Students are heavily encouraged to test their programs beyond the basic tests provided in Gradescope.
ICS 51 - Introduction to Computer Organization
Copyright 2022 - Prof. Jennifer Wong-Ma
This content is protected and may not be shared uploaded or distributed

 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Walle Build 100427

Copyright 代写C.