SlideShare a Scribd company logo
Machine Instructions and
Programs
Number, Arithmetic Operations,
and Characters
Signed Integer
• 3 major representations:
Sign-magnitude
One’s complement
Two’s complement
• Assumptions:
4-bit machine word
16 different values can be represented
Roughly half are positive, half are negative
Sign and Magnitude Representation
0000
0111
0011
1011
1111
1110
1101
1100
1010
1001
1000
0110
0101
0100
0010
0001
+0
+1
+2
+3
+4
+5
+6
+7
-0
-1
-2
-3
-4
-5
-6
-7
0 100 = + 4
1 100 = - 4
+
-
High order bit is sign: 0 = positive (or zero), 1 = negative
Three low order bits is the magnitude: 0 (000) thru 7 (111)
Number range for n bits = +/-2n-1 -1
Two representations for 0
One’s Complement Representation
• Subtraction implemented by addition & 1's complement
• Still two representations of 0! This causes some problems
• Some complexities in addition
0000
0111
0011
1011
1111
1110
1101
1100
1010
1001
1000
0110
0101
0100
0010
0001
+0
+1
+2
+3
+4
+5
+6
+7
-7
-6
-5
-4
-3
-2
-1
-0
0 100 = + 4
1 011 = - 4
+
-
Two’s Complement Representation
• Only one representation for 0
• One more negative number than positive number
0000
0111
0011
1011
1111
1110
1101
1100
1010
1001
1000
0110
0101
0100
0010
0001
+0
+1
+2
+3
+4
+5
+6
+7
-8
-7
-6
-5
-4
-3
-2
-1
0 100 = + 4
1 100 = - 4
+
-
like 1's comp
except shifted
one position
clockwise
Binary, Signed-Integer Representations
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
0
0
1
1
0
0
0
0
1
1
0
0
1
1
1
0
1
0
1
0
1
0
0
1
0
1
0
1
0
1
1
+
1
-
2
+
3
+
4
+
5
+
6
+
7
+
2
-
3
-
4
-
5
-
6
-
7
-
8
-
0
+
0
-
1
+
2
+
3
+
4
+
5
+
6
+
7
+
0
+
7
-
6
-
5
-
4
-
3
-
2
-
1
-
0
-
1
+
2
+
3
+
4
+
5
+
6
+
7
+
0
+
7
-
6
-
5
-
4
-
3
-
2
-
1
-
b3 b2b1b0
Sign and
magnitude 1's complement 2's complement
B Values represented
Binary, signed-integer representations.
Addition and Subtraction – 2’s Complement
4
+ 3
7
0100
0011
0111
-4
+ (-3)
-7
1100
1101
11001
4
- 3
1
0100
1101
10001
-4
+ 3
-1
1100
0011
1111
If carry-in to the high
order bit =
carry-out then ignore
carry
if carry-in differs from
carry-out then overflow
Simpler addition scheme makes twos complement the most common
choice for integer number systems within digital systems
2’s-Complement Add and Subtract
Operations
1 1 0 1
0 1 1 1
0 1 0 0
0 0 1 0
1 1 0 0
1 1 1 0
0 1 1 0
1 1 0 1
0 0 1 1
1 0 0 1
0 1 0 1
1 1 1 0
1 0 0 1
1 1 1 1
1 0 0 0
0 0 1 0
0 0 1 1
0 1 0 1
4
+
( )
2
-
( )
3
+
( )
2
-
( )
8
-
( )
5
+
( )
+
+
+
+
+
+
1 1 1 0
0 1 0 0
1 0 1 0
0 1 1 1
1 1 0 1
0 1 0 0
6
-
( )
2
-
( )
4
+
( )
3
-
( )
4
+
( )
7
+
( )
+
+
(b)
(d)
1 0 1 1
1 1 1 0
1 0 0 1
1 1 0 1
1 0 0 1
0 0 1 0
0 1 0 0
0 1 1 0
0 0 1 1
1 0 0 1
1 0 1 1
1 0 0 1
0 0 0 1
0 0 1 0
1 1 0 1
0 1 0 1
0 0 1 0
0 0 1 1
5
-
( )
2
+
( )
3
+
( )
5
+
( )
2
+
( )
4
+
( )
2
-
( )
7
-
( )
3
-
( )
7
-
( )
6
+
( )
3
+
( )
1
+
( )
7
-
( )
5
-
( )
7
-
( )
2
+
( )
3
-
( )
+
+
-
-
-
-
-
-
(a)
(c)
(e)
(f)
(g)
(h)
(i)
(j)
2's-complement Add and Subtract operations.
Overflow - Add two positive numbers to get a negative
number or two negative numbers to get a positive number
5 + 3 = -8 -7 - 2 = +7
0000
0001
0010
0011
1000
0101
0110
0100
1001
1010
1011
1100
1101
0111
1110
1111
+0
+1
+2
+3
+4
+5
+6
+7
-8
-7
-6
-5
-4
-3
-2
-1
0000
0001
0010
0011
1000
0101
0110
0100
1001
1010
1011
1100
1101
0111
1110
1111
+0
+1
+2
+3
+4
+5
+6
+7
-8
-7
-6
-5
-4
-3
-2
-1
Overflow Conditions
5
3
-8
0 1 1 1
0 1 0 1
0 0 1 1
1 0 0 0
-7
-2
7
1 0 0 0
1 0 0 1
1 1 0 0
1 0 1 1 1
5
2
7
0 0 0 0
0 1 0 1
0 0 1 0
0 1 1 1
-3
-5
-8
1 1 1 1
1 1 0 1
1 0 1 1
1 1 0 0 0
Overflow Overflow
No overflow No overflow
Overflow when carry-in to the high-order bit does not equal carry out
Sign Extension
• Task:
– Given w-bit signed integer x
– Convert it to w+k-bit integer with same value
• Rule:
– Make k copies of sign bit:
– X ′ = xw–1 ,…, xw–1 , xw–1 , xw–2 ,…, x0
k copies of MSB
• • •
X
X ′ • • • • • •
• • •
w
w
k
Sign Extension Example
short int x = 15213;
int ix = (int) x;
short int y = -15213;
int iy = (int) y;
Decimal Hex Binary
x 15213 3B 6D 00111011 01101101
ix 15213 00 00 C4 92 00000000 00000000 00111011 01101101
y -15213 C4 93 11000100 10010011
iy -15213 FF FF C4 93 11111111 11111111 11000100 10010011
Memory Locations, Addresses,
and Operations
Memory Location, Addresses, and
Operation
• Memory consists of
many millions of
storage cells, each
of which can store 1
bit.
• Data is usually
accessed in n-bit
groups. n is called
word length.
second word
first word
Memory words.
nbits
last word
i th word
•
•
•
•
•
•
Memory Location, Addresses, and
Operation
• 32-bit word length example
(b) Four characters
character
character
character character
(a) A signed integer
Sign bit: for positive numbers
for negative numbers
ASCII
ASCII
ASCII
ASCII
32 bits
8 bits 8 bits 8 bits 8 bits
b31 b30 b1 b0
b31 0
=
b31 1
=
•
•
•
Memory Location, Addresses, and
Operation
• To retrieve information from memory, either for one
word or one byte (8-bit), addresses for each location are
needed.
• A k-bit address memory has 2k memory locations, namely
0 – 2k-1, called memory space/ address space.
• 24-bit memory: 224 = 16,777,216 = 16M (1M=220)
• 32-bit memory: 232 = 4G (1G=230)
• 1K(kilo)=210
• 1T(tera)=240
Memory Location, Addresses, and
Operation
• It is impractical to assign distinct addresses to
individual bit locations in the memory.
• The most practical assignment is to have
successive addresses refer to successive byte
locations in the memory – byte-addressable
memory.
• Byte locations have addresses 0, 1, 2, … If
word length is 32 bits, they successive words
are located at addresses 0, 4, 8,…
Big-Endian and Little-Endian
Assignments
2
k
4
- 2
k
3
- 2
k
2
- 2
k
1
- 2
k
4
-
2
k
4
-
0 1 2 3
4 5 6 7
0
0
4
2
k
1
- 2
k
2
- 2
k
3
- 2
k
4
-
3 2 1 0
7 6 5 4
Byte address
Byte address
(a) Big-endian assignment (b) Little-endian assignment
4
Word
address
•
•
•
•
•
•
Figure 2.7. Byte and word addressing.
Big-Endian: lower byte addresses are used for the most significant bytes of the word
Little-Endian: opposite ordering. lower byte addresses are used for the less significant
bytes of the word
Memory Location, Addresses, and
Operation
• Address ordering of bytes
• Word alignment
– Words are said to be aligned in memory if they
begin at a byte addr. that is a multiple of the num
of bytes in a word.
• 16-bit word: word addresses: 0, 2, 4,….
• 32-bit word: word addresses: 0, 4, 8,….
• 64-bit word: word addresses: 0, 8,16,….
• Access numbers, characters, and character
strings
Memory Operation
• Load (or Read or Fetch)
 Copy the content. The memory content doesn’t change.
 Address – Load
 Registers can be used
