Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views20 pages

Chap0 Introduction (CompSys)

Uploaded by

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

Chap0 Introduction (CompSys)

Uploaded by

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

Basic Computer System

RAM CPU

MEMORY DMA
I/O Devices (or) Peripherals
External units
External Direct Memory Access
Unit controller External

(c) Bharadwaj V Dept of ECE NUS (2013) 1


Computer System… Cont’d
APPLICATION

MODELING (Mathematical/Statistical/Empirical, etc)

COMPUTER PROGRAM (Languages – C/C++/Java/Assembly…)

Compile – Link – Executable  Run!

How does our program get executed?

What do we mean by “running” a program?


(c) Bharadwaj V Dept of ECE NUS (2013) 2
Program Execution/Running

Program must be brought to the memory (RAM) for Execution;

Each line of the program will be translated into a set of machine


instructions (0’s and 1’s) and all instructions are stored in RAM
in a contiguous order;

Instructions are fetched from RAM, one at a time, and get


executed in the CPU;

All such instructions will live in the memory until the entire
program gets executed;

(c) Bharadwaj V Dept of ECE NUS (2013) 3


Control Structures
 An algorithm is a set of instructions, which are
followed sequentially by default.
 However, sometimes we need to change the
default sequential flow.
 We will study 3 control structures used
predominantly in programming
- Sequence - Selection - Repetition
False ?
True False
? True

ACK: Thanks Dr. Alan for control structures


(c) Bharadwaj V Dept of ECE NUS (2017)
slides
Control Structures: Sequence
 Task: Compute the average of three integers
A possible algorithm: Variables used:
num1 num2 num3
enter values for num1, num2, num3
ave  ( num1 + num2 + num3 ) / 3
ave
print ave

Variables used:
Another possible algorithm:
num1 num2 num3
enter values for num1, num2, num3
total  ( num1 + num2 + num3 ) total
ave  total / 3
print ave ave

Each box represents a variable.


Important concepts: Each variable has a
unique name and contains a value.
© NUS (c) Bharadwaj V Dept of ECE NUS (2017)
True False
Control Structures: Selection ?

 Task: Arrange two integers in ascending order (sort)


Algorithm A:
enter values for num1, num2 Variables used:
// Assign smaller number into final1,
// and larger number into final2 num1 num2
if (num1 < num2)
then final1  num1 final1 final2
final2  num2
else final1  num2
final2  num1
// Transfer values in final1, final2 back to num1, num2
num1  final1
num2  final2
// Display sorted integers
print num1, num2

© NUS (c) Bharadwaj V Dept of ECE NUS (2017)


False

Control Structures: Repetition ?


True

 Task: Find sum of positive integers up to n (assume n>0)


Algorithm:
enter value for n Variables used:
/* Initialise a counter count to 1, and ans to 0 */
count  1 n
ans  0
REPEAT_UNTIL (count <= n) do count
ans  ans + count // add count to ans
count  count + 1 // increase count by 1 ans

// Display answer
print ans

Initialisation is
very important!

© NUS (c) Bharadwaj V Dept of ECE NUS (2017)


Algorithm
 An algorithm is a well-defined computational
procedure consisting of a set of instructions, that
takes some value or set of values as input, and
produces some value or set of values as output.

Inputs Output(s)

Algorithm

‘Algorithm’ stems from ‘Algoritmi’, the Latin form of al-


Khwārizmī, a Persian mathematician, astronomer and geographer.
Source: http://en.wikipedia.org/wiki/Algorithm
© NUS (c) Bharadwaj V Dept of ECE NUS (2017)
Algorithm
 Ways of representing an algorithm:
Flowchart Pseudocode

lynda.com

© NUS (c) Bharadwaj V Dept of ECE NUS (2017)


Flow-Charts

• Visual Representation of the work-flow / process-flow

• Pre-defined symbols and representations that capture


the flow

• Typically starts with a START block and ends with an


END block

• For very large flow-charts connectors are generally used

(c) Bharadwaj V Dept of ECE NUS (2013) 10


Flow-charts Cont’d…

(c) Bharadwaj V Dept of ECE NUS (2013) 11


Flow-Chart/Algorithm: Example 1

© NUS (c) Bharadwaj V Dept of ECE NUS (2017)


Example 2 - Flow-Chart/Algorithm (High level
description – to be used in large-scale projects)
START

Compute the values


using functions:
x,y, F(x,y), G(y,z) and H(x,z)
z=0

Is G(y,z) NO Update x
> using Q(x)
F(x,y) ?

YES

Decrease y Display the


function END
using P(y)
values
(c) Bharadwaj V Dept of ECE NUS (2013) 13
Systematic design process involves drawing flow-
charts / writing pseudocodes

