Download presentation
Presentation is loading. Please wait.
Published byEvelyn Lucas Modified over 9 years ago
1
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.
2
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
3
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)
4
Block diagram of computer Figure 1.1. Basic functional units of a computer. I/OProcessor Output Memory Input and Arithmetic logic Control
5
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
6
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
7
Bus Structure
8
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
9
Von Neumann Machine Architecture and its Functions:
10
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)
11
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.
12
Computer Functions
13
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
14
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.
15
Programming Languages. There are 4 types of programming languages. High Level Language Middle Level Language Low level Language Assembly Level Language.
16
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
17
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.
18
Week 3 Organization of the IBM Personal computers Architecture Registers Memories Addressing modes Instruction sets Interrupts
19
Organization of the 8088/8086 CAP/IT221 19
20
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.
21
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.
22
Organization of the 8088/8086 16-bit registers, 1M Bytes Memory Registers: Information is stored in registers Registers are classified according to the functions they perform CAP/IT221 22
23
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
24
Register CAP/IT221 24
25
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
26
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
27
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
28
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
29
Instruction pointer IP (Instruction pointer): Points to the next instruction. Used with CS.
30
Flags register Flags: Bits specify status of CPU and information about the results of the arithmetic operations. CAP/IT221 30
31
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.
32
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)
33
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.
34
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
35
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
36
Memory Segment 00000 10000 20000 30000 40000 50000 60000 70000 80000 90000 A0000 B0000 C0000 D0000 E0000 F0000 One Segment 8000:0000 8000:FFFF segmentoffset CAP/IT221 36
37
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
38
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
39
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
40
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.
41
Software interrupts INT instruction - breakpoint interrupt. This is a type 3 interrupt. INT 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).
42
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
43
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.
44
Segmented Memory linear addresses one segment CAP/IT221 44
45
Pointer and Index Registers SP, 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
46
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
47
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
48
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.
49
Week 4 & 5 Introduction 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 numbers Complement numbers Binary Coded decimal numbers
50
Common Number Systems SystemBaseSymbols Used by humans? Used in computers? Decimal100, 1, … 9YesNo Binary20, 1NoYes Octal80, 1, … 7No Hexa- decimal 160, 1, … 9, A, B, … F No
51
Quantities/Counting (1 of 3) DecimalBinaryOctal Hexa- decimal 0000 1111 21022 31133 410044 510155 611066 711177 p. 33
52
Quantities/Counting (2 of 3) DecimalBinaryOctal Hexa- decimal 81000108 91001119 10101012A 11101113B 12110014C 13110115D 14111016E 15111117F
53
Quantities/Counting (3 of 3) DecimalBinaryOctal Hexa- decimal 16100002010 17100012111 18100102212 19100112313 20101002414 21101012515 22101102616 23101112717 Etc.
54
Conversion Among Bases The possibilities: Hexadecimal DecimalOctal Binary pp. 40- 46
55
Binary to Decimal Hexadecimal DecimalOctal Binary
56
Binary to Decimal Technique – Multiply each bit by 2 n, 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
57
Example 101011 2 => 1 x 2 0 = 1 1 x 2 1 = 2 0 x 2 2 = 0 1 x 2 3 = 8 0 x 2 4 = 0 1 x 2 5 = 32 43 10 Bit “0”
58
Octal to Decimal Hexadecimal DecimalOctal Binary
59
Octal to Decimal Technique – Multiply each bit by 8 n, 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
60
Example 724 8 => 4 x 8 0 = 4 2 x 8 1 = 16 7 x 8 2 = 448 468 10
61
Hexadecimal to Decimal Hexadecimal DecimalOctal Binary
62
Hexadecimal to Decimal Technique – Multiply each bit by 16 n, 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
63
Example ABC 16 =>C x 16 0 = 12 x 1 = 12 B x 16 1 = 11 x 16 = 176 A x 16 2 = 10 x 256 = 2560 2748 10
64
Decimal to Binary Hexadecimal DecimalOctal Binary
65
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.
66
Example 125 10 = ? 2 2 125 62 1 2 31 0 2 15 1 2 7 1 2 3 1 2 1 1 2 0 1 125 10 = 1111101 2
67
Octal to Binary Hexadecimal DecimalOctal Binary
68
Octal to Binary Technique – Convert each octal digit to a 3-bit equivalent binary representation
69
Example 705 8 = ? 2 7 0 5 111 000 101 705 8 = 111000101 2
70
Hexadecimal to Binary Hexadecimal DecimalOctal Binary
71
Hexadecimal to Binary Technique – Convert each hexadecimal digit to a 4-bit equivalent binary representation
72
Example 10AF 16 = ? 2 1 0 A F 0001 0000 1010 1111 10AF 16 = 0001000010101111 2
73
Decimal to Octal Hexadecimal DecimalOctal Binary
74
Decimal to Octal Technique – Divide by 8 – Keep track of the remainder
75
Example 1234 10 = ? 8 8 1234 154 2 8 19 2 8 2 3 8 0 2 1234 10 = 2322 8
76
Decimal to Hexadecimal Hexadecimal DecimalOctal Binary
77
Octal to Hexadecimal Technique – Use binary as an intermediary
78
Example 1076 8 = ? 16 1 0 7 6 001 000 111 110 2 3 E 1076 8 = 23E 16
79
Hexadecimal to Octal Hexadecimal DecimalOctal Binary
80
Hexadecimal to Octal Technique – Use binary as an intermediary
81
Example 1F0C 16 = ? 8 1 F 0 C 0001 1111 0000 1100 1 7 4 1 4 1F0C 16 = 17414 8
82
Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal 33 1110101 703 1AF Skip answer Answer
83
Exercise – Convert … DecimalBinaryOctal Hexa- decimal 331000014121 117111010116575 4511110000117031C3 4311101011116571AF Answer
84
Common Powers (1 of 2) Base 10 PowerPrefaceSymbol 10 -12 picop 10 -9 nanon 10 -6 micro 10 -3 millim 10 3 kilok 10 6 megaM 10 9 gigaG 10 12 teraT Value.000000000001.000000001.000001.001 1000 1000000 1000000000 1000000000000
85
Common Powers (2 of 2) Base 2 PowerPrefaceSymbol 2 10 kilok 2 20 megaM 2 30 GigaG 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
86
Decimal to Hexadecimal Technique – Divide by 16 – Keep track of the remainder
87
Example 1234 10 = ? 16 1234 10 = 4D2 16 16 1234 77 2 16 4 13 = D 16 0 4
88
Binary to Octal Hexadecimal DecimalOctal Binary
89
Binary to Octal Technique – Group bits in threes, starting on right – Convert to octal digits
90
Example 1011010111 2 = ? 8 1 011 010 111 1 3 2 7 1011010111 2 = 1327 8
91
Binary to Hexadecimal Hexadecimal DecimalOctal Binary
92
Binary to Hexadecimal Technique – Group bits in fours, starting on right – Convert to hexadecimal digits
93
Example 1010111011 2 = ? 16 10 1011 1011 2 B B 1010111011 2 = 2BB 16
94
Octal to Hexadecimal Hexadecimal DecimalOctal Binary
95
Octal to Hexadecimal Technique – Use binary as an intermediary
96
Example 1076 8 = ? 16 1 0 7 6 001 000 111 110 2 3 E 1076 8 = 23E 16
97
Hexadecimal to Octal Hexadecimal DecimalOctal Binary
98
Hexadecimal to Octal Technique – Use binary as an intermediary
99
Example 1F0C 16 = ? 8 1 F 0 C 0001 1111 0000 1100 1 7 4 1 4 1F0C 16 = 17414 8
100
Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal 33 1110101 703 1AF Skip answer Answer
101
Exercise – Convert … DecimalBinaryOctal Hexa- decimal 331000014121 117111010116575 4511110000117031C3 4311101011116571AF Answer
102
Fractions Decimal to decimal (just for fun) pp. 46- 50 3.14 =>4 x 10 -2 = 0.04 1 x 10 -1 = 0.1 3 x 10 0 = 3 3.14
103
Fractions Binary to decimal pp. 46- 50 10.1011 => 1 x 2 -4 = 0.0625 1 x 2 -3 = 0.125 0 x 2 -2 = 0.0 1 x 2 -1 = 0.5 0 x 2 0 = 0.0 1 x 2 1 = 2.0 2.6875
104
Fractions Decimal to binary p. 50 3.14579.14579 x 2 0.29158 x 2 0.58316 x 2 1.16632 x 2 0.33264 x 2 0.66528 x 2 1.33056 etc. 11.001001...
105
Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal 29.8 101.1101 3.07 C.82 Skip answer Answer
106
Exercise – Convert … DecimalBinaryOctal Hexa- decimal 29.811101.110011…35.63…1D.CC… 5.8125101.11015.645.D 3.10937511.0001113.073.1C 12.50781251100.1000001014.404C.82 Answer
107
TU/e Processor Design 5Z032107 Sign Magnitude: One's Complement Two's Complement 000 = +0000 = +0000 = +0 001 = +1001 = +1001 = +1 010 = +2010 = +2010 = +2 011 = +3011 = +3011 = +3 100 = -0100 = -3100 = -4 101 = -1101 = -2101 = -3 110 = -2110 = -1110 = -2 111 = -3111 = -0111 = -1 Issues: balance, number of zeros, ease of operations Which one is best? Why? Signed binary numbers Possible representations:
109
Common Powers (1 of 2) Base 10 PowerPrefaceSymbol 10 -12 picop 10 -9 nanon 10 -6 micro 10 -3 millim 10 3 kilok 10 6 megaM 10 9 gigaG 10 12 teraT Value.000000000001.000000001.000001.001 1000 1000000 1000000000 1000000000000
110
Common Powers (2 of 2) Base 2 PowerPrefaceSymbol 2 10 kilok 2 20 megaM 2 30 GigaG 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
111
Binary Addition (1 of 2) Two 1-bit values pp. 36- 38 ABA + B 000 011 101 1110 “two”
112
Binary Addition (2 of 2) Two n-bit values – Add individual bits – Propagate carries – E.g., 10101 21 + 11001 + 25 101110 46 11
113
CS1104-2Binary Arithmetic Operations113 Binary Arithmetic Operations (3/6) SUBTRACTION Two numbers can be subtracted by subtracting each pair of digits together with borrowing, where needed.
114
CS1104-2Binary Arithmetic Operations114 Binary Arithmetic Operations (4/6) Digit subtraction table: Borrow
115
CS1104-2Binary Arithmetic Operations115 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.
116
CS1104-2Binary Arithmetic Operations116 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.
117
Multiplication (1 of 3) Decimal (just for fun) pp. 39 35 x 105 175 000 35 3675
118
Multiplication (2 of 3) Binary, two 1-bit values AB A B 000 010 100 111
119
Multiplication (3 of 3) Binary, two n-bit values – As with decimal values – E.g., 1110 x 1011 1110 1110 0000 1110 10011010
120
CS1104-2Negative Numbers: Sign-and-Magnitude120 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 -
121
CS1104-2Negative Numbers:Sign-and-Magnitude121 Negative Numbers: Sign-and-Magnitude (2/4) Example: an 8-bit number can have 1-bit sign and 7-bit magnitude. sign magnitude
122
CS1104-21s and 2s Complement122 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.
123
CS1104-21s Complement123 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 = 2 n - x - 1 Example: With an 8-bit number 00001100, its negative value, expressed in 1s complement, is obtained as follows: -(00001100) 2 = - (12) 10 = (2 8 - 12 - 1) 10 = (243) 10 = (11110011) 1s
124
CS1104-21s Complement124 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.
125
CS1104-21s Complement125 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
126
CS1104-22s Complement126 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 = 2 n - x Example: With an 8-bit number 00001100, its negative value in 2s complement is thus: -(00001100) 2 = - (12) 10 = (2 8 - 12) 10 = (244) 10 = (11110100) 2s
127
CS1104-22s Complement127 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)
128
CS1104-22s Complement128 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.
129
CS1104-22s Complement129 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
130
CS1104-2Binary Coded Decimal (BCD)130 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.
131
CS1104-2Binary Coded Decimal (BCD)131 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.
132
CS1104-2Binary Coded Decimal (BCD)132 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
133
Week 6:Over view of Assembly Language 8086. Syntax Program data variables program structure sample programs.
134
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 OperationOperandsComments STARTMOVCX,5 ;Initialize counter
135
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
136
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
137
Word variables: The assembler defines for defining a word variable has the following forms – Name DWinitial_value Arrays: Just sequence of memory bytes of words. – SymbolAddress Constants B_ARRAY 200h10h B_ARRAY+1201h20h B_ARRAY+2202h30h W-Array DW 1000,40,29887,329 Set up array of four words with initial values 1000 40,29887,329
138
SymbolAddress Constants – W-ARRAYDW1000,40,29887,329 – Set up array of four words with initial values
139
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 05 After AH 05 AL 00 BH 00 BL 1A ADD,SUB,INC,DEC ADD Destination, source same for other operations INC Destination DEC Destination
140
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 2DW 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.