• Store (or Write)
 Overwrite the content in memory
 Address and Data – Store
 Registers can be used
Instruction and Instruction
Sequencing
“Must-Perform” Operations
• Data transfers between the memory and the
processor registers
• Arithmetic and logic operations on data
• Program sequencing and control
• I/O transfers
Register Transfer Notation
• Identify a location by a symbolic name
standing for its hardware binary address (LOC,
R0,…)
• Contents of a location are denoted by placing
square brackets around the name of the
location (R1←[LOC], R3 ←[R1]+[R2])
• Register Transfer Notation (RTN)
Assembly Language Notation
• Represent machine instructions and programs.
• Move LOC, R1 = R1←[LOC]
• Add R1, R2, R3 = R3 ←[R1]+[R2]
CPU Organization
• Single Accumulator
– Result usually goes to the Accumulator
– Accumulator has to be saved to memory quite often
• General Register
– Registers hold operands thus reduce memory traffic
– Register bookkeeping
• Stack
– Operands and result are always in the stack
Instruction Formats
• Three-Address Instructions
– ADD R1, R2, R3 R3 ← [R1] + [R2]
• Two-Address Instructions
– ADD R1, R2 R2 ← [R1] + [R2]
• One-Address Instructions
– ADD M AC ← AC + [M]
• Zero-Address Instructions
– ADD TOS ← [TOS] + [(TOS – 1)]
• RISC Instructions
– Lots of registers. Memory is restricted to Load & Store
Opcode Operand(s) or Address(es)
Instruction Formats
Example: Evaluate X = (A+B) ∗ (C+D)
• Three-Address
1. ADD A, B, R1 ; R1 ← [A] + [B]
2. ADD C, D, R2 ; R2 ← [C] + [D]
3. MUL R1, R2, X ; X ← [R1] ∗ [R2]
Instruction Formats
Example: Evaluate X = (A+B) ∗ (C+D)
• Two-Address
1. MOV A, R1 ; R1 ← [A]
2. ADD B, R1 ; R1 ← [R1] + [B]
3. MOV C, R2 ; R2 ← [C]
4. ADD D, R2 ; R2 ← [R2] + [D]
5. MUL R2, R1 ; R1 ← [R1] ∗ [R2]
6. MOV R1, X ; X ← [R1]
Instruction Formats
Example: Evaluate X = (A+B) ∗ (C+D)
• One-Address
1. LOAD A ; AC ← [A]
2. ADD B ; AC ← [AC] + [B]
3. STORE T ; T ← [AC]
4. LOAD C ; AC ← [C]
5. ADD D ; AC ← [AC] + [D]
6. MUL T ; AC ← [AC] ∗ [T]
7. STORE X ; X ← [AC]
Instruction Formats
Example: Evaluate X = (A+B) ∗ (C+D)
• Zero-Address
1. PUSH A ; TOS ← [A]
2. PUSH B ; TOS ← [B]
3. ADD ; TOS ← [A] + [B]
4. PUSH C ; TOS ← [C]
5. PUSH D ; TOS ← [D]
6. ADD ; TOS ← [C] + [D]
7. MUL ; TOS ← (C+D)∗(A+B)
8. POP X ; X ← [TOS]
Instruction Formats
Example: Evaluate X = (A+B) ∗ (C+D)
• RISC
1. LOAD A, R1 ; R1 ← [A]
2. LOAD B, R2 ; R2 ← [B]
3. LOAD C, R3 ; R3 ← [C]
4. LOAD D, R4 ; R4 ← [D]
5. ADD R1, R2, R1 ; R1 ← [R1] + [R2]
6. ADD R3, R4, R3 ; R3 ← [R3] + [R4]
7. MUL R1, R3, R1 ; R1 ← [R1] ∗ [R3]
8. STORE R1, X ; X ← [R1]
Using Registers
• Registers are faster
• Shorter instructions
– The number of registers is smaller (e.g. 32
registers need 5 bits)
• Potential speedup
• Minimize the frequency with which data is
moved back and forth between the memory
and processor registers.
Ad

