代做CSCI 2500 — Computer Organization Fall 2023 Test 2 C

- 首页 >> Matlab编程

CSCI 2500 — Computer Organization

Fall 2023 Test 2 (November 14, 2023)

1. (20 POINTS)

Recall that perfect squares between 1 and 100 are as follows: 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

Part a: (12/20 points) Write MIPS code to determine whether a given unsigned integer (passed as an argument) is a perfect square or not:

❼ Implement this as a procedure labeled issquare. The procedure must return 1 if a perfect square and 0 otherwise.

❼ You may assume the argument belongs to the range [1; 100].

❼ You must hardcode the list of perfect squares in the data segment.

❼ Your implementation must use register $t0 but no other t-registers. (You may use any of the s-registers, if necessary.)

❼ Make sure you follow all register usage conventions and save certain registers on the stack when it is required.

Part b: (8/20 points) Consider the following code of the main procedure which calls your

issquare: .data squares: .word 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 square_str: .asciiz "A PERFECT SQUARE\n" not_square_str: .asciiz "NOT A PERFECT SQUARE\n" .text .globl main main: # 1 li $v0, 5 # read_int syscall move $a0, $v0 jal issquare beq $v0, $zero, s_ns la $a0, square_str j print s_ns: la $a0, not_square_str print: li $v0, 4 # print_str syscall # 2 jr $ra

Fill in the code below comment lines #1 and #2 to save/restore registers on the stack, when required.

Optional extra credit part c: (5 points) Write an alternative implementation of issquare which does not hardcode perfect squares and therefore works for any value of the argument.

2. (20 POINTS)

Consider the following MIPS code:

1 . data 2 v al : . word 4 3 4 . t e x t 5 . g l o b l main 6 7 main : 8 sub $sp , $sp , 4 9 sw $ra , 0 ( $sp ) 10 l a $a0 , v al 11 lw $a0 , 0 ( $a0 ) 12 j a l func 13 move $a0 , $v0 14 l i $v0 , 1 15 s y s c a l l 16 lw $ra , 0 ( $sp ) 17 add $sp , $sp , 4 18 l i $v0 , 10 19 s y s c a l l 20 21 func : 22 addi $sp , $sp , —8 23 sw $ra , 4 ( $sp ) 24 sw $a0 , 0 ( $sp ) 25 26 s l t i $t0 , $a0 , 1 27 bne $t0 , $ze r o , L1 28 29 addi $v0 , $ze r o , 1 30 addi $sp , $sp , 8 31 j a l $r a 32 33 L1 : 34 addi $a0 , $a0 , ❂1 35 j a l func 36 37 lw $a0 , 0 ( $sp ) 38 lw $ra , 4 ( $sp ) 39 addi $sp , $sp , 8 40 mul $v0 , $a0 , $v0 41 j r $r a

Part a: (2/20 points) Show the output printed by this code when it is run as is.

Part b: (8/20 points) Unfortunately, this code has two bugs. In a few sentences, give a detailed verbal description of what this code was supposed to do. Do not describe what this code actually does, and do not describe the bugs here. Be specific and provide sufficient details in your description. Also, name the algorithm that this code was intended to implement.

Part c: (4/20 points) Propose a fix that would correct all bugs in this code. Make sure that you do not make any unnecessary changes. Only fix the bugs and do not attempt to re-implement the parts of code that are working correctly.

You do not have to rewrite the entire code. You may just mark your changes directly in the code listed above.

Part d: (6/20 points) Show the output printed by this code after you fixed it.

3. (15 POINTS) You are given the following Boolean function:

      _    _              _       _ _ _        _       _

F = A B C D + A B C D + A B C D + A B C D

Part a: (15/15 points) Use K-map method to produce a minimal (i.e., using the smallest number of terms and variables) Boolean formula for F. For full credit, show all work, including the tables/groupings for the K-map method but do not forget that the final result is a Boolean formula.

Optional extra credit part b: (5 points) Express the same function as a Product of Sums using only algebraic transformations (i.e., only applying axioms, laws, theorems, and identities of Boolean algebra).

Optional extra credit part c: (5 points) Prove that your solutions for parts (a) and (b) correspond to the same Boolean function and that it is the same as function F given in this problem. Note that this proof cannot rely on the correctness of your solutions for parts (a) and (b), i.e., it has to be independent from your solutions for those parts.

4. (15 POINTS)

Consider the following circuit:

where

represents a 2-input multiplexor (selector bit is at the bottom, inputs are on the left) and

represents a 7-segment display that outputs a hexadecimal value (0 to f) encoded by its four binary inputs.

