0% found this document useful (0 votes)
23 views14 pages

Lecture # 01

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views14 pages

Lecture # 01

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Computer Organization and

Assembly Language
Lecture # 01
Why study computer organization?
• What are the concern of successful programmers?
• Performance of their programs
• What was the main constraints in on computer performance in early development
decades?
• The size of the computer’s memory
• Advances in computer design and memory have greatly reduced the importance of
small memory size
• Now programmers care about efficiency of their programs.
• But what they need to know about improving efficiency of the programs?
• The understanding of what is below your code
• What is below the code/program?
• The knowledge of computer organization
Why study computer organization? (Contd.)
• After this course, you will be able to answer the following questions:
• How are programs written in a high-level language translated into machine
level?
• How does the hardware execute the resulting program?
• What is the interface between the soft ware and the hardware?
• How does soft ware instruct the hardware to perform needed functions?
• What determines the performance of a program?
• How can a programmer improve the performance?
• What techniques can be used by hardware designers to improve performance
and energy efficiency?
Why study computer organization? (Contd.)
• Let’s take an example:
• Could the following C program be improved?
if (i == j)
f = g + h;
else
f = g – h;
Why study computer organization? (Contd.)
• Here's the Assembly code for the given C statements:
beq $s3, $s4, Add # Branch if i == j (registers $s3 and $s4)
sub $s0, $s1, $s2 # f = g - h (register $s0 for f, $s1 for g, $s2 for h)
j Exit # Jump to Exit (optional)

Add:
add $s0, $s1, $s2 # f = g + h (register $s0 for f, $s1 for g, $s2 for h)

Exit:
Why study computer organization? (Contd.)
• Explanation:

• beq $s3, $s4, Add: This instruction still checks if i == j are equal.
• sub $s0, $s1, $s2: This instruction is placed after the beq. If the condition is
not met (i.e., i != j), the program continues executing instructions sequentially,
and this instruction performs the subtraction for the "not equal" case.
• j Exit (optional): This instruction remains to unconditionally jump to Exit if
the condition in the beq is true (i.e., i and j are equal). This ensures the
program skips the sub instruction for the "equal" case.
• Add:: This label and the following add instruction remain unchanged,
handling the "equal" case.
Why study computer organization? (Contd.)
• The Assembly code for the same C program but using bne statement:
bne $s3, $s4, Sub # Branch if i != j (registers $s3 and $s4)
add $s0, $s1, $s2 # f = g + h (register $s0 for f, $s1 for g, $s2 for h)
j Exit # Jump to Exit (optional)

Sub:
sub $s0, $s1, $s2 # f = g - h (register $s0 for f, $s1 for g, $s2 for h)

Exit:
Why study computer organization? (Contd.)
• Determining which code, using beq or bne, is more efficient depends
on the expected distribution of values in the registers being compared.
Here's a breakdown of the efficiency considerations:
1. Branch Penalty. A branch penalty refers to the performance overhead
incurred when executing a branch instruction. It includes
1. Pipelining
2. Branching and Pipelining:
3. The Penalty:
2. Code Structure
Why study computer organization? (Contd.)
• How it happens?
• Pipelining:
• It divides the execution of instructions into multiple stages like fetching, decoding, execution, memory access,
and writing results.
• It allows multiple instructions to be processed simultaneously, potentially improving performance.
• Branching and Pipelining:
• When a branch instruction (e.g., if, else statements) is encountered, the processor needs to determine which path
(true or false) to take after the branch condition is evaluated.
• However, in a pipelined processor, the instructions following the branch might already be fetched and partially
processed before the branch condition is determined.
• The Penalty:
• If the branch prediction (predicting which path is likely) is incorrect, the fetched instructions become useless, and the processor
needs to:
• Flush (discard) these instructions.
• Fetch and start processing instructions from the correct path.
• This flushing and re-fetching process introduces a delay, impacting the overall performance. This delay is the branch
penalty.
Why study computer organization? (Contd.)
• How Code Structure affects the performance?
• Choosing between beq and bne:
• If the "equal" case is more likely to occur: Using beq can be slightly more
efficient because it avoids the branch penalty.
• If the "not equal" case is more likely to occur, and it involves more
instructions: Using bne might be beneficial as it avoids the branch penalty in
the more frequent and costly scenario.
• Analyze the number of instructions in each branch of the conditional
statement. If the "not equal" case involves more instructions, using bne as the
first test might be advantageous as it avoids unnecessary branch penalties.
High Level
to Machine
Level
Measuring Performance
• What is the measure of computer performance?
• Time is the measure of computer performance. Program execution time is measured in seconds per
program.
• What is elapsed time?
• Elapsed time is the total time to complete a task that includes disk accesses, memory accesses,
input/output (I/O) activities, operating system overhead—everything.
• A processor may work on several programs simultaneously. In such cases, the system
may try to optimize throughput rather than attempt to minimize the elapsed time for one
program.
• Hence, we often want to distinguish between the elapsed time and the time taken by CPU to execute
a program.
• What is CPU execution time?
• The time that CPU spends computing for a task and does not include time spent waiting for I/O or
running other programs.
Measuring Performance
• Computers are constructed using a clock that determines when events
take place in the hardware.
• These discrete time intervals are called clock cycles
• What is Clock Cycle?
• Designers refer to the length of a clock period both as the time for a complete
clock cycle (e.g., 250 picoseconds, or 250 ps)
• What is Clock Rate?
• The clock rate (e.g., 4 gigahertz, or 4 GHz), which is the inverse of the clock
period
CPU Performance and Its Factors
• A simple formula relates the most basic metrics (clock cycles and
clock cycle time) to CPU time:

Alternatively, because clock rate and clock cycle time are inverses,

You might also like