Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point (real) numbers May be separate FPU (math's co-processor) May be on chip separate FPU (486DX +)
Integer Representation
Only have 0 & 1 to represent everything Positive numbers stored in binary
e.g. 41=00101001
Sign-Magnitude
Left most bit (MSB) is sign bit 0 means positive 1 means negative +18 = 00010010 -18 = 10010010
Drawbacks/problems
Need to consider both sign and magnitude in arithmetic Two representations of zero (+0 and -0)
Twos Compliment
MSB Sign bit For positive Numbers
Sign bit 0 Number zero as Positive
Benefits
One representation of zero Arithmetic works easily
Twos complement
Move the sign bit to the new leftmost position Fill with the copies of sign bit
2s complement
Take Boolean complement of each bit including sign bit Add one two the result
10
11
8 bit 2s compliment
Range of Numbers
16 bit 2s compliment
+32767 = 011111111 11111111 = 215 - 1 -32768 = 100000000 00000000 = -215
12
Normal binary addition Result is positive we get a positive number in 2s complement Result is negative a negative number in 2s complement Carry has to be ignored If the result is larger than the word size being used, then this condition is called overflow When an overflow is occurred ALU must be signaled that the result should not be used.
13
Addition
Overflow rule
If two numbers are added, and they are both positive or both negative, then overflow occurs if and only if the result has the opposite sign.
14
Subtraction
Rule: Take twos compliment of subtrahend and add to minuend
i.e. a - b = a + (-b)
15
16
Multiplication
Complex Work out partial product for each digit Take care with place value (column) Add partial products Multiplication
Multiplier Q , Multiplicand M A reg and c 0 Control logic reads the bit from Q reg and if it is 1 M is added to A and result is stored in A and C A Q Shifted O means only Shifting
17
18
Execution of Example
19
20
Solution 2
Booths algorithm
21
Booths Algorithm
22
23
Division
More complex than multiplication Negative numbers are really bad! Based on long division
24
Remainder
25
26
2s complement Division
Load the divisor-M register and dividend - A, Q registers. Shift A, Q left 1 bit position. If M and A have same signs, performs A=A-M or A=A+M Operation is successful if the sign of A is same before and after the operation.
If A=0 then set Q0= 1 If A not equal to 0 then set Q0= 0
27
M = 0011
28
Real Numbers
Numbers with fractions Could be done in pure binary
1001.1010 = 24 + 20 +2-1 + 2-3 =9.625
Moving?
How do you show where it is?
29
Floating Point
+/- .significand x 2exponent Radix point is at the right of the MSB Biased representation( A fixed value called BIAS from the field to get the true exponent value) Normalized
MSB of the significand is non Zero
30
31
First bit is sign bit First bit of significand value is 1 (no need to store) 127 is subtracted from the true exponent value
32
Using 32 bits
33
Expressible Numbers
34
In 32 bits
8 bits - exponent 23 bits - significand
No. of bits in the exponent increases range also increases But only fixed number of values are expressed, we have reduced the density and precision Only way to increase both is to increase the bits So most computers offers two
Single precision (32 bits) Double precision (64 bits)
35
IEEE 754
Standard for floating point storage Developed to facilitate the portability of programs from processor to another Defines 32 bit single and 64 bit double standards 8 and 11 bit exponent respectively Extended formats also (both significant and exponent)
36
37
The following numbers use the IEEE 32-bit floating-point format. What is the equivalent decimal value? 1 10000011 11000000000000000000000 Express the following numbers in IEEE 32-bit floating-point format:
-1.5 Ans: 1 01111111 10000000000000000000000 384 Ans: 0 10000111 00000000000000000000000
38
40
Addition and subtraction are more complex than multiplication and division, because of the need for alignment. four basic phases of the algorithm
Check for zeros Align significands (adjusting exponents) Add or subtract significands Normalize result
41
42
43
44
45
47
Elements of an Instruction
Operation code (Op code)
Specifies the operation to be performed Specified by a binary code called opcode
49
50
Instruction Representation
In machine code each instruction has a unique bit pattern For human consumption a symbolic representation is used
e.g. ADD, SUB, LOAD
Opcodes represented by abbreviations called as mnemonics Operands can also be represented in this way
ADD R,Y
51
52
Instruction Types
Data processing Data storage (main memory) Data movement (I/O) Program flow control
53
54
55
56
57
58
Fewer addresses
Less complex Shorter length to store More instructions per program Longer execution time
59
Types of Operand
Addresses Numbers
Difference between numbers used in ordinary maths and computers Latter is limited Integer, floating point and decimal
Characters
ASCII and IRA EBCDIC used in IBM
Logical Data
Bits or flags
61
8 bit Byte 16 bit word 32 bit double word 64 bit quad word 128 bit double quad word Data accessed across 32 bit bus in units of double word read at addresses divisible by 4 Little endian
62
63
Packed byte and packed byte integer Bytes packed into 64-bit quadword or 128-bit double quadword Packed word and packed word integer 16-bit words packed into 64-bit quadword or 128-bit double quadword Packed doubleword and packed doubleword integer 32-bit double word packed into 64-bit quadword or 128-bit double quad word Packed quad word and packed quadword integer Two 64-bit quadwords packed into 128-bit double quadword Packed single-precision floating-point and packed double-precision floating-point Four 32-bit floating-point or two 64-bit floating-point values packed into a 128-bit double quadword
64
8 (byte), 16 (halfword), 32 (word) bits Halfword access should be halfword aligned and word accesses should be word aligned Nonaligned access Default Treated as truncated Bits[1:0] treated as zero for word Bit[0] treated as zero for halfword Data abort signal indicates alignment fault for attempting unaligned access All data types supports both Unsigned integer and Twos-complement signed
65
Majority of ARM processors do not provide floatingpoint hardware Saves power and area Floating-point arithmetic implemented in software
66
67
Types of Operation
Data Transfer Arithmetic Logical Conversion I/O System Control Transfer of Control
68
Data Transfer
Specify
Source Destination length of data
69
70
Arithmetic
71
LOGICAL
72
73
Conversion
74
Input/output
May be specific instructions May be done using data movement instructions (memory mapped) May be done by a separate controller (DMA)
75
Systems Control
Executed on special state Used for Control registers For operating systems use
76
77
78
Transfer of Control
Branch or Jump instruction
Conditional Unconditional
Consider subtraction
BRP X - Branch to location X if result is positive. BRN X - Branch to location X if result is negative. BRZ X - Branch to location X if result is zero. BRO X - Branch to location X if overflow occurs.
80
Skip
Skip the next instruction e.g. increment and skip if zero ISZ Register1
81
Procedure call
Advantages
Code reuse Efficient use of storage
82
83
Use of Stack
84
85
86
X 86 operation types
87
88
89
90
91
92
Addressing Modes
Immediate Direct Indirect Register Register Indirect Displacement Stack
94
All architectures provides more than one of these addressing modes How the processor can determine which address mode is being used ?
one or more bits in the instruction format can be used as a mode field. Value of the mode field determines which addressing mode is to be used
95
Immediate Addressing
96
Immediate Addressing
Operand is part of instruction Operand = address field e.g. ADD 5
Add 5 to contents of accumulator 5 is operand
97
Direct addressing
98
Direct Addressing
Address field contains address of operand Effective address (EA) = address field (A) e.g. ADD A
Add contents of cell A to accumulator Look in memory at address A for operand
Single memory reference to access data No additional calculations to work out effective address Limited address space
99
Indirect Addressing
100
Address field refer to the address of a word in memory, which in turn contains a full-length address of the operand EA = (A)
Look in A, find address (A) and look there for operand
e.g. ADD (A)
Indirect Addressing
Large address space Multiple memory accesses to find operand Hence slower
101
Register Addressing
102
Operand is held in register named in address field EA = R Limited number of registers Advantages
Small address field is needed for instructions so shorter instructions less time
Register Addressing
103
104
105
Displacement Addressing
106
Displacement Addressing
Uses both direct and register indirect addressing EA = A + (R) Address field hold two values
A = base value R = register that holds displacement
107
Relative Addressing
A version of displacement addressing R = Program counter, PC EA = A + (PC)
108
Base-Register Addressing
A holds displacement R contains a main memory address
109
Indexed Addressing
A = base R = displacement EA = A + R Good for accessing arrays
110
Combinations
R value is incremented or decremented automatically auto indexing Post index indexing is performed after the indirection
EA = (A) + (R) Address is fetched and indexed with the register value
111
Stack Addressing
Operand is on top of stack Stack pointer
112
113
114
ARM Addressing Modes Load/Store Only instructions that reference memory base register plus offset Offset Offset added to or subtracted from base register contents to form the memory address Preindex Memory address is formed as for offset addressing Memory address also written back to base register Postindex Memory address is base register value Offset added or subtracted Result written back to base register Base register acts as index register for preindex and postindex addressing Offset either immediate value in instruction or another register
115
116
Data Processing
Register addressing Or mixture of register and immediate addressing
Branch
Immediate
117
118
119
Instruction Formats
Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than one instruction format in an instruction set
120
Instruction Length
Affected by and affects:
Memory size Memory organization Bus structure CPU complexity CPU speed
121
Allocation of Bits
Number of addressing modes Number of operands Register versus memory Number of register sets Address range Address granularity
122
Assembly language
Machines store and understand binary instructions E.g. N= I + J + K initialize I=2, J=3, K=4
123
124
Improvements
Use hexadecimal rather than binary
Code as series of lines
Hex address and memory address
Add symbolic names or mnemonics for instructions Three fields per line
Location address Three letter opcode If memory reference: address
First field (address) now symbolic Memory references in third field now symbolic Now have assembly language and need an assembler to translate
126