EEE 105 Machine Problem 1: 1 Specifications

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

EEE 105 Machine Problem 1

Floating Point Calculator

1 Specifications

Implement a single precision floating point calculator using MIPS. The calculator can perform the four basic
operations: addition, subtraction, multiplication, and division.
The two 32-bit inputs are pre-stored at addresses 0x10010000 and 0x10010004 using a combi-
nation of the .data and .float directives. An example of using these directives is shown in listing 1.

Code 1: Using .data and .float to pre-store inputs

.data
.float
a : 5 .5 # 0 x40b00000 ( IEEE -754 format , stored in 0 x10010000 )

The results should follow the IEEE-754 standard, and should be stored in the memory addresses
0x10010020 through 0x1001002c, i.e. one word each for the sum, difference, product, and quotient - in
this order.
The calculator should be able to handle denormal numbers as described in sec. 1.1.
Multiplication and division operations should be performed strictly following the sequential multi-
plication and non-restoring division algorithms, described in Tables 2 and 3, respectively.

1.1 Denormal Numbers

Whenever an overflow occurs, the calculator should output an infinity. Moreover, NaNs should also be set
as an output whenever an invalid operation is performed (e.g. 0/0, (+∞) + (−∞) ,etc). For simplicity, your
calculator should simply truncate any excess bits. Table 1 summarizes the special cases the calculator needs
to handle.

Input Result
(+∞) + (+∞) or (+∞) − (−∞) (+∞)
(−∞) + (−∞) or (−∞) − (+∞) (−∞)
(+∞) − (+∞) or (−∞) + (+∞) NaN
(+∞) · (+∞) or N · (+∞) (+∞)
(−∞) · (+∞) or −N · (+∞) (−∞)
N ÷ 0 or ∞ ÷ 0 or 0 ÷ 0 or ∞ · 0 NaN

Table 1: Special cases involving denormal numbers.

Page 1 of 4
Operand A = 1 0 1 1 Operand B = 1 1 0 1
Product, with carry-out Remarks
000000000 Initialize
000001101 Load operand B to Product Low.
00 0 0 01101 Check last bit of product, if 1, add Operand A to
+ 1 0 1 1 Product High; else add zero to Product High.
01 0 1 11101
00 1 0 11110 Shift right, shift in bit is 0. Discard shift out bit.
00 1 0 11110 Check last bit of product, if 1, add Operand A to
+ 0 0 0 0 Product High; else add zero to Product High.
00 1 0 11110
00 0 1 01111 Shift right, shift in bit is 0. Discard shift out bit.
00 0 1 01111 Check last bit of product, if 1, add Operand A to
+ 1 0 1 1 Product High; else add zero to Product High.
01 1 0 11111
00 1 1 01111 Shift right, shift in bit is 0. Discard shift out bit.
00 1 1 01111 Check last bit of product, if 1, add Operand A to
+ 1 0 1 1 Product High; else add zero to Product High.
10 0 0 11111
01 0 0 01111 Shift right, shift in bit is 0. Discard shift out bit.
010001111 Done. Discard the most significant bit (carry-out).

Table 2: 4-bit sequential multiplication example showing 0b1011(11) × 0b1101(13) = 0b10001111(143)

Operand A = 1110 Operand B = 0 0 1 1


Remainder Quotient Array Remarks
00000 0000 Initialize.
00000 1110 Load operand A to the array.
0 0 0 0 01110 Check sign bit of array (0).
0 0 0 0 1110 Shift left. If sign bit earlier was 0, subtract Operand B;
+1 1 1 0 1 else, add Operand B.
1 1 1 1 01100 Shift in bit is 0 if sign bit of result is 1.
1 1 1 1 01100 Check sign bit of array (1).
1 1 1 0 1100 Shift left. If sign bit earlier was 0, subtract Operand B;
+0 0 0 1 1 else, add Operand B.
0 0 0 0 01001 Shift in bit is 1 if sign bit of result is 0.
0 0 0 0 01001 Check sign bit of array (0)
0 0 0 0 1001 Shift left. If sign bit earlier was 0, subtract Operand B;
+1 1 1 0 1 else, add Operand B.
1 1 1 1 00010 Shift in bit is 0 if sign bit of result is 1.
1 1 1 1 00010 Check sign bit of array (1).
1 1 1 0 0010 Shift left. If sign bit earlier was 0, subtract Operand B;
+0 0 0 1 1 else, add Operand B.
1 1 1 1 10100 Shift in bit is 0 if sign bit of result is 1.
111110100 Check sign bit of array (1).
111110100 If sign bit earlier is 1, perform final addition to
+00011 Operand B; else, retain.
00010 0100 Done. Low half is Quotient. Upper is Remainder.

Table 3: 4-bit non-restoring division example showing 0b1110(14) ÷ 0b0011(3) = 0b0100(4) rem 0b0010(2)