More Related Content

What's hot (20)

Numbersystemcont
NumbersystemcontNumbersystemcont
Numbersystemcont
Sajib
 
IRJET- On Greatest Common Divisor and its Application for a Geometrical S...
IRJET-  	  On Greatest Common Divisor and its Application for a Geometrical S...IRJET-  	  On Greatest Common Divisor and its Application for a Geometrical S...
IRJET- On Greatest Common Divisor and its Application for a Geometrical S...
IRJET Journal
 
Elliptic Curve Cryptography
Elliptic Curve CryptographyElliptic Curve Cryptography
Elliptic Curve Cryptography
JorgeVillamarin5
 
Digital Logic & Design
Digital Logic & DesignDigital Logic & Design
Digital Logic & Design
Rokonuzzaman Rony
 
Dld 2
Dld 2Dld 2
Dld 2
MirOmranudinAbhar
 
Mcsl 17 ALP lab manual
Mcsl 17 ALP lab manualMcsl 17 ALP lab manual
Mcsl 17 ALP lab manual
sannnnnnnnnnnnnnnn
 
Top school in delhi ncr
Top school in delhi ncrTop school in delhi ncr
Top school in delhi ncr
Edhole.com
 
Introduction to Elliptic Curve Cryptography
Introduction to Elliptic Curve CryptographyIntroduction to Elliptic Curve Cryptography
Introduction to Elliptic Curve Cryptography
David Evans
 
