代做CSCI 2500 — Computer Organization Fall 2023 Test 2 A代写Processing

- 首页 >> OS编程

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 val : . word 4

3

4 . text

5 . globlmain

6

7 main :

8 sub $sp , $sp , 4

9 sw $ra , 0 ( $sp )

10 la $a0 , v al

11 lw $a0 , 0 ( $a0 )

12 jal func

13 move $a0 , $v0

14 li $v0 , 1

15 syscall

16 lw $ra , 0 ( $sp )

17 add $sp , $sp , 4

18 li $v0 , 10

19 syscall

20

21 func :

22 addi $sp , $sp , —8

23 sw $ra , 4 ( $sp )

24 sw $a0 , 0 ( $sp )

25

26 slti $t0 , $a0 , 1

27 bne $t0 , $zero , L1

28

29 addi $v0 , $zero , 1

30 addi $sp , $sp , 8

31 jal $ra

32

33 L1 :

34 addi $a0 , $a0 , —1

35 jal func

36

37 lw $a0 , 0 ( $sp )

38 lw $ra , 4 ( $sp )

39 addi $sp , $sp , 8

40 mul $v0 , $a0 , $v0

41 jr $ra

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 AND B

❼ NOT A

❼ A + B (addition)

For extra credit, implement the following additional modes:

❼ (3 points) A - B (subtraction)

❼ (3 points) A DIV4 (integer divide A by four using arithmetic shift right, i.e., the most significant bit should be filled with the sign bit of A)

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 according to the IEEE 754 standard. Compute the sum of the floating point values:

0xc1e00000 and 0x40700000

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 sin(x) by tabulation:

❼ Implement this as a function labeled sin. 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 [0; 3.0] radians.

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

❼ 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: 7.75, 263.0, -0.875, 0.0, -∞. You must follow these requirements:

❼ Use the minimal number of bits in each field.

❼ Use Excess-M (biased) notation for the exponent.

❼ Significand is always normalized.

❼ Fraction has 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.





站长地图