Describe how this circuit works and what its function is. Make sure to consider different values of A- and S-inputs of the circuit. Support your description with the relevant tables, timing diagrams, etc.

5. (20 POINTS)

Design a 5-bit ALU that supports the following modes of operation:

❼ A OR B

❼ A XOR B

❼ A + B (addition)

For extra credit, implement the following additional modes:

❼ (3 points) |A - B| (absolute value of the difference of A and B)

❼ (3 points) A MUL 4 (multiply A by four using shift left

Your ALU should have at least the following inputs and outputs:

❼ Inputs:

– Cin (incoming carry bit)

– A (five bits, interpreted as a 2’s complement signed or unsigned integer)

– B (five bits, interpreted as a 2’s complement signed or unsigned integer)

❼ Outputs:

– Cout (outgoing carry bit)

– R (five bits of the result, interpreted as a 2’s complement signed or unsigned integer)

For extra credit, implement the following additional outputs:

– (1 point) Eq a single bit output which is 1 when A is equal to B, 0 otherwise

– (1 point) SgnA a single bit output which is 1 when A is negative, 0 otherwise

– (2 points) OnesA a multi-bit output interpreted as an unsigned integer representing the number of 1’s in A. You need to determine the number of bits in OnesA yourself. OnesA should have the minimal number of bits necessary.

– (5 points) OVFL a single bit output which is 1 when an arithmetic operation resulted in the overflow, 0 otherwise

You may introduce additional inputs and/or outputs, as necessary.

(a) You are allowed to use any gates and components that we reviewed in class. It is also OK to use any components that appeared in our course textbook/zyBooks.

(b) You may define your own components and then use them.

(c) You must assume signed values for all arithmetic operations and comparison (Eq).

(d) The mode of operation of the ALU should be determined by the Operation control bus (several wires of the form. OpnOpn−1...Op0 that together define the mode). You need to use the minimal number of wires in the Operation bus. Also, you are not allowed to have any other separate control signals, like Ainvert, Binvert, etc. If you need any such control signals, they have to be produced inside your ALU from OpnOpn−1...Op0. Make sure you provide a table (legend) that shows how modes correspond to Operation bits. Draw the circuit diagram of your ALU below. Make sure that you circuit is well organized, drawn neatly, all connections are straight lines that go either vertically, horizontally, or at a 45deg angle, and that all signals and components are clearly labeled. You will lose points if your drawing is sloppy or hard to read.

6. (10 POINTS) For this question, you must show all work to receive credit! All computations must be done in binary form. and by hand. This is not a coding question! You may double check your answers by performing the computation in decimal form.

Assume two hexadecimal 32-bit words represent single precision floating point values accord-ing to the IEEE 754 standard. Compute the sum of the floating point values:

0xbfe00000 and 0xc0f00000

and encode the result as a hexadecimal 32-bit word also in single-precision IEEE 754 format.

7. Optional extra credit (20 POINTS)

Write MIPS code to compute the value of log2(x)by tabulation:

❼ Implement this as a function labeled log2. The function must take a single-precision floating point value and return a single-precision floating point value.

❼ You may assume the argument belongs to the range [1.0; 121.0].

❼ You need to hardcode (tabulate) the values of log2 for each value of the argument in the data segment according to the following table:

x               log2(x)

1.0000       0.0000

11.0000     3.4594

21.0000     4.3923

31.0000     4.9542

41.0000     5.3576

51.0000     5.6724

61.0000     5.9307

71.0000     6.1497

81.0000     6.3399

91.0000     6.5078

101.0000   6.6582

111.0000   6.7944

121.0000   6.9189

❼ If the value of x given to your function as an argument is not exactly equal to the values of x in the table above, choose closest x from the table.

❼ Make sure you follow all register usage conventions and save certain registers on the stack when it is required.

8. Optional extra credit (20 POINTS) For this question, you must show all work to receive credit!

Part a: (15/20 points) Design a floating-point notation required to represent the following numbers exactly, i.e., without any representation error: 0.625, 1024.0, -0.125, 0.0, +∞, -∞, N aN. You must follow these requirements:

❼ Use the minimal number of bits in each field.

❼ Use sign-magnitude (SM) notation for the exponent.

❼ Significand is always normalized.

❼ Fraction does not have a hidden bit.

Make sure to specify all necessary details of your solution, e.g., the number of bits for each field, the value of M in case of Excess-M notation, etc. Note that you need to design your own notation, so it won’t be one of IEEE 754 formats.

Part b: (5/20 points) Show how the numbers given above would be represented in your notation. For each number provide all bits for each of the fields.






站长地图