Logic Equation Simplification
Logic Equation SimplificationLogic Equation Simplification
Logic Equation Simplification
School of Design Engineering Fashion & Technology (DEFT), University of Wales, Newport
 
Running Free with the Monads
Running Free with the MonadsRunning Free with the Monads
Running Free with the Monads
kenbot
 
Error control coding bch, reed-solomon etc..
Error control coding   bch, reed-solomon etc..Error control coding   bch, reed-solomon etc..
Error control coding bch, reed-solomon etc..
Madhumita Tamhane
 
Understanding CTLE
Understanding CTLEUnderstanding CTLE
Understanding CTLE
继顺(Jeffrey) 王
 
Ch4 Boolean Algebra And Logic Simplication1
Ch4 Boolean Algebra And Logic Simplication1Ch4 Boolean Algebra And Logic Simplication1
Ch4 Boolean Algebra And Logic Simplication1
Qundeel
 
hexadecimal notes By ZAK
hexadecimal notes By ZAKhexadecimal notes By ZAK
hexadecimal notes By ZAK
Tabsheer Hasan
 
Elliptical curve cryptography
Elliptical curve cryptographyElliptical curve cryptography
Elliptical curve cryptography
Barani Tharan
 
Gate-Cs 1999
Gate-Cs 1999Gate-Cs 1999
Gate-Cs 1999
Ravi Rajput
 
boolean algebra and logic simplification
boolean algebra and logic simplificationboolean algebra and logic simplification
boolean algebra and logic simplification
Unsa Shakir
 
Image Cryptography and Steganography
Image Cryptography and SteganographyImage Cryptography and Steganography
Image Cryptography and Steganography
Mohammad Amin Amjadi
 
Ch3
Ch3Ch3
Ch3
Teksify
 
The International Journal of Engineering and Science (IJES)
The International Journal of Engineering and Science (IJES)The International Journal of Engineering and Science (IJES)
The International Journal of Engineering and Science (IJES)
theijes
 
Numbersystemcont
NumbersystemcontNumbersystemcont
Numbersystemcont
Sajib
 
IRJET- On Greatest Common Divisor and its Application for a Geometrical S...
IRJET-  	  On Greatest Common Divisor and its Application for a Geometrical S...IRJET-  	  On Greatest Common Divisor and its Application for a Geometrical S...
IRJET- On Greatest Common Divisor and its Application for a Geometrical S...
IRJET Journal
 
Elliptic Curve Cryptography
Elliptic Curve CryptographyElliptic Curve Cryptography
Elliptic Curve Cryptography
JorgeVillamarin5
 
Top school in delhi ncr
Top school in delhi ncrTop school in delhi ncr
Top school in delhi ncr
Edhole.com
 
Introduction to Elliptic Curve Cryptography
Introduction to Elliptic Curve CryptographyIntroduction to Elliptic Curve Cryptography
Introduction to Elliptic Curve Cryptography
David Evans
 
Running Free with the Monads
Running Free with the MonadsRunning Free with the Monads
Running Free with the Monads
kenbot
 
Error control coding bch, reed-solomon etc..
Error control coding   bch, reed-solomon etc..Error control coding   bch, reed-solomon etc..
Error control coding bch, reed-solomon etc..
Madhumita Tamhane
 
Ch4 Boolean Algebra And Logic Simplication1
Ch4 Boolean Algebra And Logic Simplication1Ch4 Boolean Algebra And Logic Simplication1
Ch4 Boolean Algebra And Logic Simplication1
Qundeel
 
