Week 1 & 2 Computer Organization & Architecture Introduction to Basic Computer Organization with its...
-
Upload
evelyn-lucas -
Category
Documents
-
view
220 -
download
0
Transcript of Week 1 & 2 Computer Organization & Architecture Introduction to Basic Computer Organization with its...
Week 1 & 2 Computer Organization & Architecture
• Introduction to Basic Computer Organization with its peripherals.
• computer architecture & its functioning. • General overview of programming
languages & its compilations.
Introduction to basic computer organizations and Architecture
– Definition of computer & its block diagram– Von man Neumann machine– Functioning of computers– Bus Structure– Computer Organization – Computer Architetcure
Computer
• Computer : Computer is an electronic machine which accepts the input from input device , transfers, do operation on data and gives the out put.
• Peripherals or parts of computers• Input device : Accepts the data/program . Ex. Keyboard, mouse
and so on.• Output Device: Used to give the result.• Ex. Monitor, printer and so on.• Central processing unit(C.P.U.) : Further divided into
– Arithmetic logic unit(A.L.U)– Memory unit(M.U)– Control Unit(C.U)
Block diagram of computer
Figure 1.1. Basic functional units of a computer.
I/O Processor
Output
Memory
Input andArithmetic
logic
Control
Memory unit( M.U): Used to store the data in binary form from the input device and gives to the output to the output device.• Two classes of memory Primary storage Fast Programs must be stored in memory while they are being executed Address RAM and memory access time Memory hierarchy – cache, main memory Secondary storage – larger and cheaper
• Arithmetic Logic Unit(A.L.U.): used to fetch the data from the memory process it and aging send the data to the memory.
• Performs the Arithmetic and logic operations• Control Unit• All computer operations are controlled by the
control unit.• The timing signals that govern the I/O
transfers are also generated by the control unit
Bus Structure
Figure 1.3. Single-bus structure.
MemoryInput Output Processor
• There are many ways to connect different parts inside a computer together.
• A group of lines that serves as a connecting path for several devices is called a bus.
• Address/data/control
Von Neumann Machine Architecture and its Functions:
Von Neumann Architecture
• Von Neumann Architecture consists of mainly 5 parts.
• Input • Output device• Central Processing unit (C.P.U.)
– Arithmetic Logic Unit (A.L.U).– Control Unit (C.U.)– Memory Unit (M.U)
• Out Put Device : It is used to display the result eg: Monitor, printer and so on.
• Input Device : It is used to enter the data .Eg. Keyboard, mouse and so on.
• Central Processing Unit : (C.P.U.)– Memory Unit (M.U.) : It is used to store the data in the
form of binary bits.– Data from the keyboard transfers to memory.– Memory of 2 types
• Primary Memory: Used to store the data temporarily.eg. Main memory ,RAM, SRAM, DRAM.
• Secondary memory : Used to store the data permanently. eg. Magnetic disks, magnetic bubbles and drums.
Computer Functions
Computer Architecture
• Refers to specification of the relationship between different hardware components of a computer system.
• It defines high and low level of abstractions.• At high level CPU is presented and low level its
parts like ALU,MU,CU represented
Computer Organization
• Organization is how features are implemented– Control signals, interfaces, memory technology.– e.g. Is there a hardware multiply unit or is it done
by repeated addition?Computer organization is a study of a Computer
Architecture. E.g. Memory, Registers, RAM, ROM, CPU, ALU, 16 bit/ 32 bit/ 64 bit architecture, what different parts makes a computer, etc.
Programming Languages.
• There are 4 types of programming languages.• High Level Language• Middle Level Language• Low level Language• Assembly Level Language.
• Compiler : It is used to translate the Highlevel language (English statements) to low level language (1 ‘ 0’s).Compile entire program one at time. eg. Pascal, Basic, Fortran and so on.
• Interpreter : Used to translate the program high level language into low level language. It translates instruction by instruction.eg. Java
• Assembler : Used to translate the Assembly level language (Mnemonics) into low level language.
• Microprocessor: This is a smallest part of the processor which performs the following functions like – Storing data – Transferring – Performing Arehtmetic and logical operations.– Shift Operations and so on.– Eg: 8086,80386.
Week 3 Organization of the IBM Personal computers
• Architecture• Registers• Memories• Addressing modes• Instruction sets• Interrupts
Organization of the 8088/8086
CAP/IT221 19
Organization of the 8088/8086
CAP/IT221 20
2 main components: . Execution Unit (EU). . Bus Interface Unit (BIU).
EU: ALU + Registers (AX, BX, CX, DX, SI, DI, BP, and SP) + FLAGS register.
ALU: performs arithmetic & logic operations. Registers: store data FLAGS register: Individual bits reflect the result of
a computation.
Organization of the 8088/8086
CAP/IT221 21
BIU: facilitates communication between the EU & the memory or I/O circuits.
Responsible for transmitting addresses, data, and control signals on the buses.
Registers (CS, DS, ES, SS, and IP) hold addresses of memory locations.
IP (instruction pointer) contain the address of the next instruction to be executed by the EU.
Organization of the 8088/8086
16-bit registers, 1M Bytes Memory
Registers:
Information is stored in registersRegisters are classified according
to the functions they perform
CAP/IT221 22
Registers
• Data registers: 4 general data registers hold data for an operation.
• Address registers: (segment, pointer and index registers) hold the address of an instruction or data.
• Status register: FLAG register keeps the current states of the processor.
• 14 16-bit registers
CAP/IT221 23
Register
CAP/IT221 24
General Data Register: Used for general data manipulation.
• They are 16-bit registers that can also be used as two 8 bit registers: low and high bytes can be accessed separately → more registers to use when dealing with byte-size data.
• In addition to being general-purpose registers, they perform special functions
CAP/IT221 25
AX (Accumulator)• Most efficient register for arithmetic,
logic operations and data transfer: the use of AX generates the shortest machine code.
• In multiplication and division operations, one of the numbers involved must be in Al or AX
BX (Base)Can hold addresses (offset)
CAP/IT221 26
CX (Counter)
Counter for looping operations: loop counter, in REP instruction, and in the shift and rotate bits
DX (Data):
Used in multiply and divide, also used in I/O operations
CAP/IT221 27
Pointer Registers • SP (Stack Pointer): Used with
SS for accessing the stack segment.
• BP ( Base Pointer): Used with SS to access data on the stack. However, unlike SP, BP can be used to access data in other segments.
CAP/IT221 28
Instruction pointer
IP (Instruction pointer):
Points to the next instruction. Used with CS.
Flags register
Flags: Bits specify status of CPU and information about the results of the arithmetic operations.
CAP/IT221 30
Registers of x86
• Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow .
• Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in result, and to 0 when there is odd number of one bits .
• Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4 bits).
• Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is set to 0.
Registers of x86• Sign Flag (SF) - set to 1 when result is negative.
When result is positive it is set to 0. (This flag takes the value of the most significant bit.) .
• Trap Flag (TF) - Used for on-chip debugging .• Interrupt enable Flag (IF) - when this flag is set to 1
CPU reacts to interrupts from external devices.Direction Flag (DF) - this flag is used by some instructions to process data chains.
• Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127)
Memories
• There are 3 types of memories– Program memory.– Data Memory.– Stack memory.Program Memory: Can be located any where in the
memory.CALL and RETURN Instructions will be used.
• Data Memory: the 8086 processor can access data in any one out of 4 available segments, which limits the size of accessible memory to 256 KB .
• Stack memory can be placed anywhere in memory. The stack can be located at odd memory addresses, but it is not recommended for performance reasons
Memory Segment• Is a block of 2 (64) K Bytes consecutive memory
bytes.• Each segment is identified by a 16-bit number
called segment number, starting with 0000 up to FFFFh . Segment registers hold segment number.
• Within a segment, a memory location is specified by giving an offset (16-bit) = It is the number of bytes from the beginning of the segment (0→ FFFFh).
16
CAP/IT221 35
Memory Segment
00000
10000
20000
30000
40000
50000
60000
70000
80000
90000
A0000
B0000
C0000
D0000
E0000
F0000
One Segment8000:0000
8000:FFFF
segment offset
CAP/IT221 36
Segment : Offset Address
• A memory location may be specified by a segment number and offset ( logical address ).
Example : A4FB : 4872
h
Segment
Offset
CAP/IT221 37
• Offset : is the distance from the beginning to a particular location in the segment.
• Segment number : defines the starting of the segment within the memory space.
CAP/IT221 38
Interrupts Of X86
1. INTR is a mask able hardware interrupt 2. The interrupt can be enabled/disabled using
STI/CLI instructions or using more complicated method of updating the FLAGS
register with the help of the POPF instruction.
3. When an interrupt occurs, the processor stores FLAGS register into stack, disables
further interrupts
• NMI is a non-mask able interrupt. Interrupt is processed in the same way as the INTR interrupt .
• . Interrupt type of the NMI is 2, i.e. the address of the NMI processing routine is stored in location 0008h. This interrupt has higher priority then the mask able interrupt.
• Software interrupts • INT instruction - breakpoint interrupt. This is a type 3
interrupt. • INT <interrupt number> instruction - any one interrupt from
available 256 interrupts. • INTO instruction - interrupt on overflow • Single-step interrupt - generated if the TF flag is set. This is a
type 1 interrupt. When the CPU processes this interrupt it clears TF flag before calling the interrupt processing routine.
• Processor exceptions: divide error (type 0), unused opcode (type 6) and escape opcode (type 7).
Instruction Set• Data moving instructions.
– Data can be moved from register to register , memory to memory, register to memory and memory to register.
• Arithmetic - add, subtract, increment, decrement, convert byte/word and compare.
• Logic - AND, OR, exclusive OR, shift/rotate and test. • String manipulation - load, store, move, compare and scan for
byte/word. • Control transfer - conditional, unconditional, call subroutine
and return from subroutine. • Input/Output instructions. • Other - setting/clearing flag bits, stack operations, software
interrupts, etc
Addressing modes• Implied - the data value/data address is implicitly associated with the instruction. • Register - references the data in a register or in a register pair. • Immediate - the data is provided in the instruction. • Direct - the instruction operand specifies the memory address where data is located. • Register indirect - instruction specifies a register containing an address, where data is
located. This addressing mode works with SI, DI, BX and BP registers. • Based - 8-bit or 16-bit instruction operand is added to the contents of a base register (BX or
BP), the resulting value is a pointer to location where data resides. • Indexed - 8-bit or 16-bit instruction operand is added to the contents of an index register (SI
or DI), the resulting value is a pointer to location where data resides. • Based Indexed - the contents of a base register (BX or BP) is added to the contents of an
index register (SI or DI), the resulting value is a pointer to location where data resides. • Based Indexed with displacement - 8-bit or 16-bit instruction operand is added to the
contents of a base register (BX or BP) and index register (SI or DI), the resulting value is a pointer to location where data resides.
Segmented Memory
00000
10000
20000
30000
40000
50000
60000
70000
80000
90000
A0000
B0000
C0000
D0000
E0000
F0000
8000:0000
8000:FFFF
seg ofs
8000:0250
0250
li ne
ar a
ddr e
sse
s
one segment
CAP/IT221 44
Pointer and Index RegistersSP, BP, SI, DI
• Used for offset of data, often used as pointers. Unlike segment registers, they can be used in arithmetic and other operations.
CAP/IT221 45
Index Registers
• SI (Source Index): Source of string operations. Used with DS (or ES).
• DI (Destination Index): Destination of string operation. Used with ES (or DS).
CAP/IT221 46
Instruction Set• Data moving instructions.
– Data can be moved from register to register , memory to memory, register to memory and memory to register.
• Arithmetic - add, subtract, increment, decrement, convert byte/word and compare.
• Logic - AND, OR, exclusive OR, shift/rotate and test. • String manipulation - load, store, move, compare and scan for
byte/word. • Control transfer - conditional, unconditional, call subroutine
and return from subroutine. • Input/Output instructions. • Other - setting/clearing flag bits, stack operations, software
interrupts, etc
Addressing modes• Implied - the data value/data address is implicitly associated with the instruction. • Register - references the data in a register or in a register pair. • Immediate - the data is provided in the instruction. • Direct - the instruction operand specifies the memory address where data is located. • Register indirect - instruction specifies a register containing an address, where data is
located. This addressing mode works with SI, DI, BX and BP registers. • Based - 8-bit or 16-bit instruction operand is added to the contents of a base register (BX or
BP), the resulting value is a pointer to location where data resides. • Indexed - 8-bit or 16-bit instruction operand is added to the contents of an index register (SI
or DI), the resulting value is a pointer to location where data resides. • Based Indexed - the contents of a base register (BX or BP) is added to the contents of an
index register (SI or DI), the resulting value is a pointer to location where data resides. • Based Indexed with displacement - 8-bit or 16-bit instruction operand is added to the
contents of a base register (BX or BP) and index register (SI or DI), the resulting value is a pointer to location where data resides.
Week 4 & 5Introduction to number systems
• Number systems and heir conversions– Decimal, Binary, Octal, Hex decimal
• Arithmetic operations • Binary Addition• Binary Subtraction• Binary Multiplications• Binary Division
• Signed and Magnitude numbersComplement numbers
• Binary Coded decimal numbers
Common Number Systems
System Base SymbolsUsed by humans?
Used in computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa-decimal
16 0, 1, … 9,A, B, … F
No No
Quantities/Counting (1 of 3)
Decimal Binary OctalHexa-
decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7p. 33
Quantities/Counting (2 of 3)
Decimal Binary OctalHexa-
decimal
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Quantities/Counting (3 of 3)
Decimal Binary OctalHexa-
decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17 Etc.
Conversion Among Bases
• The possibilities:
Hexadecimal
Decimal Octal
Binary
pp. 40-46
Binary to Decimal
Hexadecimal
Decimal Octal
Binary
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
1010112 => 1 x 20 = 11 x 21 =
20 x 22 =
01 x 23 =
80 x 24 =
01 x 25 =
32
4310
Bit “0”
Octal to Decimal
Hexadecimal
Decimal Octal
Binary
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 = 42 x 81 = 167 x 82 = 448
46810
Hexadecimal to Decimal
Hexadecimal
Decimal Octal
Binary
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
ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560
274810
Decimal to Binary
Hexadecimal
Decimal Octal
Binary
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.
Example12510 = ?2
2 125 62 12 31 02 15 12 7 12 3 12 1 12 0 1
12510 = 11111012
Octal to Binary
Hexadecimal
Decimal Octal
Binary
Octal to Binary
• Technique– Convert each octal digit to a 3-bit equivalent
binary representation
Example7058 = ?2
7 0 5
111 000 101
7058 = 1110001012
Hexadecimal to Binary
Hexadecimal
Decimal Octal
Binary
Hexadecimal to Binary
• Technique– Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example10AF16 = ?2
1 0 A F
0001 0000 1010 1111
10AF16 = 00010000101011112
Decimal to Octal
Hexadecimal
Decimal Octal
Binary
Decimal to Octal
• Technique– Divide by 8– Keep track of the remainder
Example123410 = ?8
8 1234 154 28 19 28 2 38 0 2
123410 = 23228
Decimal to Hexadecimal
Hexadecimal
Decimal Octal
Binary
Octal to Hexadecimal
• Technique– Use binary as an intermediary
Example10768 = ?16
1 0 7 6
001 000 111 110
2 3 E
10768 = 23E16
Hexadecimal to Octal
Hexadecimal
Decimal Octal
Binary
Hexadecimal to Octal
• Technique– Use binary as an intermediary
Example1F0C16 = ?8
1 F 0 C
0001 1111 0000 1100
1 7 4 1 4
1F0C16 = 174148
Exercise – Convert ...
Don’t use a calculator!
Decimal Binary OctalHexa-
decimal
33
1110101
703
1AF
Skip answer Answer
Exercise – Convert …
Decimal Binary OctalHexa-
decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Answer
Common Powers (1 of 2)
• Base 10Power Preface Symbol
10-12 pico p
10-9 nano n
10-6 micro
10-3 milli m
103 kilo k
106 mega M
109 giga G
1012 tera T
Value
.000000000001
.000000001
.000001
.001
1000
1000000
1000000000
1000000000000
Common Powers (2 of 2)
• Base 2Power Preface Symbol
210 kilo k
220 mega M
230 Giga G
Value
1024
1048576
1073741824
• What is the value of “k”, “M”, and “G”?• In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
Decimal to Hexadecimal
• Technique– Divide by 16– Keep track of the remainder
Example123410 = ?16
123410 = 4D216
16 1234 77 216 4 13 = D16 0 4
Binary to Octal
Hexadecimal
Decimal Octal
Binary
Binary to Octal
• Technique– Group bits in threes, starting on right– Convert to octal digits
Example10110101112 = ?8
1 011 010 111
1 3 2 7
10110101112 = 13278
Binary to Hexadecimal
Hexadecimal
Decimal Octal
Binary
Binary to Hexadecimal
• Technique– Group bits in fours, starting on right– Convert to hexadecimal digits
Example10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
Octal to Hexadecimal
Hexadecimal
Decimal Octal
Binary
Octal to Hexadecimal
• Technique– Use binary as an intermediary
Example10768 = ?16
1 0 7 6
001 000 111 110
2 3 E
10768 = 23E16
Hexadecimal to Octal
Hexadecimal
Decimal Octal
Binary
Hexadecimal to Octal
• Technique– Use binary as an intermediary
Example1F0C16 = ?8
1 F 0 C
0001 1111 0000 1100
1 7 4 1 4
1F0C16 = 174148
Exercise – Convert ...
Don’t use a calculator!
Decimal Binary OctalHexa-
decimal
33
1110101
703
1AF
Skip answer Answer
Exercise – Convert …
Decimal Binary OctalHexa-
decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Answer
Fractions
• Decimal to decimal (just for fun)
pp. 46-50
3.14 => 4 x 10-2 = 0.041 x 10-1 = 0.1
3 x 100 = 3 3.14
Fractions
• Binary to decimal
pp. 46-50
10.1011 => 1 x 2-4 = 0.06251 x 2-3 = 0.1250 x 2-2 = 0.01 x 2-1 = 0.50 x 20 = 0.01 x 21 = 2.0 2.6875
Fractions
• Decimal to binary
p. 50
3.14579
.14579x 20.29158x 20.58316x 21.16632x 20.33264x 20.66528x 21.33056
etc.11.001001...
Exercise – Convert ...
Don’t use a calculator!
Decimal Binary OctalHexa-
decimal
29.8
101.1101
3.07
C.82
Skip answer Answer
Exercise – Convert …
Decimal Binary OctalHexa-
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
Answer
TU/e Processor Design 5Z032 107
• Sign Magnitude: One's Complement Two's Complement
000 = +0 000 = +0 000 = +0001 = +1 001 = +1 001 = +1010 = +2 010 = +2 010 = +2011 = +3 011 = +3 011 = +3100 = -0 100 = -3 100 = -4101 = -1 101 = -2 101 = -3110 = -2 110 = -1 110 = -2111 = -3 111 = -0 111 = -1
• Issues: balance, number of zeros, ease of operations• Which one is best? Why?
Signed binary numbersPossible representations:
Common Powers (1 of 2)
• Base 10Power Preface Symbol
10-12 pico p
10-9 nano n
10-6 micro
10-3 milli m
103 kilo k
106 mega M
109 giga G
1012 tera T
Value
.000000000001
.000000001
.000001
.001
1000
1000000
1000000000
1000000000000
Common Powers (2 of 2)
• Base 2Power Preface Symbol
210 kilo k
220 mega M
230 Giga G
Value
1024
1048576
1073741824
• What is the value of “k”, “M”, and “G”?• In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
Binary Addition (1 of 2)
• Two 1-bit values
pp. 36-38
A B A + B
0 0 0
0 1 1
1 0 1
1 1 10“two”
Binary Addition (2 of 2)
• Two n-bit values– Add individual bits– Propagate carries– E.g.,
10101 21+ 11001 + 25 101110 46
11
Binary Arithmetic Operations 113CS1104-2
Binary Arithmetic Operations (3/6)
SUBTRACTION
Two numbers can be subtracted by subtracting each pair of digits together with borrowing, where needed.
(11001)2- (10011)2 (00110)2
(627)10- (537)10(090)10
Binary Arithmetic Operations 114CS1104-2
Binary Arithmetic Operations (4/6)
Digit subtraction table:
BINARY DECIMAL
0 - 0 - 0 = 0 0 0 - 0 - 0 = 0 0
0 - 1 - 0 = 1 1 0 - 1 - 0 = 1 9
1 - 0 - 0 = 0 1 0 - 2 - 0 = 1 8
1 - 1 - 0 = 0 0 …
0 - 0 - 1 = 1 1 0 - 9 - 1 = 1 0
0 - 1 - 1 = 1 0 1 - 0 - 1 = 0 0
1 - 0 - 1 = 0 0 …
1 - 1 - 1 = 1 1 9 - 9 - 1 = 1 9
Borrow
(11001)2- (10011)2 (00110)2
0 1 1 0
0
0 0 1 1
1
1 0 0 1
1
1 1 0 0
0
0 1 1 0
0
0 0 0 0
0
Binary Arithmetic Operations 115CS1104-2
Binary Arithmetic Operations (5/6)
MULTIPLICATION To multiply two numbers, take each digit of the multiplier
and multiply it with the multiplicand. This produces a number of partial products which are then added.
(11001)2 (214)10 Multiplicand x (10101)2 x (152)10 Multiplier
(11001)2 (428)10 (11001)2 (1070)10 Partial +(11001)2 +(214)10 products (1000001101)2 (32528)10 Result
Binary Arithmetic Operations 116CS1104-2
Binary Arithmetic Operations (6/6)
Digit multiplication table:
DIVISION – can you figure out how this is done? Exercise: Think of the division technique (shift & subtract)
used for decimal numbers and apply it to binary numbers.
BINARY DECIMAL
0 X 0 = 0 0 X 0= 0
0 X 1= 0 0 X 1= 0
1 X 0 = 0 …
1 X 1= 1 1 X 8 = 8
1 X 9= 9
…
9 X 8 = 72
9 X 9 = 81
Multiplication (1 of 3)
• Decimal (just for fun)
pp. 39
35x 105 175 000 35 3675
Multiplication (2 of 3)
• Binary, two 1-bit values
A B A B0 0 00 1 01 0 01 1 1
Multiplication (3 of 3)
• Binary, two n-bit values– As with decimal values– E.g.,
1110 x 1011 1110 1110 0000 111010011010
Negative Numbers: Sign-and-Magnitude
120CS1104-2
Negative Numbers: Sign-and-Magnitude (1/4)
Negative numbers are usually written by writing a minus sign in front.Example:
- (12)10 , - (1100)2
In sign-and-magnitude representation, this sign is usually represented by a bit:
0 for +1 for -
Negative Numbers:Sign-and-Magnitude
121CS1104-2
Negative Numbers:Sign-and-Magnitude (2/4)
Example: an 8-bit number can have 1-bit sign and 7-bit magnitude.
sign magnitude
1s and 2s Complement 122CS1104-2
1s and 2s Complement
Two other ways of representing signed numbers for binary numbers are: 1s-complement 2s-complement
They are preferred over the simple sign-and-magnitude representation.
1s Complement 123CS1104-2
1s Complement (1/3) Given a number x which can be expressed as an n-bit binary
number, its negative value can be obtained in 1s-complement representation using:
- x = 2n - x - 1
Example: With an 8-bit number 00001100, its negative value, expressed in 1s complement, is obtained as follows: -(00001100)2 = - (12)10
= (28 - 12 - 1)10
= (243)10
= (11110011)1s
1s Complement 124CS1104-2
1s Complement (2/3) Essential technique: invert all the bits.
Examples: 1s complement of (00000001)1s = (11111110)1s
1s complement of (01111111)1s = (10000000)1s
Largest Positive Number: 0 1111111 +(127)10
Largest Negative Number: 1 0000000 -(127)10
Zeroes: 0 0000000 1 1111111 Range: -(127)10 to +(127)10
The most significant bit still represents the sign: 0 = +ve; 1 = -ve.
1s Complement 125CS1104-2
1s Complement (3/3)
Examples (assuming 8-bit binary numbers):(14)10 = (00001110)2 = (00001110)1s
-(14)10 = -(00001110)2 = (11110001)1s
-(80)10 = -( ? )2 = ( ? )1s
2s Complement 126CS1104-2
2s Complement (1/4)
Given a number x which can be expressed as an n-bit binary number, its negative number can be obtained in 2s-complement representation using: - x = 2n - x
Example: With an 8-bit number 00001100, its negative value in 2s complement is thus:
-(00001100)2 = - (12)10
= (28 - 12)10
= (244)10
= (11110100)2s
2s Complement 127CS1104-2
2s Complement (2/4)
Essential technique: invert all the bits and add 1.Examples:
2s complement of(00000001)2s = (11111110)1s (invert)
= (11111111)2s (add 1)
2s complement of(01111110)2s = (10000001)1s (invert)
= (10000010)2s (add 1)
2s Complement 128CS1104-2
2s Complement (3/4)
Largest Positive Number: 0 1111111 +(127)10
Largest Negative Number: 1 0000000 -(128)10
Zero: 0 0000000
Range: -(128)10 to +(127)10
The most significant bit still represents the sign: 0 = +ve; 1 = -ve.
2s Complement 129CS1104-2
2s Complement (4/4)
Examples (assuming 8-bit binary numbers):(14)10 = (00001110)2 = (00001110)2s
-(14)10 = -(00001110)2 = (11110010)2s
-(80)10 = -( ? )2 = ( ? )2s
Binary Coded Decimal (BCD) 130CS1104-2
Binary Coded Decimal (BCD) (1/3)
Decimal numbers are more natural to humans. Binary numbers are natural to computers. Quite expensive to convert between the two.
If little calculation is involved, we can use some coding schemes for decimal numbers.
One such scheme is BCD, also known as the 8421 code. Represent each decimal digit as a 4-bit binary code.
Binary Coded Decimal (BCD) 131CS1104-2
Binary Coded Decimal (BCD) (2/3)
Some codes are unused, eg: (1010)BCD, (1011) BCD, …, (1111)
BCD. These codes are considered as errors.
Easy to convert, but arithmetic operations are more complicated.
Suitable for interfaces such as keypad inputs and digital readouts.
Decimal digit 0 1 2 3 4BCD 0000 0001 0010 0011 0100Decimal digit 5 6 7 8 9BCD 0101 0110 0111 1000 1001
Binary Coded Decimal (BCD) 132CS1104-2
Binary Coded Decimal (BCD) (3/3)
Examples:(234)10 = (0010 0011 0100)BCD
(7093)10 = (0111 0000 1001 0011)BCD
(1000 0110)BCD = (86)10
(1001 0100 0111 0010)BCD = (9472)10
Notes: BCD is not equivalent to binary.Example: (234)10 = (11101010)2
Decimal digit 0 1 2 3 4BCD 0000 0001 0010 0011 0100Decimal digit 5 6 7 8 9BCD 0101 0110 0111 1000 1001
Week 6:Over view of Assembly Language 8086.
• Syntax• Program data• variables• program structure• sample programs.
Overview of Assembly language • Executable Instructions
– Program consists of statements one per line– Each statement is instruction which assembler translates to machine
code.– Generate machine code for the processor to execute at runtime– Instructions tell the processor what to do
• Assembler Directives– Provide information to the assembler while translating a program– Used to define data, select memory model, etc.– Non-executable: directives are not part of instruction set
• Syntax of instructions– Shorthand notation for a group of statements– Sequence of instructions, directives, or other macros
• Assembly language instructions have the format:• name Operation Operands Comments• START MOV CX,5 ;Initialize counter
Syntax of instructions• NAME FIELD : may be instruction labels, procedure
names, and variables names.• 1-31 character long may be consists of letters, digits,
and special char.– Eg: COUNTER1 @Character SUM_OF_DIGITS
• OPERATION FIELD: Symbolic code – MOV ADD SUB NOP INC AX
• COMMENT FIELD: say some thing about the statement.• OPERANDS
Argument list
Program Data
• Numbers: binary, hex decimal, decimal• Characters: Characters must be enclosed in double quotes.
“A”• Strings: Strings must be enclosed single quotes ‘hello’.• Variables: Name of the data types and is assigned a
memory locations by the program.• Byte variables: The assembler derivative that defines a
byte variable takes the following forms– name DB initial value– Ex: ALPHA DB 4– Memory is associated
• Word variables: The assembler defines for defining a word variable has the following forms– Name DW initial_value
• Arrays: Just sequence of memory bytes of words.– Symbol Address Constants
B_ARRAY 200h 10h B_ARRAY+1 201h 20hB_ARRAY+2 202h 30h
W-Array DW 1000,40,29887,329Set up array of four words with initial values 1000 40,29887,329
• Symbol Address Constants– W-ARRAY DW 1000,40,29887,329– Set up array of four words with initial values
Few Basic Instructions
• MOV Destination , source
MOV AX,WORD1 ; contents of word 1 will be moved to register AX
MOV AX,BX ; contents of BX will be moved to register AX
XCHG AH,BL Before AH 1A AL 00 BH 00 BL 05After AH 05 AL 00 BH 00 BL 1A
ADD,SUB,INC,DECADD Destination , source same for other operations
INC DestinationDEC Destination
Program Structure• Memory models
– The size of code and data a program can have is determined by specifying memory model using the .MODEL
– SMALL Code and data in one segment
– MEDIUM code in more than one segment and data in one segment.• Data segment : Contains all the variable functions
– .DATA• Word1 DW 2• Word 2 DW 5
• Stack Segment: Set a block of memory– .STACK Size
• .Stack 100H
• Code Segment: Contains the program instructions• Name proc• ;body of the procedure• Name ENDP• .Code • MAIN PROC • ; main procedure instructions• MAIN END P • ;other procedures go here