COMP 273 Introduction to Computer Systems

COMP 273

MIPS Peripherals and Performance

Due: February 17, 2024, at 23:55 on MyCourses

INSTRUCTIONS

Tutorials B and C will be helpful for this assignment. The code to read and write from the MIPS keyboard and screen has been given in class. See the lecture slides.

Submit your answers in a single ASM text file called mini4.asm. The teaching assistants will hold office hours the week of February 13 to 17. Check myCourses for announcements.

You are expected to do all your work on your own. Plagiarism and cheating area serious offence. You may ask classmates, the TA s, and the professor clarification questions.

QUESTIONS

QUESTION ONE: MIPS Keyboard and Text Screen Drivers

Computers have many types of drivers: printer, keyboard, mouse, video, network, modem, hard disk, soundcard, etc.  Most of these drivers are created using assembler.

MARS only simulates two hardware devices: the keyboard and the text-screen.  These are both referred to as console I/O devices.

To input and display the characters from the console I/O devices you will need to access the MARS keyboard and MARS text screen from the following location:

Note:

In MIPS programming we have the following conventions: a MIPS subroutine can be implemented in two ways, as a driver or as a function. If a MIPS subroutine is implemented as a driver, then it does not use the run-time stack but uses only the register conventions for subroutine access.  In other words, A0-A4 for parameter passing and V0-V1 for returning values. It only uses the run-time stack for saving the S registers.  If a MIPS subroutine is implemented as a function, then it follows the C function calling convention: all parameters, local variables, and  saving registers are placed on the run-time stack, and returned values are placed in V0-V1.

For this assignment, write the code designated as “driver” using the register-passing

convention. Write the code designated as “function” using the C-passing convention using the run-time stack.

The assignment:

Write a MIPS program that prompts the user to enter their first name and then prompts them to enter their lastname.  The program then displays: “You entered: , ” .

Where and are the words the user input.  The program then stops. You will replace the syscall commands you normally use for I/O with your own drivers (as  described below).

Example :

First name: Bob

Last name: Smith

You entered: Smith, Bob.

Your program must adhere to the following instructions :

1.    Create a driver called GETCHAR, similar to the C library function char getchar(void) using MIPS, that interfaces with the MARS keyboard’s status and data registers. This driver, when called returns a single character from the keyboard buffer to register $V0. Do NOT use the OS syscall command.  Access the peripheral directly.  A slide in class was given to help you. Implement this program as a driver using the code presented in class.

2.    Create a driver called PUTCHAR, similar to the C library function void putchar(char c) using MIPS, that interfaces with the MIPS screen’s (console) status and data registers.  This driver, when called, assumes that register $A0 contains the single character that needs to be output.  Only one character is output. Do NOT use the OS syscall command.  Access the peripheral directly. A slide in class was given to help you.  Implement this program as a driver using the code presented in class.

3.   To test this, you will build the following functions in MIPS:

a.    int gets(char *buffer, int limit)

int puts(char *buffer)

The function GETS reads (and function PUTS writes) ASCII from the keyboard into a memory space pointed to by BUFFER (from BUFFER to the screen for PUTS).  It stops reading when the user either presses the enter key or when LIMIT characters is reached (stops printing when NULL is found for PUTS).  The string is terminated with a ‘\0’ (if there is space).  The function also returns the number of characters it read (outputted for PUTS) into $v0.

The function GETS must use GETCHAR and the function PUTS must use PUTCHAR.

The function gets() and puts() are used to read and write the user's name, and any other string based input or output,in your program. You CANNOT uses syscall in this assignment at all for string and character operations.

QUESTION TWO: Performance

Assume we have a hard drive that can operate in both polling or interrupt mode. Assume further that the disk drive can access data in either block or byte mode.  Block mode uses the disk drive's internal buffer to store 10K bytes of data.  In block mode the hard drive can run on its own after receiving the start address on disk and the number of bytes to read from the CPU.  All these bytes are loaded into the buffer.  If the number of bytes to read is greater than the size of the buffer (only the bytes that fit into    the buffer are loaded) or if all the requested bytes have been read (less than the buffer size), an interrupt is sent to the CPU once the buffer is full or once the operation is completed. The CPU then needs to download the buffer to RAM, clear the buffer, and instruct the drive to continue reading (if needed).  There is no DMI (DMA) to help do the download.

Byte mode simply copies a single byte of data from the hard disk given the address on disk of the byte. This byte is stored in the disk drive buffer at the first byte of the buffer.  No interrupt is sent.  It is up to the CPU to know when to extract that byte from the buffer using polling.  The disk drive has a status register that is set to integer 1 when the drive is busy, 0 when it is not busy and no data is in the buffer, 2 when it is not busy but a single byte is in the buffer, and 3 if it is not busy with a full buffer. The status register uses integer numbers instead of bit flags. The status register is 8-bits long.

Assume that polling for one byte takes 200 ticks, while a single interrupt takes 500 ticks. Assume we want to copy a one meg (106  bytes) file from disk to RAM.  Assume further that all other assembler instructions, for simplicity, take only 1 tick to execute.  Assume you have a 500 MHz (500 million ticks per second) processor.

Answer the following questions:

1.    How many ticks will it take for polling to load the file into RAM using byte mode?

2.    How many ticks will it take for interrupts to load the file into RAM in block mode?

3.    Compare the impact in percentage of processing time for the above calculations

a.    Where does polling lose all its time compared to where interrupts lose all its time?

4.    Assuming DMA has an overhead of 1000-ticks and can transfer the entire file directly to RAM without needing additional help from the CPU:

a.    Calculate the number of ticks it will take to load the file into RAM.

b.    Calculate the impact on percentage of processing time.

c.    Calculate the impact on running time in absolute real terms (ie. Time to wait for the file to be loaded)

d.    Where does the DMA lose all its time?

e.    How does DMA compare with polling and interrupts?

WHAT TO HAND IN

Hand in the following to MyCourses:

-     The MARS source code for question one, called mini4.asm

-      A PDF of the question two solutions, called mini4Q2.pdf

-      If you have trouble loading this on myCourses, you can ZIP all the files into mini4.zip.

HOW IT WILL BE GRADED

This assignment is worth 20 points.

Point Deductions:

-      For not following assignment instructions: -3 points.

-      Your program must execute to be graded (part marks will be given if it executes).

Important that students did not usesyscalls for character and string I/O: -5 points. This is the case everywhere in their program for this assignment. They must use the drivers and functions instead.

Points Awarded:

Question 1

Uses MARS

: 1

point

GETCHAR

: 2

point

Register-based

PUTCHAR

: 2

points

Register-based

GETS

: 2

points

Stack-based

PUTS

: 2

point

Stack-based

main()

: 2

point

Question 2

2.1

: 1

point

2.2

: 1

point

2.3

: 1

point

2.3.a

: 1

point

2.4.a

: 1

point

2.4.b

: 1

points

2.4.c

: 1

point

2.4.d

: 1

point

2.4.e

: 1

point

TA GRADING INSTRUCTIONS

Grade the student’s program only with the MARS emulator provided from myCourses.

-      10% off per day late, max 2 late days.

-      If the student submits a waiver, record the waiver in the spreadsheet. They can only use the waiver once. If this is a second time, then ignore the waiver.

-      Remember to award grades proportionally to the students, this means if the student got a question half correct then they receive half of the points.

-      Award the score to the student by comparing their work with the solution sheet.

发表评论

电子邮件地址不会被公开。 必填项已用*标注