hexadecimal notes By ZAK
hexadecimal notes By ZAKhexadecimal notes By ZAK
hexadecimal notes By ZAK
Tabsheer Hasan
 
Elliptical curve cryptography
Elliptical curve cryptographyElliptical curve cryptography
Elliptical curve cryptography
Barani Tharan
 
boolean algebra and logic simplification
boolean algebra and logic simplificationboolean algebra and logic simplification
boolean algebra and logic simplification
Unsa Shakir
 
Image Cryptography and Steganography
Image Cryptography and SteganographyImage Cryptography and Steganography
Image Cryptography and Steganography
Mohammad Amin Amjadi
 
The International Journal of Engineering and Science (IJES)
The International Journal of Engineering and Science (IJES)The International Journal of Engineering and Science (IJES)
The International Journal of Engineering and Science (IJES)
theijes
 

Similar to Basic arithmetic, instruction execution and program (20)

03_NumberSystems.pdf
03_NumberSystems.pdf03_NumberSystems.pdf
03_NumberSystems.pdf
vijayapraba1
 
Chapter 3-Data Representation in Computers.ppt
Chapter 3-Data Representation in Computers.pptChapter 3-Data Representation in Computers.ppt
Chapter 3-Data Representation in Computers.ppt
KalGetachew2
 
2013 1
2013 1 2013 1
2013 1
SIVAN HASSAN
 
microprocessors
microprocessorsmicroprocessors
microprocessors
Hossam Zein
 
dld 01-introduction
dld 01-introductiondld 01-introduction
dld 01-introduction
United International University
 
Digital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdfDigital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdf
Kannan Kanagaraj
 
An introduction to the different number systems
An introduction to the different number systemsAn introduction to the different number systems
An introduction to the different number systems
hassanbokhari14
 
Number_Systems decimal, binary, octal, and hexadecimal
Number_Systems decimal, binary, octal, and hexadecimalNumber_Systems decimal, binary, octal, and hexadecimal
Number_Systems decimal, binary, octal, and hexadecimal
Meenakshi Munjal
 
Number Systems and its effectiveness .ppt
Number Systems and its effectiveness .pptNumber Systems and its effectiveness .ppt
Number Systems and its effectiveness .ppt
MuhammadAdeel321
 
Number_Systems_Number base conversions.ppt
Number_Systems_Number base conversions.pptNumber_Systems_Number base conversions.ppt
Number_Systems_Number base conversions.ppt
anushachalla14
 
Number_Systems for the Grade 10 students.ppt
Number_Systems  for the Grade 10 students.pptNumber_Systems  for the Grade 10 students.ppt
Number_Systems for the Grade 10 students.ppt
JoshCasas1
 
Number Systems.ppt
Number Systems.pptNumber Systems.ppt
Number Systems.ppt
GnanaDeepikaMeduri
 
Digital logic design part1
Digital logic design part1Digital logic design part1
Digital logic design part1
Vaagdevi College of Engineering
 
NumberSystems.pptx
NumberSystems.pptxNumberSystems.pptx
NumberSystems.pptx
vijayapraba1
 
NumberSystems.pptx
NumberSystems.pptxNumberSystems.pptx
NumberSystems.pptx
vijayapraba1
 
Number_Systems (2).ppt
Number_Systems (2).pptNumber_Systems (2).ppt
Number_Systems (2).ppt
nivedita murugan
 
Unit 1 PDF.pptx
Unit 1 PDF.pptxUnit 1 PDF.pptx
Unit 1 PDF.pptx
ChandraV13
 
15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3
RLJIT
 
Kaizen cso002 l1
Kaizen cso002 l1Kaizen cso002 l1
Kaizen cso002 l1
asslang
 
digital-systems-and-binary-numbers1.pptx
digital-systems-and-binary-numbers1.pptxdigital-systems-and-binary-numbers1.pptx
digital-systems-and-binary-numbers1.pptx
RameshK531901
 
03_NumberSystems.pdf
03_NumberSystems.pdf03_NumberSystems.pdf
03_NumberSystems.pdf
vijayapraba1
 
Chapter 3-Data Representation in Computers.ppt
Chapter 3-Data Representation in Computers.pptChapter 3-Data Representation in Computers.ppt
Chapter 3-Data Representation in Computers.ppt
KalGetachew2
 
Digital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdfDigital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdf
Kannan Kanagaraj
 
An introduction to the different number systems
An introduction to the different number systemsAn introduction to the different number systems
An introduction to the different number systems
hassanbokhari14
 
Number_Systems decimal, binary, octal, and hexadecimal
Number_Systems decimal, binary, octal, and hexadecimalNumber_Systems decimal, binary, octal, and hexadecimal
Number_Systems decimal, binary, octal, and hexadecimal
Meenakshi Munjal
 
