Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 38

Computer Organization and

Assembly Language
(CS2411 & CSC2201)

Class: BSCS 4
Lecture: 1
Lecturer Name: Kashif
Email: kashifdayo@Hotmail.com

SZABIST LARKANA CAMPUS 1


Lecture outline

 Resources
 Grading Theory
 Goals and Required Background
 Organization VS Architecture
 Function and Structure of Computer System
 Data Representation
 Number System Conversion
 Computer Arithmetic
 Two’s Compliment of Binary and Hexadecimal
 Boolean Algebra

SZABIST LARKANA CAMPUS 2


Resources
1. Assembly Language for x86 Processors, 7th edition/4th edition, Kip Irvine
2. Art of Assembly Language, 2e, Randall Hyde
3.IDE for assembly language programming (Visual Studio 2012)
4. Irvine (32-bit/16bit) Library

SZABIST LARKANA CAMPUS 3


Grading (Theory)
 Type of  Percenta  Remark
Assessment ge (%)
 2 x Quizzes (10 Marks)
 1 x Assignments (5 Marks)
 Course Work  30  1 x Lab File (5 Marks)
 1 x Presentation (5 Marks)
 1 x Class Participation (5 Marks)
 Mid-Term  30  Subjective + Programming
Exam
 Final Exam  40  Subjective + Programming

 Marks  Grade  Marks  Grade


 95-100  A+  75-78  B-
 91-94  A  72-74  C+
 87-90  A-  69-71  C
 83-86  B+  66-68  C-
 79-82  B      
SZABIST LARKANA CAMPUS 4
Goals and Required Background

 Goals: broaden student’s interest and knowledge in …


 Basic organization of a computer system
 Intel IA-32 processor architecture
 How to write assembly language programs
 How high-level languages translate into assembly language
 Interaction between the assembly language programs, libraries, the operating
system, and the hardware
 How interrupts, system calls, and handlers work
 How to debug a program at the machine level
 Required Background
 The student should already be able to program confidently in at least one high-
level programming language, such as Java or C.

SZABIST LARKANA CAMPUS 5


Early computers and Programming Tools

SZABIST LARKANA CAMPUS 6


Language

 Human Language  Programming Language

 Naturally created, e.g.,  Artificially developed, e.g.,


English, Urdu, Sindhi,
C, Basic, C#, Fortran,…
Punjabi,…

 Interpreted mostly by  Interpreted by human and


human computer

 Ambiguities and exceptions  Clear and precise syntax


in syntax and grammar

SZABIST LARKANA CAMPUS 7


Hierarchy of Programming Language

SZABIST LARKANA CAMPUS 8


Organization VS Architecture

 Organization refers to….


 Operational Units and their interconnection.
 Realize the architectural specification.
 Physical arrangement of components of computer.
 Placement of main memory, CPU, cache memory etc.
 Examples of Organizational Attributes:
 Hardware details transparent (not visible) to the programmer
Interface between computer and peripherals.
Memory technology used.

SZABIST LARKANA CAMPUS 9


Organization VS Architecture Cont…

 Architecture refers to…


 Attributes of computer system visible to programmer.
 Direct impact on logical execution of program.
 Examples of Architectural Attributes:
Instruction set
Number of bits used to represent data types.
I/O mechanism
Memory addressing techniques

SZABIST LARKANA CAMPUS 10


Organization VS Architecture Cont…
 Example of architectural design issue:
 A computer will have a multiply instruction.
 Example of Organizational issue:
 An Instruction will be implemented by a special multiply unit or by
repeated use of the add unit of the system.
 Particular architecture may span many years.
 Encompass a number of different computer models
 But its organization changing with changing technology.
 Organization must be designed to implement a particular architectural.
 Thorough treatment of organization requires a detailed examination of
architecture.
 Changes in technology influence organization and architectures.

SZABIST LARKANA CAMPUS 11


Function of Computer System

 Function
 The operation of each individual component
as part of the structure.
Data processing
Data storage
Data movement
Control

SZABIST LARKANA CAMPUS 12


Structure of Computer System

 Structure
 The way in which the components are
interrelated.
 Computer interacts in some fashion with its
external environment.
 Its linkages to the external environment
 Classified as peripheral devices or
communication lines.

SZABIST LARKANA CAMPUS 13


Structure of Computer System

 Four main structural components:


 CPU, Main Memory, I/O, System interconnection/System Bus
 CPU’s structural components:
 CU, ALU, Registers, CPU interconnection.
 Control unit: Controls the operation of the CPU and the computer
 Arithmetic and logic unit (ALU): Performs the computer’s data
processing functions
 Registers: Provides storage internal to the CPU
 CPU interconnection: Some mechanism that provides for communication
among the control unit, ALU, and registers.

SZABIST LARKANA CAMPUS 14


Data representation

 Computer is a construction of digital circuits with two states:


on and off
 You need to have the ability to translate between different
representations to examine the content of the machine
 Common number systems:
 Binary, octal, decimal and hexadecimal

SZABIST LARKANA CAMPUS 15


Data Representation

 Often, binary numbers are used to describe the contents of computer memory.
 At other times, decimal and hexadecimal numbers are used.
 Quickly translate numbers from one format to another.
 Each numbering system has a base or maximum number of symbols.

SZABIST LARKANA CAMPUS 16


Binary Integers

 Computer stores instructions and data in memory as collections of electronic


charges.
 Representing these entities with numbers requires a system geared to the concepts
of on and off or true and false.
 Binary numbers are base 2 numbers, in which each binary digit (called a bit) is
either 0 or 1

SZABIST LARKANA CAMPUS 17


