Cisc 530 Midterm Fall 2022-1
Cisc 530 Midterm Fall 2022-1
Solution :
IEEE-754 standard define a single (32 bits) and double (64 bits) precision float point format
as follows:
Since the first bit to the (most significant bit) is zero, the value is unsigned (or non-negative
or positive)
2. Assume $t0 holds the value 0x10101000 and $t1 0x00101001. What is the
value of $t0 after the following instructions?
Solution:
Instruction slt $t2,$0,$t0 tells the CPU to compare the content of register $0 and the
temporary register $t0. If $0 is less than $t0, the temporary register $t2 is set to a value
of 1. Otherwise, register $t2 is set to 0 (see page 99 HP MIPS 6th edition; section 2.7
Instructions for Making Decisions)
We also know that register $0 is hardwired to be always zero (0).
$t0 = 0x10101000 = 27+ 25+ 23 = 128 + 64 + 8 = 200
Obviously, $0 or 0 is less than $t0 or 100. Thus, $t2 will be set to a value of 1.
Instruction bne $t2,$0,ELSE tells the CPU to compare the temporary register $t2 to
the zero register $0. If the two registers are not equal, jump to the instruction at the ELSE
label. Indeed, zero (0) is not equal to (1), the PC is set to the location of ELSE and continue.
Instruction addi $t0, $t1, 5 adds a value of 5 to the temporary register $t1 and
store the result into the same register $t0. Since $t2 has a 1, thus, after the execution of
this instruction, register $t0 has a value of 6.
Answer: $t0 = 6
Solution :
The most significant digit has a value of f*167 where the hexadecimal value of f is
15.
- The least significant digit has a value of 2*160.
feab010116= 15 * 167 + 14 * 166 + 10 * 165 + 11* 164 + 0*163 + 1*162 + 0*161 + 1*160
= 4026531840 + 234881024 + 10485760 + 720896 + 0 +256 + 0 + 1
= 4272619777
4. For the following C statement, what is the corresponding MIPS assembly code?
Assume that the variables f, g, h, i, and j are assigned to registers $s2, $s3,
$s5, $s6, and $s7, respectively. Assume that the base address of the arrays D
and C are in registers $s0 and $s1, respectively.
D[12] = C[i*j]
Solution:
- Assume that the type is int that requires a word or four (4) bytes.
5. Consider three different processors C1, C2, and C3, executing the same
instruction set:
• C1 has a 1.5 GHz clock rate and a CPI of 2.1
• C2 has a 4.5 GHz clock rate and a CPI of 1.2
• C3 has a 1.1 GHz clock rate and has a CPI of 2.1
a. Which processor has the poorest performance expressed in instructions per
second?
b. If the processors each execute a program in 12 seconds, find the number of
cycles and the number of instructions.
c. We are trying to reduce the execution time by 31% but this leads to an
increase of 19% in the CPI. What clock rate should we have to get this time
reduction?
Solution:
a)
Instructions per second = 𝑐𝑙𝑜𝑐𝑘 𝑟𝑎𝑡𝑒𝑐𝑦𝑐𝑙𝑒𝑠 𝑝𝑒𝑟 𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛
GHz: 109 Hertz or cycles per second
• • C1: instructions per second = 1.5 × 109 / 2.1 = 0.79×109
b)
Number of cycles in 12 seconds = 12 × 𝑐𝑙𝑜𝑐𝑘 _𝑟𝑎𝑡𝑒
Number of instructions = 𝑛𝑢𝑚𝑏𝑒𝑟 _𝑜𝑓 _𝑐𝑦𝑐𝑙𝑒𝑠/ 𝑛𝑢𝑚𝑏𝑒𝑟 _𝑜𝑓 _𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠 _𝑝𝑒𝑟 _𝑐𝑦𝑐𝑙𝑒 _
In 12 seconds,
c)
It used to take 12 seconds to run and now it takes only 8.28 seconds, a 31% reduction in
execution time.
CPInew = 1.19 x CPUold: It takes more cycles to execute an instruction with the new
architecture.
Clock rate = 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠 × 𝑐𝑦𝑐𝑙𝑒𝑠 𝑝𝑒𝑟 𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑡𝑖𝑚𝑒 𝑡𝑜 𝑟𝑢𝑛 (𝑠𝑒𝑐𝑜𝑛𝑑𝑠)
a. Find the average CPI for each program given that the processor has a clock
cycle time of 1.3ns
b. Assume the compiled programs run on two different processors. If the
execution times on the two processors are the same, how much faster is
the clock of the processor running compiler B's code versus the clock of
the processor running compiler A's code?
c. A new compiler is developed that uses only .7E9 instructions and has an
average CPI of 1.3. What is the speedup of using this new compiler versus
using compiler A or B on the original processor?
Solution:
a)
With a clock cycle of 1.3 ns (nanosecond) (10-9), we have a clock rate of 1x109 cycles
per second or Hz
𝐶𝑃𝐼 (𝑐𝑦𝑐𝑙𝑒𝑠 𝑝𝑒𝑟 𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛)=𝑒𝑥𝑒𝑐𝑢𝑡𝑖𝑜𝑛 𝑡𝑖𝑚𝑒 × 𝑐𝑙𝑜𝑐𝑘 𝑟𝑎𝑡𝑒/𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠
b)
𝑠𝑝𝑒𝑒𝑑A/𝑠𝑝𝑒𝑒𝑑B=1.5×109 /3.75×109=0.4
c)
Solution :
/**
Generate a mips gcc 5.4 assembly code for the following C code. Copy
the mips assembly code into a file.
Fix it up so that you can run using JsSpim software located here:
*/
int special_formula(int f1, int f2, int f3, int f4, int f5) {
int f9 = 1234;
int main() {
int f1 = 123;
int f2 = 456;
int f4 = special_formula(12.0, 11.0, f1, f2, 0.5);
}
Generate a mips gcc 5.4 assembly code for the following C code. Copy the mips
assembly code into a file.
Fix it up so that you can run using JsSpim software located here:
https://shawnzhong.github.io/JsSpim/.
You can also use QtSPIM installed on your VM instead.
Describe thoroughly the state of $sp, $fp and related registers and memory
content (pointed by $sp and $fp).
It is best to simply copy and paste screen using Windows Snipping or the like.
Or
Solution
Useful formulas
clock rate
Instructions per second =
cycles per instruction
number of cycles
Number of instructions =
number of instructions per cycle