Number Systems and its effectiveness .ppt
Number Systems and its effectiveness .pptNumber Systems and its effectiveness .ppt
Number Systems and its effectiveness .ppt
MuhammadAdeel321
 
Number_Systems_Number base conversions.ppt
Number_Systems_Number base conversions.pptNumber_Systems_Number base conversions.ppt
Number_Systems_Number base conversions.ppt
anushachalla14
 
Number_Systems for the Grade 10 students.ppt
Number_Systems  for the Grade 10 students.pptNumber_Systems  for the Grade 10 students.ppt
Number_Systems for the Grade 10 students.ppt
JoshCasas1
 
NumberSystems.pptx
NumberSystems.pptxNumberSystems.pptx
NumberSystems.pptx
vijayapraba1
 
NumberSystems.pptx
NumberSystems.pptxNumberSystems.pptx
NumberSystems.pptx
vijayapraba1
 
Unit 1 PDF.pptx
Unit 1 PDF.pptxUnit 1 PDF.pptx
Unit 1 PDF.pptx
ChandraV13
 
15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3
RLJIT
 
Kaizen cso002 l1
Kaizen cso002 l1Kaizen cso002 l1
Kaizen cso002 l1
asslang
 
digital-systems-and-binary-numbers1.pptx
digital-systems-and-binary-numbers1.pptxdigital-systems-and-binary-numbers1.pptx
digital-systems-and-binary-numbers1.pptx
RameshK531901
 
Ad

More from JyotiprakashMishra18 (6)

Program execution, straight line sequence and branching
Program execution, straight line sequence and branchingProgram execution, straight line sequence and branching
Program execution, straight line sequence and branching
JyotiprakashMishra18
 
Memory (Computer Organization)
Memory (Computer Organization)Memory (Computer Organization)
Memory (Computer Organization)
JyotiprakashMishra18
 
Instruction types
Instruction typesInstruction types
Instruction types
JyotiprakashMishra18
 
Central processing unit ii
Central processing unit iiCentral processing unit ii
Central processing unit ii
JyotiprakashMishra18
 
Central processing unit i
Central processing unit iCentral processing unit i
Central processing unit i
JyotiprakashMishra18
 
Addressing modes examples and subroutines
Addressing modes examples and subroutinesAddressing modes examples and subroutines
Addressing modes examples and subroutines
JyotiprakashMishra18
 
Ad

Recently uploaded (20)

seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink DisplayHow to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
CircuitDigest
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
Reflections on Morality, Philosophy, and History
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink DisplayHow to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
CircuitDigest
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 