You should draw flow-charts in all the three lab


assignments which reflects your design; Drawing
flow-chart carries marks.
Exercise: Modify Example 1 to allow the user to input N for
any number of times until she/he wants to quit. This is
an example of an interactive design!

(c) Bharadwaj V Dept of ECE NUS (2013) 14


Ethics in Computer Programming
Following Code of Ethics in Computer Programming is based on defunct International
Programmer’s Guild.

A programmer must...
...never create or distribute malware.
...never write code that is obfuscated or intentionally difficult to follow.
...never write documentation that is intentionally confusing or inaccurate.
...never reuse copyrighted code unless the proper license is purchased or permission is
obtained.
...acknowledge (verbally and in source code comments) the work of other programmers on
which the code is based, even if substantial changes are made.
...never write code that is deliberately inefficient with the intent of later claiming credit for
making efficiency improvements.
...never intentionally introduce bugs with the intent of later claiming credit for fixing the
bugs, or to stimulate the uptake of later versions.
...never write code that intentionally breaks another programmer's code for the purpose of
elevating one's status.
...never hide known obstacles to a project's completion during any phase of development,
especially the design phase.
...never dishonestly downplay the difficulty of completing a project. 15
Ethics in Computer Programming (Cont’d)...
...report any illegal activities of the employer.
...never defame the profession.
...never falsely deny the presence of bugs.
...never reveal the secret corporate knowledge of an employer.
...never accept compensation from multiple parties for the same work unless permission is
given.
...never perform competitive work without the employer's knowledge.
...never conceal pertinent information from other members of the development team.
...never conceal from the employer their financial interest in development resources.
...never conceal any conflict of interest that may affect the project.
...never seek external profit from a project that was funded by a second party without
permission. If permission is given to resell a product, the work should be discounted.
...never maliciously injure the reputation of an employer or members of the development team.
...never misrepresent their knowledge, experience, or abilities.
...never take credit for another's work.
...never steal software, especially development tools.
...never conceal the deficiencies of other programmers by writing code for them and allowing
them to pass it off as their own work.
...never install third-party applications without the user's permission. Preferably not at all.
...stay current on the advancement of the field of Computer Science.
...never force updates on a user without their knowledge and approval. 16
ANNEXURE
Binary number system…Quick review
Binary Number system - O and 1 representation
Example:

(Decimal) 42 = 4 x 101 + 2 x 100 We know this! 

(Binary) 42 = 1 x 25 + 0 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20
= 32 + 8 + 2
So the pattern will be: 101010 (Verify the reverse!)

Hence:

With just 2 digits – YY – {0,1,2,3} – 4 distinct numbers


With just 3 digits – YYY – {0,1,…,7} – 8 distinct numbers
With just 4 digits – YYYY – {0,1,2,…,15} – 16 distinct numbers

With k digits: (YYYY….YY) – {0,1,…., 2k-1} – (2k) distinct numbers
(c) Bharadwaj V Dept of ECE NUS (2013) 17
Binary number system…Quick review
Hexa-decimal – Valid Numbers: {0,1,…,15} and they are represented
as

{0,1,2…,9, A, B,C,D,E,F}

Example:
(Hexa-Decimal) 42 = 2 x 161 + 10 x 160 (= 32 + 10)
So the pattern will be: 2A (Verify the reverse!)
We usually represent a hexadecimal number as ‘2A H’;

Hence:

4E8 H = 1024+224 + 8 = 1256(decimal)


(c) Bharadwaj V Dept of ECE NUS (2013) 18
Computer System… Cont’d
1 Byte = 8 Bits (each slot)

0100 1010
Most Significant Bit(MSB) Least Significant Bit(LSB)
. Addressing:
RAM . Each slot has a unique address
.
Address is represented as a binary word

RAM 8 Slots implies we need 3 bit number


representing (addressing) each slot ;

0100 1010 - This pattern is represented RAM 16 Slots implies we need 4 bit number
as a hexa-decimal number 4A in the representing (addressing) each slot ;
Memory for the ease of reading(c) Bharadwaj V Dept of ECE NUS (2013) 19
Program Execution/Running … (Cont’d)

Example
printf (“My name is BV\n”); /* typical C syntax */
After compilation and other processes a set of machine
codes will be generated. A single high level statement may
generate more than 1 machine code instruction. A sample
is shown below for a single instruction.
Machine code:
101010111100010101010010100111101100 Clearly more than 1 byte!!

Hence,
1010 10111100 01010101 00101001 11101100
In this case, this instruction occupies 5 bytes; The last 4 most significant bits will
be padded with 0s.
(c) Bharadwaj V Dept of ECE NUS (2013) 20

You might also like