CS170
The following High-level code counts the number of 1's in a 32-bit number. int count = 0; while (num != 0) { if (num & 0x1) // if lsb is 1(num and 0x1) count = count + 1; num = num >> 1; } What is the MIPS assembly code?
# $a0 = num, $v0 = count add $v0, $0, $0 # count = 0 count: beq $a0, $0, done # if num == 0, done andi $t0, $a0, 0x1 # $t0 = num AND 0x1 beq $t0, $0, shift # if 0, only shift addi $v0, $v0, 1 # count = count + 1 shift: srl $a0, $a0, 1 # num = num >> 1 j count done:
Assume $t0 holds the hexadecimal value 00101000. What is the value of $t2 after the following instructions? slt $t2, $0, $t0 bne $t2, $0, ELSE j DONE ELSE: addi $t2, $t2, 2 DONE:
$t2 = 3
What is true about parallel programming?
- The number of cores increases. - Hardware executes multiple instructions at once. - Programmers use it because they want theirs programs to run faster.
Convert the following two's complement binary number to decimal. 110110
-10
Convert the following two's complement binary number to decimal. 1110
-2
Convert the following two's complement binary number to decimal. 100011
-29
Assume a 20 cm diameter wafer has a cost of 15, contains 100 dies, and has 0.031 defects/cm 2. What is the cost per die? 0.0903 0.031 0.1650 0.9093
0.1650
Assume a 20 cm diameter wafer has a cost of 15, contains 100 dies, and has 0.031 defects/cm 2. If the number of dies per wafer is increased by 10% and the defects per area unit increases by 15%, what is the yield? 3.14 0.9093 1.650 0.9082
0.9082
Assume a 20 cm diameter wafer has a cost of 15, contains 100 dies, and has 0.031 defects/cm 2. What is the yield for the wafer? 0.0903 0.031 3.14 0.9093
0.9093
What is the machine code for the following j assembly instruction. Instruction addresses are given to the left of each instruction. 0x00403004 back: . . . . . . 0x0040400C j back
000010 00 0001 0000 0000 1100 0000 0001 = 0x08100C01
What is the machine code for the following beq assembly instruction. Instruction addresses are given to the left of each instruction. 0x00401000 beq $t0, $s1, Loop 0x00401004 . . . 0x00401008 . . . 0x0040100C Loop: . . .
000100 01000 10001 0000 0000 0000 0010 = 0x11110002
Convert the following decimal number to 8-bit two's complement number. 42
00101010
Convert the following hexadecimal number to unsigned binary. 3B
00111011
Convert the following MIPS assembly code into machine language. add $t0, $s0, $s1 What is the instruction in hexadecimal?
02114020
Convert the following MIPS assembly code into machine language. sub $t1, $s7, $s2 What is the instruction in hexadecimal?
02F24822
Consider the following MIPS assembly language snippet. The numbers to the left of each instruction indicate the instruction address. 0x00400028 add $a0, $a1, $0 0x0040002C jal f2 0x00400030 f1: jr $ra 0x00400034 f2: sw $s0, 0($s2) 0x00400038 bne $a0, $0, else 0x0040003C j f1 0x00400040 else: addi $a0, $a0, −1 0x00400044 j f2 What is the addressing mode used at each line of code?
0x00400028 add $a0, $a1, $0 # register only 0x0040002c jal f2 # pseudo-direct 0x00400030 f1: jr $ra # register only 0x00400034 f2: sw $s0, 0($s2) # base addressing 0x00400038 bne $a0, $0, else # PC-relative 0x0040003c j f1 # pseudo-direct 0x00400040 else: addi $a0, $a0, -1 # immediate 0x00400044 j f2 # pseudo-direct
What is the ASCII encoding for the following string (The answer is in hexadecimal): SOS
0x53 4F 53 00
Convert the following hexadecimal number to unsigned binary. A5
10100101
Convert the following decimal number to unsigned binary number. 42
101010
Perform the following addition of unsigned binary numbers. Indicate whether or not the sum overflows a 4-bit result. 1101 + 1011
11000
Convert the following decimal number to 8-bit two's complement number. -63
11000001
Perform the following addition of unsigned binary numbers. Indicate whether or not the sum overflows a 4-bit result. 1001 + 0100
1101
Convert the following hexadecimal number to unsigned binary. FFFF
1111111111111111
ASCII (American Standard Code for Information Interchange) contains ________.
128
There are four main components to the hardware. Memory accesses account for 20% of all instructions, integer arithmetic accounts for 10% of all instructions, conditionals account for 30% of all instructions, and jumps account for the rest. Assume the original execution time takes 200 seconds. Assuming integer arithmetic can be improved by a factor of 4, what is the new execution time?
185 seconds
Assume a 20 cm diameter wafer has a cost of 15, contains 100 dies, and has 0.031 defects/cm 2. If the number of dies per wafer is increased by 10% and the defects per area unit increases by 15%, what is the die area? 3.14 cm2 2.86 cm2 1.650 cm2 1.1 cm2
2.86 cm2
Consider the following MIPS loop: LOOP: slt $t2, $0, $t1 beq $t2, $0, DONE addi $t1, $t1, -1 addi $s2, $s2, 2 j LOOP DONE: Assume that the register $t1 is initialized to the value 10. What is the value in register $s2 assuming $s2 is initially zero?
20
Convert the following MIPS assembly code into machine language. addi $s0, $0, 73 What is the instruction in hexadecimal?
20100049
Convert the following MIPS assembly code into machine language. addi $s0, $0, −10 What is the instruction in hexadecimal?
2010FFF6
A task runs alone on a CPU. The task starts by running for 5 ms. The task then waits for 4 ms while the operating system runs some instructions to access disk. The CPU is then idle for 2 ms while waiting for data from disk. Finally, the task runs another 10 ms and completes. The elapsed time is ____ ms.
21 5 + 4 + 2 + 10 = 21. Elapsed time is the total time, also known as wall clock time or response time.
What is the largest unsigned 8-bit binary number?
255
Assume a color display using 8 bits for each of the primary colors (red, green, blue) per pixel and a frame size of 1280 × 1024. What is the minimum size in bytes of the frame buffer to store a frame? 3,932,160 bytes/frame 1,310,720 bytes/frame 1024 bytes/frame 1284 bytes/frame
3,932,160 bytes/frame
What is the largest 16-bit binary number that can be represented with two's complement numbers?
32768
Each array entry contains _______ .
4 bytes
Convert the following unsigned binary number to decimal. 110110
54
Convert the following hexadecimal number to decimal. 3B
59
How many different binary numbers can be represented with 16 bits?
65,536 numbers
What is the largest 16-bit binary number that can be represented with unsigned numbers?
65535
Convert the following unsigned binary number to hexadecimal. 000100010100111
8A7
Convert the following unsigned binary number to hexadecimal. 1010
A
Sequential Logic
A group of logic elements that contain memory and hence whose value depends on the inputs as well as the current contents of the memory
Combinational Logic
A logic system whose blocks do not contain memory and hence compute the same output given the same input.
High level language
A portable language such as C++, or Visual Basic that is composed of words and algebraic notation
Convert the following MIPS assembly code into machine language. sw $t1, −7($t2) What is the instruction in hexadecimal?
AD49FFF9
1-bit adder must have: Two inputs for the operands Single-bit output for the sum Second output to pass on the carry, called CarryOut All the above
All of the above
Transistor is:
An on/off switch controlled by an electric signal.
A program that translates a symbolic version of instruction into the binary version.
Assembler
clock cycles per instruction (CPI)
Average number of clock cycles per instruction
Assume the following register contents (in Hexadecimal): $t0 = AAAAAAAA, $t1 = 12345678 For the register values shown above, what is the value of $t2 in Hexadecimal for the following sequence of instructions? sll $t2, $t0, 4 or $t2, $t2, $t1
BABEFEF8
Personal Mobile Device (PMD)
Battery operated Connects to the Internet Hundreds of dollars Smart phones, tablets, electronic glasses
A program selected for use in comparing computer performance.
Benchmark
Register files
Can be used to build small memory Too costly to build large amount of memory
A program that translates highlevel language statements into assembly language statements.
Compiler
Server
Computer used for large workloads and usually accessed via a network
_____ memory is volatile.
DRAM
Output
Data that has been processed into a useful format. Reads data from memory
Input
Data that is entered into the computer system via an input or storage device. Writes data to memory
8 Ideas of Computer Architecture
Design for Moore's Law Use abstraction to simplify design Make the common case fast Performance via parallelism Performance via pipelining Performance via prediction Hierarchy of memories Dependability via redundancy
How should programmers write code to maximize the benefits of parallel programming?
Divide a program into sub-tasks so all processors run about the same amount of time Programmers decide how to divide a program into sub-tasks, and then schedule and coordinate sub-tasks to run on multiple processors. Programmers must be cautious that any benefit achieved by parallelism is not negated by the overhead of coordinating sub-tasks.
Indicate to which class each computing application belongs. A computer in a cardiac pacemaker, which delivers electric shocks to keep a human's heart beating properly.
Embedded
At Joe's Car Wash, a car enters the wash, and exits 5 minutes later (nice and clean). 5 minutes is the _________.
Execution time
Convert the following unsigned binary number to hexadecimal. 11110000
F0
$a0-$a3 hold the return value of a function and $v0-$v1 hold the arguments.
False
Calculating the 2's complement starts with adding 1 and followed by inverting the bits.
False
Compiler is a program that translates machine language statements into instructions that the hardware can execute.
False
In procedures, callee passes the arguments to caller.
False
MIPS has a 32 × 64-bit register file
False
Moore's Law states that integrated circuit resources double every 3-4 months.
False
Very large-scale integrated circuits combine dozens to hundreds of vacuum tubes into a single chip.
False Integrated circuits consist of transistors, not vacuum tubes.
Power is not a useful evaluation metric in the SPEC benchmarks.
False Power is a critical metric in the PostPC Era because of cooling costs and limited battery life. SPECpower_ssj2008 is a benchmark specifically developed to measure power.
A smaller SPECratio indicates better performance.
False The SPECratio is the inverse of execution time. Shorter execution times are desired, thus a larger SPECratio indicates better performance.
Very large-scale integrated circuits combine dozens to hundreds of vacuum tubes into a single chip.
False Integrated circuits consist of transistors, not vacuum tubes.
A typical computer display is made up of hundreds of pixels.
False Millions, not just hundreds, of pixels make up a display. Each pixel is barely visible alone. "Pixel" is short for "picture element".
An instruction set is a particular program provided in the language of a computer.
False The instruction set is the language itself, not a particular program. The language is like English, whereas a program is like a particular book written in English.
Types of memory elements
Flip-Flops Latches Registers Register Files SRAMS DRAMS
Each word in MIPS architecture representing ______ bytes.
Four
Operating system
Handling basic input and output operations Allocating storage and memory Scheduling tasks & sharing resources
A computer system consists of:
Hardware Systems software Applications software
Performance via prediction
In some cases it can be faster on average to guess and start working rather than wait until you know for sure Ex. Aircraft and marine navigation systems that incorporate wind information
The basic components of a computer are:
Input Output Memory Datapath Control
Instruction count
Instructions executed for the program
Performance via pipelining
It is an elegant technique that runs programs faster by overlapping the execution of instructions Ex. Assembly lines in automobile manufacturing
MIPS was developed by __________.
John Hennessy and David Patterson
Cloud Computing refers to:
Large collections of servers that provide services over the Internet.
A systems program that combines independently assembled machine language programs and resolves all undefined labels into an executable file.
Linker
A systems program that places an object program in main memory so that it is ready to execute.
Loader
Make the common case fast
Making the common case fast will tend to enhance performance better than optimizing the rare case. Ex. Express elevators in buildings
Datapath
Performs computations
Stuff about pixels
Pixel is the smallest individual picture element. Screens are composed of millions of pixels. A color display might use 8 bits for each of the three colors (red, blue, and green) If we used 24 bits per pixel, we could display millions of different colors
Voltage = 4 V, frequency = 1 GHz, and power = 3 W. Frequency is increased to 6 GHz. What is the new power?
Power = k×Voltage^2×Frequency= (3 / (16×109) ) × 42 × (6×109) = 18W
What is the type, assembly language instruction, and binary representation of instruction described by the following MIPS fields: op=0, rs=3, rt=2, rd=3, shamt=0, funct=34
R-type sub $v1, $v1, $v0 00621822 again, I have no idea
Output
Reads data from memory Ex. display
CPU execution time for a program
Seconds for the program
Clock cycle time
Seconds per clock cycle
Control
Sends signals that determine the operation of the other components
Indicate to which class each computing application belongs. A computer at a federal laboratory that continually executes sophisticated algorithms on massive amounts of data from various weather stations to develop accurate weather forecasts.
Server
Select the underlying design principle(s) for MIPS architecture
Simplicity favors regularity Make the common case fast Smaller is faster Good design demands good compromises
Dependability via redundancy
Since any physical device can fail, we make systems dependable by including redundant components that can take over when a failure occurs and to help detect failures. Ex. Suspension bridge cables
Application Software
Software that performs some useful task such as word processing or playing a game for a user.
Systems software
Software that provides services that are commonly useful, including operating systems, compilers, loaders, and assemblers.
nonvolatile memory
Storage that retains data even when powered down (such as flash memory, hard disk, or DVD storage).
Memory
Stores instructions and data
Assembly language
Textual representation of instructions
Hierarchy of Memories
The fastest, smallest, and most expensive memory per bit at the top of the hierarchy and the slowest, largest, and cheapest per bit at the bottom. Ex. Library reserve desk
At Joe's Car Wash, a car enters the wash, and exits 5 minutes later. However, 1 minute after a car enters, the next car can enter. Thus, once full, the car wash outputs 1 clean car per minute. 1 car per minute is the _________.
Throughput
Compiler
Translates high-level language into assembly language.
Assembler
Translates the assembly language into machine language
$ra holds the return address after a jal instruction.
True
Carry lookahead adder is faster than ripple carry adder.
True
Computers make novel applications feasible.
True
In MIPS, NOT is implemented using a NOR with one operand being zero.
True
In signed numbers, positive numbers have 0 in the most significant bit, and negative numbers have 1 in the most significant bit.
True
Just In Time compiler (JIT) is a compiler that operates at runtime, translating the interpreted code segments into the native code of the computer.
True
Loops are used to compute part(s) of the program multiple times.
True
Non-volatile secondary memory is cheaper than main memory.
True
Register 0 ($0) always holds the constant 0.
True
The algorithm is the steps to solve the problem.
True
The instruction slt is used to compare two integers.
True
To speed up the addition, we need to determine the CarryIn to the high order bits sooner.
True
For a given number of instructions, assume CPI is increased by 20%, and clock cycle time is decreased by 10%. The program execution time decreases.
True 1 × (1 + 0.20) × (1 - 0.10) = 1.08 If instruction count remains the same, CPI increases by 20%, and clock cycle time decreases by 10%, then the program execution time increases by 8%.
A workload is typically a set of benchmarks.
True Most computers execute more than one program. A workload specifies both the set of benchmarks and the relative frequency that benchmarks are executed, to better evaluate different computers.
A clock rate of 1 GHz corresponds to a period of 1 nanosecond, which is 1x10-9 seconds.
True The clock period is the inverse of the clock rate, so 1 / (109) = 1x10-9, which is 1 nanosecond.
Suppose all the registers are used and the values are still needed. Now suppose you need to save another value, but there is no open register to use. What do you do?
Use stack
Use abstraction to simplify design
We use abstractions (simplified versions of something technical) to represent the design at different levels of representation Ex. Building self-driving cars whose control systems partially rely on existing sensor systems already installed into the base vehicle, such as lane departure systems and smart cruise control systems
Volatile memory (RAM)
When the power goes off the data disappears Ex. DRAM
Input
Writes data to memory Ex. keyboard
The fundamental building block of memory is ___________.
a bistable element (an element with two stable states)
Silicon is _____.
a common element found in sand Silicon is plentiful and cheap, and in fact is the main element in glass and mirrors. Importantly for chips, silicon has the desirable feature of being a semiconductor, modifiable into a good insulator or a good conductor.
Embedded computer
a computer inside another electrical device
Flip flop
a digital circuit that has two states, ON or OFF, that can be used to store a 1 or a 0. It is the fundamental unit of computer memory.
Synchronous System
a memory system that employs clocks and where data signals are read only when the clock indicates that the signal values are stable
We use (blank) to represent the design at different levels of representation.
abstractions
For the following C statement, what is the crosponding MIPS assembly code? Assume that the variables f, g and h have already been placed in registers $s0, $s1, ans $s2, respectively. f = g + (h − 5);
addi $s0, $s2, -5 add $s0, $s0, $s1
A program to play tic-tac-toe.
application software
Personal Computer (PC)
computer designed for general use by a single person
DRAM
dynamic random access memory - uses a capacitor - much denser than SRAM - slower than SRAM - cheaper than SRAM - needs to be refreshed periodically - used for computer main memory
What is a single C statement corresponds to the following two MIPS assembly instructions, add f, g, h add f, i, f
f = g+h+i
An N-bit register is a bank of N __________ that share a common CLK input
flip flops
The instruction beq register1, register2, L1 means _____________.
go to the statement labeled L1 if the value in register1 equals the value in register2.
D latch
has two inputs: CLK and D output is q or not q
Increasing the speed limit for cars driving over a bridge _______ the execution time.
improves Cars can cross in less (decreased) time, which is an improvement in execution time.
Adding additional processors to a system that uses multiple processors for separate tasks -- for example, searching the web -- has what effect? Assume that before adding processors, tasks do not wait to execute (tasks do not "queue up").
increases throughput
The manufacturing process begins with a silicon _____.
ingot
Design for Moore's Law
integrated circuit resources double every 18-24 months Ex. Adding electromagnetic aircraft catapults (which are electrically-powered as opposed to current steam powered models), allowed by the increased power generation off ered by the new reactor technology
Processor (CPU)
interprets and carries out the basic instructions that operate a computer
Which instructions are I-type instructions lw $t0, 20($t7) addi $s0, $0, -10 sub $t1, $s7, $s2 add $t0, $s0, $s1
lw $t0, 20($t7) addi $s0, $0, -10
Assume that A is an array of 100 words and that the compiler has associated the variables g and h with the registers $s1 and $s2. Also assume that the starting address, or base address, of the array is in $s3. Compile this C assignment statement: g = h + A[6];
lw $t0, 24($s3) add $s1, $s2, $t0
As computing systems move to multicore microprocessors, programmers _____ to obtain performance benefits.
need to rewrite their programs Programs must be rewritten to explicitly take advantage of multiple processors.
Clock
needed in sequential logic to decide when an element that contains state should be updated.
What is the minimal set of MIPS instructions that may be used to implement the following pseudoinstruction: not $t1, $t2 // bit-wise invert
nor $t1, $t2, $t2 don't ask why I have no idea
The nori instruction is not part of the MIPS instruction set, because the same functionality can be implemented using existing instructions. Which of the foloowing assembly code snippet has the following functionality: $t0 = $t1 NOR F234
ori $t0, $t1, F234 nor $t0, $t0, $0
Performance via parallelism
perform operations in parallel Ex. Increasing the gate area on a CMOS transistor to decrease its switching time
A CPU is also known as _________.
processor
Consider three different processors P1, P2, and P3 executing the same instruction set. P1 has a 3 GHz clock rate and a CPI of 1.5. P2 has a 2.5 GHz clock rate and a CPI of 1.0. P3 has a 4.0 GHz clock rate and has a CPI of 2.2. Which processor has the highest performance expressed in instructions per second?
processors P2 performance of P1 (instructions/sec) = 3 × 10^9/1.5 = 2 × 10^9 performance of P2 (instructions/sec) = 2.5 × 10^9 /1.0 = 2.5 × 10^9 performance of P3 (instructions/sec) = 4 × 10^9 /2.2 = 1.8 × 10^9
slt rd, rs, rt _____________.
sets rd to 1 when rs < rt. Otherwise, rd is 0
Implement the following high-level code segments using the slt instruction. Assume the integer variables g and h are in registers $s0 and $s1,respectively. if (g > h) g = g + h; else g = g − h; Which of the following is the correct MIPS code?
slt $t0, $s1, $s0 beq $t0, $0, else add $s0, $s0, $s1 j done else: sub $s0, $s0, $s1 done:
SRAM
static random access memory - faster - more expensive - i literally don't know what any of this means - used for computer cache
Memory
stores instructions and data
SR Latch
stores one bit, with an input s to set the latch to 1, an input r to reset the latch to 0, and with the stored bit appearing on output q. S and s are for "set", and R and r for "reset".
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 $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. B[8] = A[i−j];
sub $t0, $s3, $s4 sll $t0, $t0, 2 add $t0, $s6, $t0 lw $t1, 0($t0) sw $t1, 32($s7)
The base address of an array is _____________.
the address of the first word in the array
Throughput
the amount of work performed by a system during a given period of time
Frame pointer is __________.
the location of the Stack Pointer before the function is invoked
Cloud Computing
the practice of using a network of remote servers hosted on the Internet to store, manage, and process data, rather than a local server or a personal computer.
The compiler _____________.
transforms the C program into an assembly language program
$sp points to the address of the most recent element in the stack.
true
What is the MIPS assembly code for swapping the contents of two registers, $t0 and $t1? You may not use any other registers.
xor $t0, $t0, $t1 xor $t1, $t0, $t1 xor $t0, $t0, $t1