You are on page 1of 34

COMSATS Institute of
Information Technology
CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE
Lecture # 2
asif.malik@comsats.edu.pk

Quote of the day
The greatest mistake we humans
make in our relationships
"We listen half, understand quarter,
think zero and react double"
4/17/16

CSC221– COMPUTER ORGANIZATION AND
ASSEMBLY LANGUAGE

3

Data Representation • Binary numbers are used to describe the contents of computer memory • Each numbering format has a base. or maximum number of symbols that can be assigned to a single digit 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 4 .

Binary Integers • Binary numbers are base 2 numbers. and the bit on the right is the least significant bit (LSB) • Binary integers can be signed or unsigned 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 5 . in which each binary digit (called a bit) is either 0 or 1 • Bits are numbered sequentially starting at zero on the right side and increasing toward the left • The bit on the left is called the most significant bit (MSB).

each bit in an unsigned binary integer represents an increasing power of 2 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 6 .Unsigned Binary Integers • Starting with the LSB.

Translating Unsigned Binary Integers to Decimal • Weighted positional notation represents a convenient way to calculate the decimal value of an unsigned binary integer having n digits: • D indicates a binary digit • Calculate Decimal of Binary 10101001 ? 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 7 .

repeatedly divide the integer by 2.) to produce binary 100101 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 8 . saving each remainder as a binary digit • We can concatenate the binary bits from the remainder column of the table in reverse order (D5. .Translating Unsigned Decimal Integers to Binary • To translate an unsigned decimal integer into binary. . D4. .

Binary Addition • When adding two binary integers. starting with the low-order pair of bits (on the right) and add each subsequent pair of bits • Add binary 00000100 to 00000111: • What If we add 11111111 to 00000001 and save in 8 bits ? CSC221– COMPUTER ORGANIZATION AND 4/17/16 ASSEMBLY LANGUAGE 9 . proceed bit by bit.

Integer Storage Sizes • The basic storage unit for all data in an x86 computer is a byte. containing 8 bits • Other storage sizes are : 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 10 .

Integer Storage Sizes 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 11 .

Hexadecimal Integers 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 12 .

Hexadecimal Integers • Each hexadecimal digit corresponds to 4 binary bits. • Example: Translate the binary integer 000101101010011110010100 to hexadecimal: 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 13 .

each digit position represents a power of 16 • The formula can be generalized for any n-digit hexadecimal integer: • For example.Converting Unsigned Hexadecimal to Decimal • In hexadecimal. Convert Hexadecimal ABCD to Decimal ? 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 14 .

Powers of 16 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 15 .

Converting Unsigned Decimal to Hexadecimal 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 16 .

Hexadecimal Addition 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 17 .

the MSB indicates the sign: 0 is positive and 1 is negative 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 18 .Signed Binary Integers • For x86 processors.

if presented with the expression A .Two’s-Complement Representation • Negative integers use two’s-complement representation. using the mathematical principle that the two’s complement of an integer is its additive inverse • Two’s-complement representation is useful to processor designers because it removes the need for separate digital circuits to handle both addition and subtraction • For example.B. the processor can simply convert it to an addition expression: A + (-B) 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 19 .

for example.Two’s-Complement Representation • The two’s complement of a binary integer is formed by inverting (complementing) its bits and adding 1 • Using the 8-bit binary value 00000001. its two’s complement turns out to be 11111111. as can be seen as follows: 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 20 .

convert B to its two's complement • Add A to (–B) 00001100 00001100 – 00000011 11111101 00001001 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 21 .Binary Subtraction • When subtracting A – B.

Hexadecimal Two’s Complement • To create the two’s complement of a hexadecimal integer. • An easy way to reverse the bits of a hexadecimal digit is to subtract the digit from 15. reverse all bits and add 1. • Example : 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 22 .

For Self Learning • Converting • Converting • Converting • Converting 4/17/16 Signed Signed Signed Signed Binary to Decimal Decimal to Binary Decimal to Hexadecimal Hexadecimal to Decimal CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 23 .

Create its two’s complement a second time to get its positive equivalent.Converting Signed Binary to Decimal • If the highest bit is a 1. the number is stored in two’s-complement notation. 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 • Same steps for “Converting Signed Hexadecimal to Decimal” 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 24 .

Example 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 25 .

we create the two’s complement of 00101011. which is 11010101 • Same steps for “Converting Signed Decimal to Hexadecimal” 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 26 . create the two’s complement of the binary number from the previous step For example. −43 decimal is translated to binary as follows: • The binary representation of unsigned 43 is 00101011 • Because the original value was negative.Converting Signed Decimal to Binary • Convert the absolute value of the decimal integer to binary • If the original decimal integer was negative.

This limits the range: Practice: What is the largest positive value that may be stored in 20 bits? 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 27 .Ranges of Signed Integers • The highest bit is reserved for the sign.

which is a mapping of characters to integers • ANSI Character Set The American National Standards Institute (ANSI) defines an 8-bit character set that represents up to 256 characters 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 28 .Character Storage • If computers only store binary data. how do they represent characters? They use a character set.

Character Storage • Unicode Standard Today. computers must be able to represent a wide variety of international languages in computer software • As a result. and punctuation used in all major languages 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 29 . the Unicode standard was created as a universal way of defining characters and symbols • It defines numeric codes (called code points) for characters. symbols.

32h. 43h. 42h. and 33h 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 30 . A sequence of one or more characters is called a string • An ASCII string is stored in memory as a succession of bytes containing ASCII codes • For example. the numeric codes for the string “ABC123” are 41h. 31h.Character Storage • ASCII Strings.

Summary 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 31 .

Reading Material • Chapter # 1 Assembly Language for x86 Processors. IRVINE 4/17/16 CSC221– COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE 32 . Seventh Edition By KIP R.