ICS 51 Winter 2022 – Homework 1
Due January 14, 2022 @ 8pm via Gradescope 20 points
DO NOT COPY/SHARE CODE! We will check your assignments against this term and code on the Internet! BE AWARE: The complexity of this assignment is simple and future assignments will be more challenging.
Download the course version of MARS posted on Canvas. DO NOT USE the MARS available on the official webpage. The course version has a reduced instruction set, added tools, and additional system calls you will need to complete the homework assignments.
You personally must implement the assignment in MIPS Assembly language by yourself. You may not use a code generator or other tools that write any MIPS code for you. You must manually write all MIPS Assembly code you submit as part of the assignment. You may also not write a code generator in MIPS Assembly that generates MIPS Assembly.
All test cases MUST execute in 5,000 instructions or less. Efficiency is an important aspect of programming!
Any excess output from your program (debugging notes, etc) WILL impact your grading. Do not leave erroneous printouts in your code!
Do not start your label names with two underscore characters (__). This will interfere with the autograder.
You will obtain a ZERO for the assignment if you do this.
Before you begin this assignment:
1. Watch the Lab Getting Started videos
2. Watch the Lab #1 MIPS videos
3. Complete the Lab #1 MIPS Activities in Canvas
Introduction
All data is stored in computers as a series of 1’s and 0’s. The accessibility of these bits by the programmer varies based on the programming language. Assembly language, and therefore MIPS, is the language the hardware understands and therefore it allows programmers to manually access and manipulate the bits.
In this assignment, the program created will access and manipulate inputted data. As we are still getting started and familiarized with MIPS, the assignment re-iterates many of the same concepts as Lab #1. The goal is to reinforce the experiences working with MIPS and strengthen your understanding and comfort level in assembly.
The learning objectives of this assignment are:
● Continue to work with different categories of MIPS instructions & registers
● Continue to use MIPS syscalls
● More experience working with data in memory (bytes)
● More experience working with ASCII character encoding
● Implement basic loops in MIPS
Getting Started
ICS 51 – Introduction to Computer Organization
This content is protected and may not be shared uploaded or distributed
Copyright 2022 – Prof. -Ma
📝
❗ ❗ ❗
❗
hw1.asm contains the base code for this assignment. Download the file and open it with Mars.
In hw1.asm, at the top of your program in the provided comments, place your name and netid. Save the file as
hw1_netid.asm, replacing netid with your netid name.
# Homework 1
# Name: MY_FIRSTNAME MY_LASTNAME (e.g., ) # Net ID: MY_NET_ID (e.g., jdoe)
.globl main
.data
# Data declarations go here ….
.text
main:
# Your code goes here
Submitting your Homework
Upload hw1_netid.asm to Gradescope under the assignment, “Homework 1”
(Don’t forget to replace netid with your netid! For example: If your netid is panteate, then you would
name your submission hw1_panteate.asm)
Remember, you can submit to Gradescope as many times as needed. Use this to your advantage to help identify
bugs in your implementation.
Part 1: Data is Just Data
In this part of the assignment, you will use your knowledge of ASCII characters and 2’s complement binary number representation.
Begin by prompting the user to input an ASCII string which represents a binary value. Use the string, prompt_binary, defined in the .data section. All the prompt strings are defined for you in the basecode file.
ICS 51 – Introduction to Computer Organization Copyright 2022 – Prof. -Ma This content is protected and may not be shared uploaded or distributed
A listing of all the official MARS systems calls here. You can also find the documentation for all instructions and supported system calls within MARS itself. Click the ? in the toolbar (as shown in the figure below) to open it.
🤔
Create space to store the entered ASCII string in the .data section. Remember, ASCII strings are stored in memory in Little Endian Format (we discussed this in the Memory Lecture of the theory module). Each ASCII character is encoded in 1 byte (8-bits) of data (reference). Use the read string syscall to read at most 32 ASCII characters.
Write a loop (or multiple) to iterate through the characters of the string in memory and perform the following:
How are strings terminated? How will you know when to stop?
● check that each character of the entered string is either ASCII character ‘0’ (0x30) or ‘1’(0x31). If any other ASCII character was entered, print the error message “INPUT ERROR” and exit the program (syscall 10). Note that the error string has already been defined in the .data section and is stored in memory at the address labeled err_string.
● determine the number of binary digits entered (aka bit length)
● if the entered string is less than 32 bytes, replace the ‘\n’ character at the end of the string with ‘\0’
If the bit length is < 2, print "INPUT ERROR" and exit the program (syscall 10). In all other cases, print out the following information:
● The bit length
● The maximum unsigned value represented by bit length (Use syscall 32 to print unsigned values)
● The range of 2's complement values represented by bit length
Examples:
ICS 51 - Introduction to Computer Organization Copyright 2022 - Prof. -Ma This content is protected and may not be shared uploaded or distributed
The read string syscall will only accept strings of the specified length. Make sure the space in memory can store 32 characters + the null terminator.
Note: An empty string is considered valid input by the syscall.
Enter ASCII string of binary digits (max 32 char): 1000K1110 INPUT ERROR
-- program is finished running --
Note: In the examples, black text is printed by your program or MARS. Red text is the values entered by the user. This is for your understanding of the examples only. The MARS simulator will not use these colors.
Think carefully about how you can determine/calculate these values. There are different ways to create the bit representations of these values in a register.
Enter ASCII string of binary digits (max 32 char): 1000 Bit Length: 4
Max unsigned value is 15
2's complement Range is [-8,7]
🤔
🤔
🤔
Enter ASCII string of binary digits (max 32 char): 1010101010 Bit Length: 10
Max unsigned value is 1023
2's complement Range is [-512,511]
Enter ASCII string of binary digits (max 32 char): 01 Bit Length: 2
Max unsigned value is 3
2's complement Range is [-2,1]
Implement a loop to translate the ASCII string of binary digits into its integer value (in a single register). For example, the ASCII string of binary digits "0100" is stored in 5 bytes of memory as 0x30, 0x31, 0x30, 0x30, 0x00. After the loop, a register should contain the 32-bit value 0x00000004. Use the print integer syscall to print the 2's complement value of the binary digits.
Examples:
Note: The 2's complement value printed will only be negative when all 32 binary digits are entered and the most significant digit (left-most) is 1.
Enter ASCII string of binary digits (max 32 char): 1000 Bit Length: 4
Max unsigned value is 15
2's complement Range is [-8,7]
2's complement value entered is 8
Enter ASCII string of binary digits (max 32 char): 1010101010 Bit Length: 10
Max unsigned value is 1023
2's complement Range is [-512,511]
2's complement value entered is 682
Enter ASCII string of binary digits (max 32 char): 10000000000000000000000000000001Bit Length: 32
Max unsigned value is 4294967295
2's complement Range is [-2147483648,2147483647] 2's complement value entered is -2147483647
Notice how the bit length string is not on its own line. This is because the syscall for reading a string
ICS 51 - Introduction to Computer Organization Copyright 2022 - Prof. -Ma This content is protected and may not be shared uploaded or distributed
🤔