Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS 230 Winter 2024

Assignment 3

Coverage: Character Representations; Integer Operations and Branching in MIPS

Due Date: Monday, February 26, 11:59 p.m.

• All submissions are to be completed through MarkUs (https://markus.student.cs.uwaterloo.ca/markus_cs230_w/en/assignments)

The file submitted for Question 1 must be PDF files. For the PDF files you may submit electronically generated files from a source such as LaTeX, or you may submit scanned, hand-written solutions. However, the submitted file must be readable by the markers.

The files submitted for Questions 2 and 3 must be a plain text file. The easiest way to ensure this is to create the file on the linux.student.cs server, then assemble and test the file using the MIPS emulator.

• Read the policy described in Learn regarding late submissions.

Check MarkUs to see how many 12-hour grace periods you have remaining.

• Solutions for assignments will not be posted.

For this and all future assignments and quizzes, the term bit sequence refers to a computer representation of data. Normally there will be a fixed length associated with the sequence. There will always be context associated with the sequence to explain how it should be interpreted. The term decimal refers to base-10 numbers.

Questions 1 and 2 are weighted approximately evenly. Question 2 is approximately 3/4 of the weight of Question 3.

1. Answer the following questions about ASCII and Unicode encoding. When interpreting the bit sequences, read the bytes from left to right.

You can refer to the ASCII code table found at: http://www.asciitable.com/

You can use the code charts at https://www.unicode.org/charts/ to look up codes or find encodings for Unicode characters.

(a) This part deals with ASCII codes.

i. Write the bit sequence of the ASCII encoding that represents the text inside the quotes: “uW#1”

ii. Write the text represented by the following ASCII encoding bit sequence:

001110100101111000101001

(b) Identify the character represented by each of the following UTF-8 encoding bit sequences. For each character identify the Unicode code point. Where possible write the exact character or include a picture of the character. If that is not possible, then clearly describe the character.

Show the steps you used to determine each character within a sequence. All sequences are 32-bits long and represent one or more Unicode characters. There are no extra bits in the encodings.

i. 00101010111000101001110010101000

ii. 11110000100111111010011010001001

iii. 11100010100011001010100001001011

iv. 11000011101101111100001010100010

(c) For this part, you need to identify the Unicode code point and write the UTF-8 encoding for each of the two characters described below. The UTF-8 code should be written with hexadecimal digits rather than a bit sequence, i.e. every 4 bits of the sequence should be replaced by a single hexadecimal digit.

The basic steps for encoding a character are:

Determine if the code is 8, 16, 24, or 32 bits long. The Wikipedia summary may be helpful: https://en.wikipedia.org/wiki/UTF-8#Encoding

• Convert the code point to a bit sequence

Use the bits of the code point to produce the correct UTF-8 encoding sequence Show the steps you used to determine the UTF-8 encoding for each character.

i. PEACE SYMBOL

ii. SMILING FACE WITH SUNGLASSES

Submit the file a3q1.pdf.

Questions 2 and 3 are programming questions in assembly code.

Your programs must assemble and run properly with the given MIPS assembler binasm in the student.cs environment. Programs that do not assemble will lose the majority of the marks for the question.

Assume that all values can be properly represented with 32-bits (i.e. they fit in a register)

You can test your program using the twoints MIPS emulator frontend, which means you should assume that registers $1 and $2 will be initialized, but you should not make any assumptions about the exact values in those registers.

Your solution should include comments at the beginning that include your name, your Quest ID, and a brief description of the program. These comments should also include a summary of the registers used in the program. See the solutions for Tutorial 5 coding questions as a model.

Comment each line of your code to describe the purpose of the instruction.

Do not change the value of registers $30 or $31. The contents of the registers that are explicitly mentioned in the problem description must meet the specification, however other registers may have random values as required by your solution.

2. Consider the following equation: y = (5a 2b) + (3a 8)2 6ab

Write an assembly program that calculates the value of y, and places the result in register $3. The program should assume that the values for register $1 and register $2 have been set by the twoints front end, where register $1 contains the value for a and register $2 contains the value for b.

For example, if the user enters the integers 4 and 1, then after your program runs, the value 0x0000000a should appear in register $3, since 0xa is equal to the decimal number 10.

Submit the file a3q2.asm.

3. Write an assembly program that finds the sum of the digits of a non-negative, decimal integer that are multiples of a single-digit, positive integer n. At the end of the program, this sum should appear in register $3.

The program should assume that the values for register $1 and register $2 have been set by the twoints front end, where register $1 contains the decimal integer and register $2 contains the value of n.

For example, when running the program with the twoints front end and entering the following decimal values:

• value for register $1: 6337194

• value for register $2: 3

at the end of the program, register $3 should contain 0x00000015 since there are four digits that are multiples of 3, and 6 + 3 + 3 + 9 = 2110 =0x15.

Submit the file a3q3.asm.