Number Systems and Conversion
 Binary
 Base 2 (0,1)
 Decimal
 Base 10 (0 to 9)
 Octal
 Base 8 (0 to 7)
 Hexa-Decimal
 Base 16 (0 to 9 and A to F)

SZABIST LARKANA CAMPUS 18


Binary to Decimal Conversion OR Vice-Versa
Weighted positional notation shows how to
calculate the decimal value of each binary bit:
dec = (Dn-1  2n-1) + (Dn-2  2n-2) + ... + (D1  21) +
(D0  20)

D = binary digit

SZABIST LARKANA CAMPUS 19


Binary Addition

SZABIST LARKANA CAMPUS 20


Extra Digit/Bit is needed in Addition
 Sometimes a carry is generated out of the highest bit position.
 When that happens, the size of the storage area set aside
becomes important.
 If we add 11111111 to 00000001, for example, a 1 carries out of
the highest bit position, and the lowest 8 bits of the sum equal
all zeros.
 If the storage location for the sum is at least 9 bits long, we can
represent the sum as 100000000.
 But if the sum can only store 8 bits, it will equal to 00000000,
the lowest 8 bits of the calculated value.
 It is like adding 99 with 1 ( 1+99 =100). An extra digit is needed
for the result.

SZABIST LARKANA CAMPUS 21


Integer Storage Sizes

 The basic storage unit for all data in an x86 computer is a byte (8 bits).
 Other storage sizes are:
 Word (2 bytes)
 Doubleword (4 bytes)
 Quadword (8 bytes)

SZABIST LARKANA CAMPUS 22


Hexadecimal Integers

 Large binary numbers are cumbersome to read.


 Hexadecimal digits offer a convenient way to represent binary data.
 Each digit in a hexadecimal integer represents four binary bits.
 A single hexadecimal digit represents decimal 0 to 15, so letters A to F represent
decimal values in the range 10 through 15.
 Binary, decimal and Hexa-decimal conversion via equivalent table.

• Example: Translate the binary integer 000101101010011110010100


to hexadecimal:

SZABIST LARKANA CAMPUS 23


Hexadecimal integers
 All values in memory are stored in binary. Because long binary
numbers are hard to read, we use hexadecimal representation.

SZABIST LARKANA CAMPUS 24


Hexadecimal Addition

Important skill: Programmers frequently add and subtract the addresses of


variables and instructions.
SZABIST LARKANA CAMPUS 25
Another Method Hexadecimal addition

 Divide the sum of two digits by the number base (16). The quotient
becomes the carry value, and the remainder is the sum digit.

1 1
36 28 28 6A
42 45 58 4B
78 6D 80 B5

Practice: The address of var1 is 00400020. The address of the next variable after
var1 is 0040006A. How many bytes are used by var1?

SZABIST LARKANA CAMPUS 26


Signed Binary Integers

 Signed binary integers are positive or negative.


 MSB indicates the sign.
 0 is positive and 1 is negative.

SZABIST LARKANA CAMPUS 27


Two’s-Complement Representation

 Negative integers use two’s-complement representation.


 Two’s complement of an integer is its additive inverse.
 add a number to its additive inverse, the sum is zero
 Useful to processor designers as it removes the need for
separate digital circuits to handle both addition and
subtraction.
 A-B can be expressed as A+(-B).

SZABIST LARKANA CAMPUS 28


Two’s-Complement

 The two’s complement of a binary integer is formed by inverting (complementing)


its bits and adding 1.
 as can be seen as follows:

 11111111 is the two’s-complement representation of -1.


 The two’s-complement operation is reversible, so the two’s complement of
11111111 is 00000001.

SZABIST LARKANA CAMPUS 29


Hexadecimal Two’s Complement

 Reverse all the bits and add 1.


 An easy way to reverse the bits of a hexadecimal digit is to
subtract the digit from 15.
 Examples of hexadecimal integers converted to their two’s
complements:

SZABIST LARKANA CAMPUS 30


Converting Signed Binary to Decimal

 If the highest bit is a 1:


 Number is stored in two’s-complement notation.
 Create its two’s complement a second time to get its
positive equivalent.
 Then convert this new number to decimal as if it were an
unsigned binary integer.
 If the highest bit is a 0, you can convert it to decimal as if it
were an unsigned binary integer.

SZABIST LARKANA CAMPUS 31


Converting Signed Binary to Decimal

 For example, signed binary 11110000 has a 1 in the highest bit.


 Indicating that it is a negative integer.
 First we create its two’s complement, and then convert the result to
decimal.
 Here are the steps in the process:

SZABIST LARKANA CAMPUS 32


Converting Signed Decimal to Binary

 Convert the absolute value of the decimal integer to binary.


 If the original decimal integer was negative, create the two’s complement
of the binary number from the previous step.
 Example: −43 decimal is translated to binary as follows:
 The binary representation of unsigned 43 is 00101011.
 Because the original value was negative, we create the two’s
complement of 00101011.
 Which is 11010101. This is the representation of −43 decimal.

SZABIST LARKANA CAMPUS 33


Boolean algebra

 Boolean expressions created from:


 NOT, AND, OR

SZABIST LARKANA CAMPUS 34


NOT

 Inverts (reverses) a boolean value


 Truth table for Boolean NOT operator:

Digital gate diagram for NOT:

NOT

SZABIST LARKANA CAMPUS 35


AND

 Truth if both are true


 Truth table for Boolean AND operator:

Digital gate diagram for AND:

AND

SZABIST LARKANA CAMPUS 36


OR

 True if either is true


 Truth table for Boolean OR operator:

Digital gate diagram for OR:

OR

SZABIST LARKANA CAMPUS 37


THANKS

SZABIST LARKANA CAMPUS 38

You might also like