Unit1 Basic Structure of Computer
Unit1 Basic Structure of Computer
Architecture
Course Instructor
Dr. Umadevi V
Department of CSE, BMSCE
1
* CSE, BMSCE
Unit-1
* CSE, BMSCE 2
A Computer
Computer is a “machine”
□As long as power is supplied, processor keeps executing
instructions
■ Stored program model
■ Sequential order of execution
□Memory: Program and data storage
* CSE, BMSCE 3
Functional Units
A computer consists of 5 functionally independent main parts: 1) Input 2) Memory 3)
ALU (Arithmetic and Logic Unit) 4) Output and 5) Control unit
2. Output Unit: Computer after computation returns the computed results, error messages,
etc. via output unit. The standard output device is a video monitor, LCD/TFT monitor. Other
output devices are printers, plotters etc.
* CSE, BMSCE 5
Functional Units
3. Memory Unit: Memory unit stores the program instructions (Code), data and
results of computations etc. Memory unit is classified as:
□• Primary /Main Memory
□• Secondary /Auxiliary Memory
Primary memory is a semiconductor memory that provides access at high speed. Run time program instructions and operands
are stored in the main memory. Main memory is classified again as ROM and RAM. ROM holds system programs and firmware
routines such as BIOS, POST, I/O Drivers that are essential to manage the hardware of a computer. RAM is termed as
Read/Write memory or user memory that holds run time program instruction and data. While primary storage is essential, it is
volatile in nature and expensive. Additional requirement of memory could be supplied as auxiliary memory at cheaper cost.
Secondary memories are non volatile in nature.
* CSE, BMSCE 6
Functional Units
4. Arithmetic and logic unit: ALU consist of necessary logic circuits like adder, comparator etc., to perform
operations of addition, multiplication, comparison of two numbers etc.
5. Control Unit: Control unit co-ordinates activities of all units by issuing control signals. Control signals issued
by control unit govern the data transfers and then appropriate operations take place. Control unit interprets or
decides the operation/action to be performed.
The control Unit and the Arithmetic and Logic unit of a computer system are jointly known as the Central
Processing Unit (CPU).
* CSE, BMSCE 7
Next we will learn
* CSE, BMSCE 8
Background information to understand “Basic Operational Concepts”
* CSE, BMSCE 9
Background information to understand “Basic Operational Concepts”
Program consists of
Basic Step1
N Instructions Instruction
Basic
. Step2
Instruction 1
.
Instruction 2 . Operation Operand
Basic Step m Or
.
. Opcode
.
. Register Memory
.
Instruction N.
* CSE, BMSCE 10
Background information to understand “Basic Operational Concepts”: Instruction types
* CSE, BMSCE 11
BASIC OPERATIONAL CONCEPTS
- The Program Counter (PC) register holds the
memory address of the current instruction
- The Instruction Register (IR) holds the current
instruction
- General-purpose registers hold data and
addresses (R0, R1, ….)
- Control circuits and the Arithmetic and Logic
Unit (ALU) fetch and execute instructions
* CSE, BMSCE 12
BASIC OPERATIONAL CONCEPTS:
Fetching and executing instructions
* CSE, BMSCE 13
BASIC OPERATIONAL CONCEPTS: Fetching and executing instructions : Illustration with
example
Memory
Basic Steps to execute the instruction Load R2, A Address Instructions / Data
1. Send address in PC to memory; issue Read
2. Load instruction from memory into IR 100 Load R2, A
3. Increment PC to point to next instruction 101 Load R3, B
4. Send address A to memory; issue Read
5. Load word from memory into register R2 102 Add R4, R2, R3
….. -----
PC 100 R2
IR
Processor
* CSE, BMSCE 14
BASIC OPERATIONAL CONCEPTS: Fetching and executing instructions : Illustration with
example
Memory
Basic Steps to execute the instruction Load R2, A: Address
1. Send address in PC to memory; issue Read
2. Load instruction from memory into IR 100 Load R2, A
3. Increment PC to point to next instruction
4. Send address A to memory; issue Read 101 Load R3, B
5. Load word from memory into register R2 102 Add R4, R2, R3
….. -----
Memory Address 200 76
Label A
PC 100 R2
IR
Processor
* CSE, BMSCE 15
BASIC OPERATIONAL CONCEPTS: Fetching and executing instructions : Illustration with
example
Memory
Basic Steps to execute the instruction Load R2, A: Address
1. Send address in PC to memory; issue Read
2. Load instruction from memory into IR 100 Load R2, A
3. Increment PC to point to next instruction
4. Send address A to memory; issue Read 101 Load R3, B
5. Load word from memory into register R2 102 Add R4, R2, R3
….. -----
Memory Address 200 76
Label A
PC 100 R2
IR Load R2, A
* CSE, BMSCE 16
BASIC OPERATIONAL CONCEPTS: Fetching and executing instructions : Illustration with
example
Memory
Basic Steps to execute the instruction Load R2, A: Address
1. Send address in PC to memory; issue Read
2. Load instruction from memory into IR 100 Load R2, A
3. Increment PC to point to next instruction
4. Send address A to memory; issue Read 101 Load R3, B
5. Load word from memory into register R2 102 Add R4, R2, R3
….. -----
Memory Address 200 76
Label A
PC 101 R2
IR Load R2, A
* CSE, BMSCE 17
BASIC OPERATIONAL CONCEPTS: Fetching and executing instructions : Illustration with
example
Memory
Basic Steps to execute the instruction Load R2, A: Address
1. Send address in PC to memory; issue Read
2. Load instruction from memory into IR 100 Load R2, A
3. Increment PC to point to next instruction
4. Send address A to memory; issue Read 101 Load R3, B
5. Load word from memory into register R2 102 Add R4, R2, R3
….. -----
Memory Address 200 76
Label A
PC 101 R2
IR Load R2, A
* CSE, BMSCE 18
BASIC OPERATIONAL CONCEPTS: Fetching and executing instructions : Illustration with
example
Memory
Basic Steps to execute the instruction Load R2, A: Address
1. Send address in PC to memory; issue Read
2. Load instruction from memory into IR 100 Load R2, A
3. Increment PC to point to next instruction
4. Send address A to memory; issue Read 101 Load R3, B
5. Load word from memory into register R2 102 Add R4, R2, R3
….. -----
Memory Address 200 76
Label A
PC 101 R2 76
IR Load R2, A
* CSE, BMSCE 19
BASIC OPERATIONAL CONCEPTS:
Fetching and executing instructions
Memory
Basic Steps to execute the instruction Load R2, A: Address
1. Send address in PC to memory; issue Read
2. Load instruction from memory into IR 100 Load R2, A
3. Increment PC to point to next instruction
4. Send address A to memory; issue Read 101 Load R3, B
5. Load word from memory into register R2 102 Add R4, R2, R3
….. -----
Memory Address 200 76
Label A
100 R2 76
PC
IR Load R2, A
Processor
* CSE, BMSCE 20
Test Your Knowledge
W.r.t Computer Processor,
What is the role of PC ?
What is the role of IR ?
* CSE, BMSCE 21
Test Your Knowledge
What is the role of PC ?
□The Central Processing Unit (CPU) contains a register called the Program Counter (PC), which
holds the address of instruction to be executed next.. to begin the execution of the program the
address of its First instruction must be placed into the PC.
What is the role of IR ?
□The instruction register (IR) is used to hold the instruction that is currently being executed. The
contents of IR are available to the control unit, which generate the timing signals that control
the various processing elements involved in executing the instruction.
* CSE, BMSCE 22
BASIC OPERATIONAL CONCEPTS:
Fetching and executing instructions
* CSE, BMSCE 23
BASIC OPERATIONAL CONCEPTS:
Fetching and executing instructions
* CSE, BMSCE 24
Question
(a) Give a short sequence of machine instructions for the task “Add the contents of memory-location A to those of location B,
and place the answer in location C”. Instructions:
Load Ri , LOC
and
Store LOC , Ri
are the only instructions available to transfer data between memory and the general purpose registers. Add instructions of type
ADD LOCA, R0 and Add R1, R0 are available. Do not change contents of either location A or B.
(b) Suppose that Move and Add instructions are available with the formats:
Move Location1, Location2
and
Add Location1, Location2
These instructions move or add a copy of the operand at the second location to the first location, overwriting the original
operand at the first location. Either or both of the operands can be in the memory or the general-purpose registers.
Is it possible to use fewer instructions of these types to accomplish the task in part (a)? If yes, give the sequence.
* CSE, BMSCE 25
Answer
(a) Give a short sequence of machine instructions for the task “Add the contents of memory-location A to those of location B,
and place the answer in location C”. Instructions:
Load Ri , LOC
and
Store LOC , Ri
are the only instructions available to transfer data between memory and the general purpose registers. Add instructions of type
ADD LOCA, R0 and Add R1, R0 are available. Do not change contents of either location A or B.
* CSE, BMSCE 26
Answer
(a) Give a short sequence of machine instructions for the task “Add the contents of memory-location A to those of location B,
and place the answer in location C”. Instructions:
Load Ri , LOC
and
Store LOC , Ri
are the only instructions available to transfer data between memory and the general purpose registers. Add instructions of type
ADD LOCA, R0 and Add R1, R0 are available. Do not change contents of either location A or B.
Solution:
(a)
Load R0 , A
Load R1 , B
Add R1, R0
Store C , R1
* CSE, BMSCE 27
Answer
(b) Suppose that Move and Add instructions are available with the formats:
Move Location1, Location2
and
Add Location1, Location2
These instructions move or add a copy of the operand at the second location to the first location, overwriting the
original operand at the first location. Either or both of the operands can be in the memory or the general-purpose
registers.
Is it possible to use fewer instructions of these types to accomplish the task in part (a)? If yes, give the
sequence.
* CSE, BMSCE 28
Answer
(b) Suppose that Move and Add instructions are available with the formats:
Move Location1, Location2
and
Add Location1, Location2
These instructions move or add a copy of the operand at the second location to the first location, overwriting the
original operand at the first location. Either or both of the operands can be in the memory or the general-purpose
registers.
Is it possible to use fewer instructions of these types to accomplish the task in part (a)? If yes, give the
sequence.
Solution:
(b) Yes;
Move C, B
Add C, A
* CSE, BMSCE 29
Test Your Knowledge
* CSE, BMSCE 30
Test Your Knowledge
* CSE, BMSCE 31
Test Your Knowledge
* CSE, BMSCE 32
Test Your Knowledge
* CSE, BMSCE 33
Next we will learn
* CSE, BMSCE 34
Three major representations of Signed Integer
* CSE, BMSCE 35
Decimal Number Representation or Base 10
* CSE, BMSCE 36
Binary Number Representation or Base 2
* CSE, BMSCE 37
Binary Number Representation or Base 2
Power of 2 Calculation Value
20 1 1
21 2 2
* CSE, BMSCE 38
Binary Number Representation or Base 2
Power of 2 Calculation Value
20 1 1
21 2 2
Decimal Binary
0 00
1 01
2 10
3 11
* CSE, BMSCE 39
Binary Number Representation or Base 2
Power of 2 Calculation Value
20 1 1
21 2 2
Decimal Binary
1 01
2 10
3 11
* CSE, BMSCE 40
Binary Number Representation or Base 2
Power of 2 Calculation Value
20 1 1
21 2 2
Decimal Binary
* CSE, BMSCE 41
Example: 3-bit binary numbers
Decimal Binary Power of 2 Calculation Value
0 000
20 1
1 001
2 010 21 2 2
3 011
4 100 22 2*2 4
5 101
6 110
7 111
* CSE, BMSCE 42
Question: List out all 4-bit binary numbers
* CSE, BMSCE 44
Representation of a Binary Number
□ Converting from decimal to binary (base 10 to base 2) will also produce a weighted binary
number with the right-hand most bit being the Least Significant Bit or LSB, and the
left-hand most bit being the Most Significant Bitor MSB, and we can represent this as:
□ Convert binary to decimal by finding the decimal equivalent of the binary array of
digits 1011001012 and expanding the binary digits into a series with a base of 2giving an
equivalent of 35710 in decimal or denary.
* CSE, BMSCE 45
Question: Convert the following Binary number to Decimal
* CSE, BMSCE 46
Answer
* CSE, BMSCE 47
Decimal to Binary Conversion
* CSE, BMSCE 48
Question: Represent the following Decimal number in 7-bit binary numbers
7-bit Binary
Decimal
Number
5
14
26
53
* CSE, BMSCE 49
Answer
7-bit Binary
Decimal
Number
5 0000101
14 0001110
26 0011010
53 0110101
* CSE, BMSCE 50
Question
* CSE, BMSCE 51
Answer
* CSE, BMSCE 52
Signed Binary Number Representation
□ We can use a single bit to identify the sign of a signed binary number as being positive or negative in
value. So to represent a positive binary number (+n) and a negative (-n) binary number, we can use
them with the addition of a sign.
□ For signed binary numbers the most significant bit (MSB) is used as the sign bit. If the sign bit is “0”,
this means the number is positive in value. If the sign bit is “1”, then the number is negative in value.
The remaining bits in the number are used to represent the magnitude of the binary number in the
usual unsigned binary number format way.
□ Then we can see that the Sign-and-Magnitude (SM) notation stores positive and negative values by
dividing the “n” total bits into two parts: 1 bit for the sign and n–1 bits for the value which is a pure
binary number. For example, the decimal number 53 can be expressed as an 8-bit signed binary
number as follows:
* CSE, BMSCE 53
Signed Binary Number Representation
□ We can use a single bit to identify the sign of a signed binary number as being positive or negative in value. So to represent a
positive binary number (+n) and a negative (-n) binary number, we can use them with the addition of a sign.
□ For signed binary numbers the most significant bit (MSB) is used as the sign bit. If the sign bit is “0”, this means the number is
positive in value. If the sign bit is “1”, then the number is negative in value. The remaining bits in the number are used to represent
the magnitude of the binary number in the usual unsigned binary number format way.
□ Then we can see that the Sign-and-Magnitude (SM) notation stores positive and negative values by dividing the “n” total bits into
two parts: 1 bit for the sign and n–1 bits for the value which is a pure binary number. For example, the decimal number 53 can be
expressed as an 8-bit signed binary number as follows:
* CSE, BMSCE 54
Example: Signed numbers
* CSE, BMSCE 55
1’s (One’s) complement number representation
□ If all bits in a byte are inverted by changing each 1 to 0 and each 0 to 1, we have
formed the one’s complement of the number.
* CSE, BMSCE 56
Binary Sign-Magnitude and One’s Complement representation
* CSE, BMSCE 57
Two’s Complement of Number representation
The two’s complement is a method for representing positive and negative integer values in binary. The useful
part of two’s complement is that it automatically includes the sign bit.
Rule: To form the two’s complement, add 1 to the one’s complement.
* CSE, BMSCE 58
Two’s Complement
The two’s complement is a method for representing positive and negative integer values in binary. The useful
part of two’s complement is that it automatically includes the sign bit.
Rule: To form the two’s complement, add 1 to the one’s complement.
* CSE, BMSCE 59
Binary Sign-Magnitude, One’s Complement representation and Two’s Complement
* CSE, BMSCE 60
Conversion of Negative Numbers to Two’s Complement
* CSE, BMSCE 61
Conversion of Negative Numbers to Two’s Complement
* CSE, BMSCE 62
Conversion of Negative Numbers to Two’s Complement
* CSE, BMSCE 63
Question
□ Using 7 bits to represent each number, write the representations of 23 and -23 in
signed-magnitude , 1’s complement and 2's complement system
* CSE, BMSCE 64
Answer
□ Using 7 bits to represent each number, write the representations of 23 and -23 in
signed magnitude and 2's complement integers
* CSE, BMSCE 65
Question
Represent the decimal values 5, -2, 14, -10, 26, -19, 51 and -43 as signed 7-bit
numbers in the following formats
a.Sign-Magnitude
b.1’s complement
c.2’s complement
* CSE, BMSCE 66
Answer
Represent the decimal values 5, -2, 14, -10, 26, -19, 51 and -43 as signed 7-bit
numbers in the following formats
a.Sign-Magnitude
b.1’s complement
c.2’s complement
* CSE, BMSCE 67
Conversion of Negative Numbers to Two’s Complement
□ Convert 47 to an 8-bit, twos complement binary number. This is positive, so all that is needed is to convert
to binary and pad to eight bits. So 4710 = 1011112. So 47 as an 8-bit two's complement number is just
00101111.
□ Convert -109 to an 8-bit, twos complement number. So 10910 = 11011012.
□ Convert 81 to an 8-bit, twos complement number. Since this is positive, it's just a matter of converting to binary and
padding to 8 bits. So 8110 = 10100012, giving 01010001
* CSE, BMSCE 68
Under Signed Number Representation
* CSE, BMSCE 69
4-bit Signed Binary Number Representation
Decimal Signed Magnitude Signed One’s Complement Signed Two’s Complement
Adding 0101 +5
+5-5 1101 -5
Total 10010 INCORRECT, because the result should be zero
(1 i.e., 00000
Carryout)
Adding 0101 +5
+5-5 1010 -5
One’s Complement of -5
+7 0111
Two’s Complement
+6 0110 (4-bit Representation)
+5 0101
Adding 0101 +5
+4 0100 +5-5 1011 -5
+3 0011
Total 10000 CORRECT(Zero)
+2 0010
(1 Ignore the Carryout
+1 0001 Carryout)
+0 0000
-0 – Two’s Complement
(4-bit Representation)
-1 1111
-2 1110
Adding 0110 +6
+6-2 1110 -2
-3 1101
-4 1100 Total 10100 CORRECT(+4)
-5 1011
(1 Ignore the Carryout
Carryout)
-6 1010
-7 1001
* CSE, BMSCE 72
Addition and Subtraction of Signed Numbers using two’s Complement
The 2’s complement is the most efficient method for performing addition and subtraction
operations
The rules governing addition and subtraction of n-bit signed numbers using 2's complement
representation system may be stated as follows:
□To add two numbers, add their n-bit representation , ignoring the carry-out bit from the Most
Significant Bit (MSB) position. The sum will be algebraically correct value in 2’s complement
representation if the actual result is in the range -2n-1 through +2n-1 -1
□To subtract two numbers X and Y, that is, to perform X-Y, form the 2’s complement of Y, then
add it to X using the add rule. Again, the result will be algebraically correct value in 2’s
complement representation if the actual result is in the range -2n-1 through +2n-1 -1
* CSE, BMSCE 73
Addition and Subtraction of Signed Numbers
* CSE, BMSCE 74
Subtraction by 2’s Complement:
The operation is carried out by means of the following steps:
(i) At first, 2’s complement of the subtrahend is found.
(ii) Then it is added to the minuend.
(iii) Throw away extra carries
(iv) If leading number (MSB) is 0, answer is positive. If leading number is 1,
answer is negative.
Note:
Subtrahend: what is being subtracted
Minuhend: what it is being subtracted from
* CSE, BMSCE 75
Addition and Subtraction of Signed Numbers
* CSE, BMSCE 76
Addition and Subtraction of Signed Numbers
Carry Out
Ignore
* CSE, BMSCE 77
Addition and Subtraction of Signed Numbers
Ignore
11100 -4
* CSE, BMSCE 78
Test Your knowledge
* CSE, BMSCE 79
Answer
* CSE, BMSCE 80
Example of two’s Complement Arithmetic
* CSE, BMSCE 81
Example of two’s Complement Arithmetic
* CSE, BMSCE 82
Arithmetic Overflow
□ In 2's complement number representation system, n-bits can represent values in
the range (-2n-1) to (+2n-1 – 1).
□ When the result of an arithmetic operation is outside the representable range, an
arithmetic overflow has occurred.
* CSE, BMSCE 83
Arithmetic Overflow
Care must be taken when adding numbers of like sign since overflow can occur.
□If you add two numbers of like sign and the result is of the opposite sign, then the result cannot be used. This
"overflow" condition occurs because, in order to represent the result, we would need more bits than are available
in the bit field. (Remember, we can't just "enlarge" the size of the result- it must remain the same size as the
operands.) Here are examples for adding two negative numbers, and adding two positive numbers, each of which
results in overflow.
* CSE, BMSCE 84
Detecting overflow when adding two 2’s complement numbers
If 2 Two's Complement numbers are added, and they both have the same sign (both positive or both
negative), then overflow occurs if and only if the result has the opposite sign. Overflow never occurs when
adding operands with different signs. i.e. Adding two positive numbers must give a positive result Adding
two negative numbers must give a negative result
Overflow occurs if
(+A) + (+B) = −C
(−A) + (−B) = +C
* CSE, BMSCE 85
Test Your Knowledge
Convert the following pairs of decimal numbers to 5-bit 2’s-complement numbers, then
add them. State whether or not overflow occurs in each case
a. 7 and 13 b. -10 and -13
* CSE, BMSCE 86
Answer
Convert the following pairs of decimal numbers to 5-bit 2’s-complement numbers, then
add them. State whether or not overflow occurs in each case
a. 7 and 13 b. -10 and -13
* CSE, BMSCE 87
Question
Convert the following pairs of decimal numbers to 5-bit 2’s-complement numbers, then
add them. State whether or not overflow occurs in each case
a.5 and 10
b.7 and 13
c.-14 and 11
d.-5 and 7
e.-3 and -8
f.-10 and -13
* CSE, BMSCE 88
Detecting overflow when subtracting two 2’s complement numbers
If two 2's Complement numbers are subtracted, and their signs are different, then overflow
occurs if and only if the result has the same sign as the subtrahend.
Overflow occurs if
(+A) − (−B) = −C
(−A) − (+B) = +C
Example: Using 4-bit Two's Complement numbers (−8 ≤ x ≤ +7)
Subtract −6 from +7
(+7) 0111 0111
−(−6) 1010 -> Negate -> +0110
---------- -----
13 1101 (−3) : Overflow
* CSE, BMSCE 89
Question
Repeat for subtraction operation, where the second number of each pair to be
subtracted from first number. State whether or not overflow occurs in each case
a.5 and 10
b.7 and 13
c.-14 and 11
d.-5 and 7
e.-3 and -8
f.-10 and -13
* CSE, BMSCE 90
How to avoid Overflow
□ You can enlarge the size of the bit field, but only before you perform any operations, and it must be done a
certain way. If you find that the size of the bit field is too small and overflow is occurring, you can promote the values to
larger bit fields. This is done by a technique called sign extension. To enlarge the bit field, add bits on the left, duplicating
the most significant bit. This preserves the sign of the number and does not alter its value. Remember, you must promote
all values to the same size. The table below illustrates sign-extension of a 4-bit number to 5, 6, and 8-bit fields. In each
case, the most significant bit of the original 4-bit field (in blue) is simply repeated as many times as necessary on the
left(in red).
* CSE, BMSCE 91
Unit1:Memory Locations and Addresses
* CSE, BMSCE 92
Memory Locations and Addresses
* CSE, BMSCE 93
Memory Locations and Addresses
Address n bits
0 first word
1 second word
•
•
•
i th word
•
•
•
* CSE, BMSCE 94
Memory Locations and Addresses
2 22=4 Locations
3 23=8 Locations
4 24=16 Locations
Memory
Address Word Length
K=2bits n =8bits = 1 Byte
0 00 0000 0110 1st Byte or word
1 01 0000 0111 2nd Byte or word
2 10 0000 1000 3rd Byte or word
3 11 0000 1010 4th Byte or word
* CSE, BMSCE
Memory Locations and Addresses
Address Length Addressable Locations
k
Memory
K-bits 2
Address Word Length
2 22=4 Locations K=3bits n =8bits = 1 Byte
3 23=8 Locations 0 000 0000 0110 1st Byte or word
* CSE, BMSCE
Question
Address Length Addressable Locations
Memory
K-bits 2k Address Word Length
K=3bits n =8bits = 1 Byte
2 22=4 Locations 0 000 0000 0110 1st Byte or word
3 23=8 Locations 1 001 0000 0111 2nd Byte or word
4 24=16 Locations 2 010 0000 1000 3rd Byte or word
3 011 0000 1010 4th Byte or word
4 100 0000 1011 5th Byte or word
Question:
Consider in one memory location, 5 101 0000 1100 6th Byte or word
One byte of information can be stored 6 110 0000 1101 7th Byte or word
i.e., n=8bits. To store 1024 bytes of information, 7 111 0000 1110 8th Byte or word
How many address bits should be used
i.e., what should be the k value ?
* CSE, BMSCE
Question
Address Length Addressable Locations Address Word Length
K-bits 2k K=3bits n =8bits = 1 Byte
0 000 0000 0110 1st Byte or word
2 22=4 Locations
1 001 0000 0111 2nd Byte or word
3 23=8 Locations
2 010 0000 1000 3rd Byte or word
4 24=16 Locations
3 011 0000 1010 4th Byte or word
4 100 0000 1011 5th Byte or word
* CSE, BMSCE
Byte Addressability
* CSE, BMSCE 99
Two ways of Byte address assignment across words
□ Big-endian and little-endian are terms that describe the order in which
a sequence of bytes are stored in computer memory.
1. Big-endian addressing assigns Lower byte addresses to Most Significant
(leftmost) bytes of word
2. Little-endian addressing assigns Lower byte addresses to Least Significant
(rightmost) bytes of word
□ Example: Consider storing the number 2064 i.e., Two thousand Sixty four. We will assume one digit
occupies 4bits.
2064 2 0 6 4
0010 0000 0110 0100
MSB LSB
Most Significant Byte Least Significant Byte
□ Example: Consider storing the number 2064 i.e., Two thousand Sixty four. We will assume one digit
occupies 4bits.
2064 2 0 6 4
0010 0000 0110 0100
MSB LSB
Most Significant Byte Least Significant Byte
Big-endian addressing assigns Lower byte addresses Little-endian addressing assigns Lower byte addresses
to Most Significant (leftmost) bytes of word to Least Significant (rightmost) bytes of word
W ord
address Byte address Byte address
0 1 2 3 0 3 2 1 0
0
4 4 5 6 7 4 7 6 5 4
• •
• •
• •
k k k k k k k k k k
2 - 4 2 - 4 2 - 3 2 - 2 2 - 1 2 - 4 2 - 1 2 - 2 2 - 3 2 - 4
Note: To specify
Hexadecimal numbers
Prefix 0x will be used
i.e.,
0x123
or
123h
Hex
c 0x63
o 0x6F
m 0x6D
p 0x70
u 0x75
t 0x74
e 0x65
r 0x72
Word Length
Hex Address n=8bits=1 Byte
c 63 1000 0110 0011 c 63 MSB
o 6F 1001 0110 1111 o 6F
m 6D 1002 0110 1101 m 6D
p 70
1003 0111 0000 p 70
u 75
1004 0111 0101 u 75 Big-Endian Approach
t 74
1005 0111 0100 t 74
e 65
1006 0110 0101 e 65
r 72
1007 0111 0010 r 72 LSB
* CSE, BMSCE 106
Question
□ Consider a computer has a byte-addressable memory organized in 32-bit words according to the Little-endian scheme. A
program reads ASCII characters entered at a keyboard and stores them in successive byte locations, starting at location
1000. Show the contents of the two memory words at locations 1000 and 1004 after the word “computer” has been
entered. Values corresponding to the characters are as shown below:
Hex
c 63
o 6F
m 6D
p 70
u 75
t 74
e 65
r 72
Word Length
Hex Address n=8bits=1 Byte
c 63 1000 0110 0011 r 72 LSB
o 6F 1001 0110 1111 e 65 1000: 72 65 74 75
m 6D 1002 0110 1101 t 74 r e t u
p 70 1004: 70 6D 6F 63
1003 0111 0000 u 75
u 75
p m o c
1004 0111 0101 p 70 Little-Endian
t 74 Approach
1005 0111 0100 m 6D
e 65
1006 0110 0101 o 6F
r 72
1007 0111 0010 c 63 MSB
* CSE, BMSCE 108
Memory Word Alignment
□ Words are said to be Aligned in memory if they begin at a
byte-address that is a multiple of number of bytes in a word.
□ For example,
■ If the word length is 16 (2 Bytes), aligned words begin at byte addresses 0, 2,
4,....
■ If the word length is 32 (4 Bytes), aligned words begin at byte addresses 0, 4,
8,....
□ Words are said to have Unaligned Addresses, if they begin at an
arbitrary byte-address
Example
Load R2, LOC ; R2 ← [LOC]
R1 2 R1 18
R2 10 R2 10
0x2000 2 0x2000 2
R1 0x2000 R1 0x2000
R2 8 R2 10
0x2005 2 0x2005 2
R1 0x2000 R1 0x2000
R2 8 R2 2
0x2005 6 0x2005 6
R1 0x2000 R1 0x2000
R2 8 R2 6
R3 5 R3 5
* CSE, BMSCE 138
Question
The addressing mode used in the instruction
Move R1, 8(R2) is
a.Register and Index
b.Register and Direct
c.Register and Immediate
ii. (R4,R5)
EA=[R4]+[R5]
5000=2000+3000
iii. 28(R4,R5)
EA= [28]+[R4]+[R5]
5028= 28+2000+3000
N 2 1000
Sum1 1036
Sum2 1040
Sum3 1044
* CSE, BMSCE 149
Move R2, #List 3000
Clear R3 3004
Program to find sum of Test1, Test2 and Test3 marks of all students
Memory Clear R4 3008
4 Bytes Address Clear R5 3012
N 2 1000
Load R6, N 3016
List BM01 1004 Student ID
Loop: Load R7, 4(R2) 3020
1 1008 Test1 Marks
Add R3, R3, R7 3024
2 1012 Test2 Marks
Load R7, 8(R2) 3028
3 1016 Test3 Marks
Add R4, R4, R7 3032
BM02 1020 Student ID
Load R7, 12(R2) 3036
10 1024 Test1 Marks
Add R5, R5, R7 3040
20 1028 Test2 Marks
Add R2, R2, #16 3044
30 1032 Test3 Marks
Subtract R6, R6, #1 3048
Sum1 1036
Branch_if_[R6] >0 Loop 3052
Sum2 1040
Store R3, Sum1 3056
Sum3 1044
Store R4, Sum2 3060
Clear R3 3004
After executing the program
Memory Clear R4 3008
4 Bytes Address Clear R5 3012
N 2 1000
Load R6, N 3016
List BM01 1004 Student ID
Loop: Load R7, 4(R2) 3020
1 1008 Test1 Marks
Add R3, R3, R7 3024
2 1012 Test2 Marks
Load R7, 8(R2) 3028
3 1016 Test3 Marks
Add R4, R4, R7 3032
BM02 1020 Student ID
Load R7, 12(R2) 3036
10 1024 Test1 Marks
Add R5, R5, R7 3040
20 1028 Test2 Marks
Add R2, R2, #16 3044
30 1032 Test3 Marks
Subtract R6, R6, #1 3048
Sum1 11 1036
Branch_if_[R6] >0 Loop 3052
Sum2 22 1040
Store R3, Sum1 3056
Sum3 33 1044
Store R4, Sum2 3060
Move R10, J
Clear R0
Load (R3), R0
20 212
30 216
* CSE, BMSCE 160
Question
Write a RISC-style program that finds the number of negative integers in a list of n 32-bit
integers and stores the count in location NEGNUM. The value n is stored in memory location N,
and the first integer in the list is stored in location NUMBERS. Include the necessary assembler
directives and a sample list that contains six numbers, some of which are negative.
END of Unit-1