CH 0
CH 0
Introduction to computer
organization
Examples:
COBOL Business applications
FORTRAN Engg & Scientific Applications
PASCAL General use and as a teaching tool
C & C++ General Purpose – currently most popular.
PROLOG Artificial Intelligence
JAVA General all purpose programming
.NET General or web applications.
Advantages of High over Low level language
• The main advantage of high-level languages over low-level lan-
guages is that they are easier to read, write and maintain.
• High-level languages make complex programming simpler.
• High level programming techniques are applicable everywhere even
where computational resources are limited.
• Error ratio is less in high level language and debugging (locate and
correct errors in program code ) is easier.
• Length of the program is also small compared with low level.
• Many real time problems can be easily solved with high level lan-
guage.
Assembly Language
• A computer low level language that deals with hardware registers by
name known as assembly language.
• Assembly language is the best example of low level language, this is
in between machine language and high-level language.
• A low-level language does not need a compiler or interpreter to run
the program, the processor run low-level code directly.
Assembly Language
• Assembly languages enable a programmer to use names instead of
numbers.
• Programmers still use assembly language when speed is essential or
when they need to perform an operation that isn't possible in a high-
level language.
• It uses mnemonic codes (short forms) for instructions and allows the
programmer to introduce names for blocks of memory that hold data.
Example:
mov edx, [esp+8]
cmp edx,
Machine language
• Machine code or machine language is a system of instructions and data executed di-
rectly by a computer's CPU, The lowest-level programming language that only
be understood by computers.
• Computer language that is directly executable by a computer without the need for
translation by a compiler or an assembler.
• The native language of the computer, The set of symbolic instructions in binary
that is used to represent operations and data in a machine called machine code
Program code converters
INTERPRETER: Interpreter can convert a source code , usually on a step-by-step,
line-by-line and unit-by-unit basis into machine code.
COMPILER: Compiler is a program that compile source code into executable instruc-
tions that a computer can understand, it check the entire program for Syntex and
semantic errors.
Decimal Octal
Binary Hexadecimal
Quick Example
Base
Decimal to Decimal (just for fun)
Decimal Octal
Binary Hexadecimal
Weight
Base
Binary to Decimal
Decimal Octal
Binary Hexadecimal
Binary to Decimal
• Technique
– Multiply each bit by 2n, where n is the “weight” of
the bit
– The weight is the position of the bit, starting from
0 on the right
– Add the results
Example
Bit “0”
1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Octal to Decimal
Decimal Octal
Binary Hexadecimal
Octal to Decimal
• Technique
– Multiply each bit by 8n, where n is the “weight” of
the bit
– The weight is the position of the bit, starting from
0 on the right
– Add the results
Example
7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Decimal
• Technique
– Multiply each bit by 16n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting from
0 on the right
– Add the results
Example
Decimal Octal
Binary Hexadecimal
Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant bit)
– Second remainder is bit 1
– Etc.
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1
12510 = 11111012
Octal to Binary
Decimal Octal
Binary Hexadecimal
Octal to Binary
• Technique
– Convert each octal digit to a 3-bit equivalent
binary representation
Example
7058 = ?2
7 0 5
7058 = 1110001012
Hexadecimal to Binary
Decimal Octal
Binary Hexadecimal
Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
10AF16 = ?2
1 0 A F
10AF16 = 00010000101011112
Decimal to Octal
Decimal Octal
Binary Hexadecimal
Decimal to Octal
• Technique
– Divide by 8
– Keep track of the remainder
Example
123410 = ?8
8 1234
8 154 2
8 19 2
8 2 3
0 2
123410 = 23228
Decimal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder
Example
123410 = ?16
16 1234
16 77 2
16 4 13 = D
0 4
123410 = 4D216
Binary to Octal
Decimal Octal
Binary Hexadecimal
Binary to Octal
• Technique
– Group bits in threes, starting on right
– Convert to octal digits
Example
10110101112 = ?8
1 3 2 7
10110101112 = 13278
Binary to Hexadecimal
Decimal Octal
Binary Hexadecimal
Binary to Hexadecimal
• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits
Example
10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
Octal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Octal to Hexadecimal
• Technique
– Use binary as an intermediary
Example
10768 = ?16
1 0 7 6
2 3 E
10768 = 23E16
Hexadecimal to Octal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Octal
• Technique
– Use binary as an intermediary
Example
1F0C16 = ?8
1 F 0 C
1 7 4 1 4
1F0C16 = 174148
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF
/ 230 =
Exercise – Free Space
• Determine the “free space” on all drives on a
machine in the lab
Free space
Drive Bytes GB
A:
C:
D:
E:
etc.
Review – multiplying powers
• For common bases, add powers
ab ac = ab+c
or…
26 210 = 64 210 = 64k
Fractions
• Decimal to decimal (just for fun)
Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
BCD, ASCII, Negative Binary
Numbers, Addition, Subtraction
Unsigned Numbers
• Unsigned number implies that the sign of the
number is irrelevant
• We consider the numbers as having no sign bit
• All the bits allotted for the data are used for
magnitude alone
• Refers to positive numbers
• With 8 bits, numbers from 0 to 255 can be
used
Representation of Negative Numbers
Hex 7EH
Hex F5H
A B A+ B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Addition of Unsigned Numbers Case1:
110011+001100=
Binary addition
10101010 + 11001100 = 0101110110
110011+001100= 0111111
Hexadecimal addition
59H 8ABH 999H
69H B78H ABCDH
----- --------- ---------
C2H 1423H B566H
Hexadecimal addition
79H 898 FFF
79H ABA EEE
----- --------- ---------
Hexadecimal addition
79H 898H FFFH
79H ABAH EEEH
----- --------- ---------
F2H 1352H 1EEDH
Addition of Negative Numbers
• Negative numbers are represented in 2’s
complement notation
Q) Add -43 and -56
A) Calculate 2’s complement of 43 and 56
- 43
1101 0101
- 56 + 1100 1000
-99 1 1001 1101
A B A– B
0 0 0
0 1 1 (borrow 1)
1 0 1
1 1 0
Subtraction
Subtraction
Second Step
Third Step
BCD subtraction in 9’s compliment method.