Page 2 of 4
1.2 Restrictions

You are not allowed to use any floating point instructions, as well as pseudo-instructions. As mentioned
earlier, all multiplication and division operations are to be implemented using their respective algorithms.

You may, however, use floating point instructions for verification purposes only. Results from
these operations will be available in the Coproc 1 tab located beside the Registers tab. You may store the
results from these floating point instruction in memory addresses 0x10010040 through 0x1001004C for
easy comparison.

Important note: MIPS floating point instructions perform rounding off, while your calculator simply
truncates excess bits. This may cause some discrepancies between your result and the one generated by the
MIPS floating point instructions.

1.3 Submission

Upload your .asm file to the MP1 folder for your lab section with the filename <student number>-MP1.asm.
You are only allowed to upload one file. DO NOT upload archives (e.g. ZIP, RAR, etc.)

Make sure that you finalize your submission before checking. Drafts will not be graded.

1.4 Other Notes

Try to optimize your code by using subroutine calls. Subroutines are generally used for implementing
procedures that are repetitive. It is also better if the four operations have their own subroutines, which the
main program will call.

2 Grading

Your final grade for this MP has two components. You earn a base grade (Sec. 2.1) depending on how many
test cases your calculator is able to solve correctly, but points may be deducted depending on how you answer
the Q&A (Sec. 2.2).

2.1 Base Grade

There will be ten (10) cases to be provided during checking. The weight of each operation is specified in
Table 4.

Operation Points per case Total


Addition 0.5 5
Subtraction 0.5 5
Multiplication 2.5 25
Division 2.5 25
Total base grade 60

Table 4: Base grade breakdown.

Points will be determined depending on how far your output is from the expected output (which
takes truncation into account, i.e. not the result of the MIPS floating point instructions). For every erroneous
bit in the final result of each, a 0.5-point deduction will be applied. However, the maximum deduction will
be limited by the weight of each test case, i.e. 4 erroneus bits on an addition will result in a 0 for that test
case, while the same number of erroneous bits on a multiplication will result in a 0.5.

Page 3 of 4
2.2 Q&A

You must sign-up for a Q&A slot. See Sec. 2.2.2 for details.

2.2.1 Grading

During checking, you will be asked some questions about your code and how it works (or doesn’t work, for
that matter). Up to 3 points per unanswered/incorrectly answered question will be deducted, depending on
the level of the question. Although you cannot earn points from the Q&A, it is a necessary part of your MP,
because no Q&A, no grade.
The questions will also vary from student to student, as the focus of the Q&A is not the correctness
of operation (which is addressed by the base grade) but the understanding of the programmer. Understanding
your own code should come naturally if you wrote it, so the Q&A should be no problem.

Therefore, it is better to submit non-working code you wrote yourself than it is to submit working
code you did not write yourself. It is, of course, best to submit working code you wrote independently.
In this vein, please be informed that software will be employed as an aid in detecting plagiarized
code. While we do not believe you have the intention to cheat in the first place, there are many reasons
why one may be tempted to. For instance, you may have other deadlines around the same date, or your
instructors (us!) did a poor job in equipping you to solve the problem, or maybe life just happens. These are
not valid excuses to cheat, and cheating will still be seriously dealt with regardless of the underlying reason.
We hope you treat this note not as a warning, but more of an encouragement to ask for help if you
are having trouble. But of course, if everybody asks for help very close to deadline, we may not have enough
time to adequately address all of your concerns, so please start early so you can ask early. You need
not wait for the lab meetings to ask and may use our online channels.

2.2.2 Signing up for a Q&A slot

We will use the tool titled MP1 Checking Sign-up under the Machine Problem tab on UVLê. The day
before a lab session, the sign-up tool will open and you may choose 1 slot. If you would like to change your
slot, or if you missed it, you may book another one, provided there are still slots available.

As an attempt to make earlier timeslots a little more attractive on the last day of checking, the
first 10 will get 1 bonus point.

Make sure that your submission is final, NOT DRAFT, before your checking time slot.

3 Deadline

You have 4 weeks to work on this MP, the first week being spec release. The next two weeks will be open
lab sessions, and you are strongly encouraged to come to class and work on your MP. You may want to think
of it this way: your MP is divided into smaller lab exercises that you need to submit as weekly milestones.
You may have your MP checked as soon as you finish it (checking will be done during lab sessions,
see Sec. 2.2.2). Submissions made earlier will be given bonus points, as specified in Table 5.

Week Lab session Early Bird Bonus


1 Spec Release -
2 Open lab 6
3 Open lab 3
4 DEADLINE 1, for the first 10

Table 5: MP1 schedule.

There will be NO LATE CHECKING, so again, start early!

Page 4 of 4

You might also like