# 代写assembly | 汇编代写 | assignment | 代写lab | mips – Lab 4: ASCII Decimal to 2SC

### Lab 4: ASCII Decimal to 2SC

#### Minimum Submission Requirements

`````` Create a Lab4 folder (note the capitalization convention, include no extra
characters in the directory name) that contains the following files:
Diagram.pdf
Lab4.asm
Tag the commit that you would like to be graded
You will submit two tags for this lab: Lab4a_submission_# for Part A and
Lab4b_submission_# for Part B (note the capitalization convention)
``````

#### lab Objective

In this lab, you will develop a more detailed understanding of how data is represented, stored, and manipulated at the processor level. In addition to strengthening your understanding of mips coding, you will read a string input and learn how to convert numerical ASCII characters into a twos complement binary number. You will also learn how to print a twos complement integer stored in a register.

#### Lab Preparation

Read chapters 1 and 9 from Introduction To MIPS assembly Language Programming.

#### Specification

##### Functionality

The functionality of your program will be as follows:

1. Read two program arguments: signed decimal numbers [-64, 63].
2. Print the user inputs.
3. Convert the ASCII strings into two sign-extended integer values. a. Convert the first program argument to a 32-bit twos complement number, stored in register \$s1. b. Convert the second program argument to a 32-bit twos complement number, stored in register \$s2.
4. Add the two integer values, store the sum in \$s0.
5. Print the sum as a decimal to the console.
6. Print the sum as 32-bit twos complement binary number to the console.
7. (Extra credit) Print the sum as a decimal number expressed in Morse code. a. Use a period (ASCII code 0x2E) for dots and a hyphen (ASCII code 0x2D) for dashes. b. Insert a space (ASCII code 0x20) between characters. c. Dont forget to print the Morse code for a minus sign if the number is negative! Lab 4 Page 1 of 8 Fall 2018
##### Two Parts

Part A: Block Diagram & Pseudocode Before coding, you will first create a top level block diagram or flowchart to show how the different portions of your program will work together. Use https://www.draw.io or a similar drafting program to create this document. This diagram will be contained in the file Diagram.pdf. This diagram must be computer generated to receive full credit. Next, you will create pseudo code that outlines your program. Your pseudocode will appear underneath your header comment in Lab4.asm. Part B: Assembly Code Write a program in MIPS to implement the functionality.

##### Output

An example of the expected output is given below. Your codes output format should

##### match this output format exactly . New line characters are printed after each number

representation. If you skip the extra credit, the last line printed will be the new line character after the binary value. You entered the decimal numbers: 45 – The sum in decimal is:

The sum in twos complement binary is: 11111111111111111111111111110111 The sum in Morse code is: -….- —-. — program is finished running —

##### Files

Diagram.pdf This file will contain a block diagram or flowchart of how the different components of your code work together. To receive full credit, you must submit a computer generated diagram. Hand drawn diagrams will be worth half credit. Lab4.asm This file contains your pseudocode and assembly code. Header Comment Your code should include a header comment with your name, CruzID, date, lab number, course number, quarter, school, program description and notes. Every program you write should include information like this. This is a good opport unity to start developing effective code documentation skills. An example header comment is shown below. Lab 4 Page 2 of 8 Fall 2018

# Notes: This program is intended to be run from the MARS IDE.

############################################################################ Notes can contain any messages that are important for the user to know in order to run the program properly. For this lab you should put a note about how to enter a program argument. Every block or section of code should have a comment describing what that block of code is for. In-line comments should be lined up (using spaces) for ease of readability. Register Usage Registers \$s1 and \$s2 shall contain the two 32-bit twos complement integers entered by the user. Register \$s0 shall be used to store the 32-bit twos complement sum. You should try to use as few registers as possible. Try to only use \$zero, \$v0, \$a0, \$s0-\$s2, and the temporary registers, \$t0-\$t9. If you run out of registers, you may use \$s3-\$s8. After the header comment and pseudocode, but before your program, include a comment about register usage. Some registers might be reused in several parts of your code, this is ok. An example of this comment is shown below.

# \$s0: stores 2SC sum of user inputs

White Space Line up instructions, operands, and comments to increase readability. Code should be indented from labels. Bad Example LI \$t1 2 #initialize \$t LOOP: ADDI \$t0 \$t0 1 #increment \$t BLT \$t0 \$t1 L oop #determine if code should re-enter loop Good Example LI \$t1 2 # initialize \$t LOOP: ADDI \$t0 \$t0 1 # increment \$t BLT \$t0 \$t1 LOOP # determine if code should re-enter loop Lab 4 Page 3 of 8 Fall 2018

Lab 4: ASCII Decimal to 2SC CMPE 012 Fall 2018 Last Name, First Name CruzID

What was your approach to converting each decimal number to twos complement form? Write the answer here. What did you learn in this lab? Write the answer here. Did you encounter any issues? Were there parts of this lab you found enjoyable? Write the answer here. How would you redesign this lab to make it better? Write the answer here.

##### Syscalls

When printing the integer values, you may use syscall system services 4 (print string) and 11 (print character). You may not use syscall system service 1 (print integer), syscall system service 35 (print integer as binary), or syscall system service 36 (print integer as unsigned).

##### Input

In this lab you will obtain two user inputs, not using a syscall, but by using program arguments. The user will enter two integer values between -64 and 63. These numbers will be sign-extended to 32 bits and stored in \$s1 and \$s2. Turn on program arguments from the Settings menu as shown below. Lab 4 Page 4 of 8 Fall 2018

When program arguments are entered and the code is run, \$a0 initially contains the number of program arguments entered (program arguments are separated by spaces). The register \$a1 initially contains an address that we will call Address 1. If we go to Address 1 in memory, we will find another address, which we will call Address 2A. If we go to Address 2A in memory, we will find the ASCII encoding for the first byte of the first string entered in the program arguments. Example Program Argument In this example, there are four program arguments. We will call these Program Arguments A, B, C, and D as follows: Program Argument A: Flux Program Argument B: is Program Argument C: a Program Argument D: bunny The value of \$a0 has the value of 4 to match the 4 program arguments. We will call the value in \$a1 Address 1. Lab 4 Page 5 of 8 Fall 2018

It is important that you do not hard-code the values for any of the addresses in your program.

#### Turn Off Delayed Branching

From the settings menu, make sure Delayed branching is unchecked. Checking this option will insert a delay slot which makes the next instruction after a branch execute, no matter the outcome of the branch. To avoid having your program behave in unpredictable ways, make sure Delayed branching is turned off. In addition, add a nop instruction after each branch instruction. For example: LI \$t1 2 LOOP: ADDI \$t0 \$t0 1 BLT \$t0 \$t1 LOOP NOP # nop added after the branch instruction ADD \$t3 \$t5 \$t Lab 4 Page 7 of 8 Fall 2018

#### Submission Instructions

This assignment will be submitted in two parts. You will use the tags Lab4a_submission_# and Lab4b_submission_#. Late hours will not be used for Part A of the assignment. If you do not submit a diagram or pseudocode by the Part A deadline, you can submit it with your Part B submission for less points.