Basic arithmetic, instruction execution and program

  • 3. Signed Integer • 3 major representations: Sign-magnitude One’s complement Two’s complement • Assumptions: 4-bit machine word 16 different values can be represented Roughly half are positive, half are negative
  • 4. Sign and Magnitude Representation 0000 0111 0011 1011 1111 1110 1101 1100 1010 1001 1000 0110 0101 0100 0010 0001 +0 +1 +2 +3 +4 +5 +6 +7 -0 -1 -2 -3 -4 -5 -6 -7 0 100 = + 4 1 100 = - 4 + - High order bit is sign: 0 = positive (or zero), 1 = negative Three low order bits is the magnitude: 0 (000) thru 7 (111) Number range for n bits = +/-2n-1 -1 Two representations for 0
  • 5. One’s Complement Representation • Subtraction implemented by addition & 1's complement • Still two representations of 0! This causes some problems • Some complexities in addition 0000 0111 0011 1011 1111 1110 1101 1100 1010 1001 1000 0110 0101 0100 0010 0001 +0 +1 +2 +3 +4 +5 +6 +7 -7 -6 -5 -4 -3 -2 -1 -0 0 100 = + 4 1 011 = - 4 + -
  • 6. Two’s Complement Representation • Only one representation for 0 • One more negative number than positive number 0000 0111 0011 1011 1111 1110 1101 1100 1010 1001 1000 0110 0101 0100 0010 0001 +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 -1 0 100 = + 4 1 100 = - 4 + - like 1's comp except shifted one position clockwise
  • 8. Addition and Subtraction – 2’s Complement 4 + 3 7 0100 0011 0111 -4 + (-3) -7 1100 1101 11001 4 - 3 1 0100 1101 10001 -4 + 3 -1 1100 0011 1111 If carry-in to the high order bit = carry-out then ignore carry if carry-in differs from carry-out then overflow Simpler addition scheme makes twos complement the most common choice for integer number systems within digital systems
  • 9. 2’s-Complement Add and Subtract Operations 1 1 0 1 0 1 1 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 1 1 0 1 0 0 1 1 1 0 0 1 0 1 0 1 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 1 0 1 0 1 4 + ( ) 2 - ( ) 3 + ( ) 2 - ( ) 8 - ( ) 5 + ( ) + + + + + + 1 1 1 0 0 1 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 0 6 - ( ) 2 - ( ) 4 + ( ) 3 - ( ) 4 + ( ) 7 + ( ) + + (b) (d) 1 0 1 1 1 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 5 - ( ) 2 + ( ) 3 + ( ) 5 + ( ) 2 + ( ) 4 + ( ) 2 - ( ) 7 - ( ) 3 - ( ) 7 - ( ) 6 + ( ) 3 + ( ) 1 + ( ) 7 - ( ) 5 - ( ) 7 - ( ) 2 + ( ) 3 - ( ) + + - - - - - - (a) (c) (e) (f) (g) (h) (i) (j) 2's-complement Add and Subtract operations.
  • 10. Overflow - Add two positive numbers to get a negative number or two negative numbers to get a positive number 5 + 3 = -8 -7 - 2 = +7 0000 0001 0010 0011 1000 0101 0110 0100 1001 1010 1011 1100 1101 0111 1110 1111 +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 -1 0000 0001 0010 0011 1000 0101 0110 0100 1001 1010 1011 1100 1101 0111 1110 1111 +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 -1
  • 11. Overflow Conditions 5 3 -8 0 1 1 1 0 1 0 1 0 0 1 1 1 0 0 0 -7 -2 7 1 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 5 2 7 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 -3 -5 -8 1 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 0 Overflow Overflow No overflow No overflow Overflow when carry-in to the high-order bit does not equal carry out
  • 12. Sign Extension • Task: – Given w-bit signed integer x – Convert it to w+k-bit integer with same value • Rule: – Make k copies of sign bit: – X ′ = xw–1 ,…, xw–1 , xw–1 , xw–2 ,…, x0 k copies of MSB • • • X X ′ • • • • • • • • • w w k
  • 13. Sign Extension Example short int x = 15213; int ix = (int) x; short int y = -15213; int iy = (int) y; Decimal Hex Binary x 15213 3B 6D 00111011 01101101 ix 15213 00 00 C4 92 00000000 00000000 00111011 01101101 y -15213 C4 93 11000100 10010011 iy -15213 FF FF C4 93 11111111 11111111 11000100 10010011
  • 15. Memory Location, Addresses, and Operation • Memory consists of many millions of storage cells, each of which can store 1 bit. • Data is usually accessed in n-bit groups. n is called word length. second word first word Memory words. nbits last word i th word • • • • • •
  • 16. Memory Location, Addresses, and Operation • 32-bit word length example (b) Four characters character character character character (a) A signed integer Sign bit: for positive numbers for negative numbers ASCII ASCII ASCII ASCII 32 bits 8 bits 8 bits 8 bits 8 bits b31 b30 b1 b0 b31 0 = b31 1 = • • •
  • 17. Memory Location, Addresses, and Operation • To retrieve information from memory, either for one word or one byte (8-bit), addresses for each location are needed. • A k-bit address memory has 2k memory locations, namely 0 – 2k-1, called memory space/ address space. • 24-bit memory: 224 = 16,777,216 = 16M (1M=220) • 32-bit memory: 232 = 4G (1G=230) • 1K(kilo)=210 • 1T(tera)=240
  • 18. Memory Location, Addresses, and Operation • It is impractical to assign distinct addresses to individual bit locations in the memory. • The most practical assignment is to have successive addresses refer to successive byte locations in the memory – byte-addressable memory. • Byte locations have addresses 0, 1, 2, … If word length is 32 bits, they successive words are located at addresses 0, 4, 8,…
  • 19. Big-Endian and Little-Endian Assignments 2 k 4 - 2 k 3 - 2 k 2 - 2 k 1 - 2 k 4 - 2 k 4 - 0 1 2 3 4 5 6 7 0 0 4 2 k 1 - 2 k 2 - 2 k 3 - 2 k 4 - 3 2 1 0 7 6 5 4 Byte address Byte address (a) Big-endian assignment (b) Little-endian assignment 4 Word address • • • • • • Figure 2.7. Byte and word addressing. Big-Endian: lower byte addresses are used for the most significant bytes of the word Little-Endian: opposite ordering. lower byte addresses are used for the less significant bytes of the word
  • 20. Memory Location, Addresses, and Operation • Address ordering of bytes • Word alignment – Words are said to be aligned in memory if they begin at a byte addr. that is a multiple of the num of bytes in a word. • 16-bit word: word addresses: 0, 2, 4,…. • 32-bit word: word addresses: 0, 4, 8,…. • 64-bit word: word addresses: 0, 8,16,…. • Access numbers, characters, and character strings
  • 21. Memory Operation • Load (or Read or Fetch)  Copy the content. The memory content doesn’t change.  Address – Load  Registers can be used • Store (or Write)  Overwrite the content in memory  Address and Data – Store  Registers can be used
  • 23. “Must-Perform” Operations • Data transfers between the memory and the processor registers • Arithmetic and logic operations on data • Program sequencing and control • I/O transfers
  • 24. Register Transfer Notation • Identify a location by a symbolic name standing for its hardware binary address (LOC, R0,…) • Contents of a location are denoted by placing square brackets around the name of the location (R1←[LOC], R3 ←[R1]+[R2]) • Register Transfer Notation (RTN)
  • 25. Assembly Language Notation • Represent machine instructions and programs. • Move LOC, R1 = R1←[LOC] • Add R1, R2, R3 = R3 ←[R1]+[R2]
  • 26. CPU Organization • Single Accumulator – Result usually goes to the Accumulator – Accumulator has to be saved to memory quite often • General Register – Registers hold operands thus reduce memory traffic – Register bookkeeping • Stack – Operands and result are always in the stack
  • 27. Instruction Formats • Three-Address Instructions – ADD R1, R2, R3 R3 ← [R1] + [R2] • Two-Address Instructions – ADD R1, R2 R2 ← [R1] + [R2] • One-Address Instructions – ADD M AC ← AC + [M] • Zero-Address Instructions – ADD TOS ← [TOS] + [(TOS – 1)] • RISC Instructions – Lots of registers. Memory is restricted to Load & Store Opcode Operand(s) or Address(es)
  • 28. Instruction Formats Example: Evaluate X = (A+B) ∗ (C+D) • Three-Address 1. ADD A, B, R1 ; R1 ← [A] + [B] 2. ADD C, D, R2 ; R2 ← [C] + [D] 3. MUL R1, R2, X ; X ← [R1] ∗ [R2]
  • 29. Instruction Formats Example: Evaluate X = (A+B) ∗ (C+D) • Two-Address 1. MOV A, R1 ; R1 ← [A] 2. ADD B, R1 ; R1 ← [R1] + [B] 3. MOV C, R2 ; R2 ← [C] 4. ADD D, R2 ; R2 ← [R2] + [D] 5. MUL R2, R1 ; R1 ← [R1] ∗ [R2] 6. MOV R1, X ; X ← [R1]
  • 30. Instruction Formats Example: Evaluate X = (A+B) ∗ (C+D) • One-Address 1. LOAD A ; AC ← [A] 2. ADD B ; AC ← [AC] + [B] 3. STORE T ; T ← [AC] 4. LOAD C ; AC ← [C] 5. ADD D ; AC ← [AC] + [D] 6. MUL T ; AC ← [AC] ∗ [T] 7. STORE X ; X ← [AC]
  • 31. Instruction Formats Example: Evaluate X = (A+B) ∗ (C+D) • Zero-Address 1. PUSH A ; TOS ← [A] 2. PUSH B ; TOS ← [B] 3. ADD ; TOS ← [A] + [B] 4. PUSH C ; TOS ← [C] 5. PUSH D ; TOS ← [D] 6. ADD ; TOS ← [C] + [D] 7. MUL ; TOS ← (C+D)∗(A+B) 8. POP X ; X ← [TOS]
  • 32. Instruction Formats Example: Evaluate X = (A+B) ∗ (C+D) • RISC 1. LOAD A, R1 ; R1 ← [A] 2. LOAD B, R2 ; R2 ← [B] 3. LOAD C, R3 ; R3 ← [C] 4. LOAD D, R4 ; R4 ← [D] 5. ADD R1, R2, R1 ; R1 ← [R1] + [R2] 6. ADD R3, R4, R3 ; R3 ← [R3] + [R4] 7. MUL R1, R3, R1 ; R1 ← [R1] ∗ [R3] 8. STORE R1, X ; X ← [R1]
  • 33. Using Registers • Registers are faster • Shorter instructions – The number of registers is smaller (e.g. 32 registers need 5 bits) • Potential speedup • Minimize the frequency with which data is moved back and forth between the memory and processor registers.
  翻译: