Computer Organization & Arch.
Chapter -2-
By
Abdullah Fadil Korjy
حملة جمهورية الصباحي المتحدة
Instruction Set Architecture and Design
main memory: a sequence of array of millions of adjacent cells each capable of
storing n bits , having value 0 or 1
program: a set consists of a number of instructions that have to be accessed in a
certain order and to be executed or Set of instructions to be executed for
certain task
ى, MCQ = T\F = فراغات
حت التعاريف
Q\ What is the hiearachy that’s starts with in Typical Memory ?!
A typical memory hierarchy starts with a small, expensive, and relatively fast
module, called the cache (T\F) فراغcache is followed in the hierarchy by a larger
,less expensive, and relatively slow main memory part hierarchy by larger less
expensive, and far slower magnetic memories that consist of the (hard) disk and
the tape
: يبدأ من, التصنيف والبناء المعماري للذاكره يف الكمبيوتر بحسب الحجم والثمن والكفاءه: توضيح
1 – Cache Memory
2 – Main Memory
3 – Hard Desks and Tapes
MEMORY LOCATIONS AND OPERATIONS
Byte : an entity consisting of 8 bits is called a byte
Word : the entity consisting of n bits that can be stored and retrieved in and out
of the memory using one basic memory operation (the smallest addressable
entity
size of a word ranges from 16 to 64 bits فراغ
!? What is the number of bits needed to address M words in Memory
يعط حجم بالسؤال ,مثال حجم معلومه ), )Word Size = 2Gbyte
ي من هذه الصيغه,
ويسألنا كم بت نحتاج ى
حت نخزنها يف موقع او عنوان معي ,او تعريفها يف هذا الموقع ؟
عىل هذا األثر نستخدم هذه العالقه :
L = 𝑳𝒐𝒈𝟐 M
) 𝒓𝒆𝒘𝒐𝑷𝟐 L = 𝑳𝒐𝒈𝟐 (Memory Size x
𝒓𝒆𝒘𝒐𝑷𝟐 نحصل عليها من هذه القيم :
ه:
اذا كان الحجم Giga byte or GBفالقيمه ي
𝟎𝟑𝟐
ه:
اذا كان الحجم MB or Mega Byte or Mega Wordفالقيمه ي
𝟎𝟐𝟐
ه:
اذا كان الحجم KB or Kilo Byteفالقيمه ي
𝟎𝟏𝟐
أمثله عىل ذلك :
Q \ if the size of memory is 64M (Mega Word) , How many or What is the
? number of bits needed to address
Answer :
L = 𝑳𝒐𝒈𝟐 M
) 𝟎𝟐𝟐 L = 𝑳𝒐𝒈𝟐 (64 x
نحول الحجم اىل قوه مرفوعه
نجمع أالسس ) 𝟎𝟐𝟐 L = 𝑳𝒐𝒈𝟐 (𝟐𝟔 x
نأخذ أالس ناتج مباش) 𝟔𝟐𝟐( 𝟐𝒈𝒐𝑳 = L
L = 26 bits
Q - Mid\ if the size of memory is 2Gb (Giga Byte) , How many or What is the
number of bits needed to address ?
Answer :
L = 𝑳𝒐𝒈𝟐 M
L = 𝑳𝒐𝒈𝟐 (2 x 𝟐𝟑𝟎 )
نحول الحجم اىل قوه مرفوعه
L = 𝑳𝒐𝒈𝟐 (𝟐𝟏 x 𝟐𝟑𝟎 ) نجمع أالسس
L = 𝑳𝒐𝒈𝟐 (𝟐𝟑𝟏 ) نأخذ أالس ناتج مباش
L = 31 bits
Q - Mid\ if the size of memory is 32bits (bit) , How many or What is the number
of bits needed to address ?
ونأخذ مساواة البايت, نقوم بتقسيم البت عىل البايت وكأثبات عالقه, يف حال اعطاء الحجم بالبت
: وهذا الحل والتوضيح, ألن القيمه ثابته ومباشة, للبت مباشة
1 Byte = 8 bits ثابت
32 bits / 8 = 4 Byte
: بالتاىل
ي , كـقيمه ثابته ونرفعها اىل أس8 bit نأخذ الـ
L = 𝑳𝒐𝒈𝟐 (𝟐𝟖 x 𝟐𝟐𝟎 ) نجمع أالسس
L = 𝑳𝒐𝒈𝟐 (𝟐𝟐𝟖 ) نأخذ أالس ناتج مباش
L = 28 bits
➢ there are two basic memory operations: These are the memory write and
memory read operations فراغات
o memory read and memory write operations are performed by the
central processing unit (CPU).
Q \ What are basic steps are needed in order for the CPU to perform a write
operation into a specified memory location ?
Answer:
1. The word to be stored into the memory location is first loaded by the CPU
into a specified register, called the memory data register (MDR).
2. The address of the location into which the word is to be stored is loaded by
the CPU into a specified register, called the memory address register (MAR).
3. A signal, called write, is issued by the CPU indicating that the word stored in
the MDR is to be stored in the memory location whose address in loaded in
the MAR.
MDR : Memory Data Register
MAR : Memory Address Register
Q \ What are basic steps are needed in order to perform a memory read
operation ?
Answer:
1. The address of the location from which the word is to be read is loaded into
the MAR.
2. A signal, called read, is issued by the CPU indicating that the word whose
address is in the MAR is to be read into the MDR.
3. After some time, corresponding to the memory delay in reading the specified
word, the required word will be loaded by the memory into the MDR ready
for use by the CPU.
Q \ What are basic steps are needed in order to perform a memory read and
write operation ? تكتب جواب السؤالي أعاله
MDR and the MAR are registers used exclusively by the CPU and are not
accessible to the programmer فراغ
ADDRESSING MODES
Q \ What are Addressing Modes?
Answer :
• Immediate Mode
• Direct (Absolute) Mode
• Indirect Mode
• Indexed Mode
• Other Modes
- Relative Mode
- Autoincrement Mode
- Autodecrement Mode
Instructions can be classified based on the number of operands as:
three address , two-address, one-and-half-address, one-address, and zero
address
any operation performed by the CPU needs to be addressed In computer
terminology, such information is called the operand.فراغ
any instruction issued by the processor must carry at least two types of
information These are the operation to be performed, encoded in what is called
the op-code فراغ
and the address information of the operand on which the operation is to be
performed, encoded in what is called the address field. فراغ
Q \ What are the fields that each line of assembly program has ?
Answer :
1 – Operand
2 – Operation Operand (Op – Code)
3 – Address and Comments
4 – Label
Q \ each line of assembly program split into the four following fields , label , and
op code , operand , comments , what is label used for ?
Answer :Label serve as marker of flow of execution and enable effective control
and management for the program
the source operand: The source operand is a constant, a value stored in a
register, or a value stored in the memory.
The destination field: represents the place where the result of the operation is
to be stored
Examples and Explain for instruction Types:
❖ three-address instruction : ADD R1,R2,R3 (add R1 and R2 , Store in R3)
❖ two-address instruction : ADD R1,R2 ( add R1 and R2 , Store in R2)
❖ one-address instruction : this type uses Accumulator Register
❖ one and half instruction : ADD B,R1(add R1 to B , Store in R1)
❖ zero-address instruction : ADD (SP+),(SP)(uses Stack pointer and push and pop
operations to perform , add the contents of pointed stack and store them back
in SP)
Accumulator Register : is a Register that used add for example its contents and holds
one of the operands to another Register and then store back the result in the
accumulator (ADD R1,𝑹𝒂𝒄𝒄 )
Q \ what is the role of the accumulator register in the one address instructions ? give
example for such instruction?
Answer: used add for example its contents and holds one of the operands to another
Register and then store back the result in the accumulator (ADD R1,𝑹𝒂𝒄𝒄 )
Q \ what is the role of the stack in zero address instruction? Give an Example
Answer: In a zero-address instruction set, the stack is used for storing intermediate
values and return addresses for function calls , example, ADD (SP)+, (SP). The
instruction adds the contents of the stack location pointed to by the SP to those
pointed to by the SP + 1 and stores the result on the stack in the location pointed to by
the current value of the SP.
Addressing modes :The different ways in which operands can be addressed are called
the addressing modes
Immediate addressing mode: The simplest addressing mode is to include the operand
itself in the instruction, that is, no address information is needed. This is called
immediate addressing
Indexed addressing mode :adding a constant value to the content of a register. This is
called indexed addressing
فاالجابه تكون, مع اعطاء مثال, ماهو األدرس كذا, االسئله العامه عنه تكون, أنواع األدرس: مالحظه
المثال لكل نوع+ أو مقارنه بي نوع ونوع أخر عن طريق كتابة التعريف, التعريف مع المثال ألي نوع يطلب
Immediate Mode
the value of the operand is (immediately) available in the instruction itself
Example : LOAD #1000, 𝑹𝒊
Q \ The use of immediate addressing leads to poor programming practice.
Answer:
because a change in the value of an operand requires a change in every
instruction that uses the immediate value of such an operand
Direct (Absolute) Mode
the address of the memory location that holds the operand is included in the
instruction
Ex \ LOAD 1000, 𝑹𝒊
Q \ What is the advantage and disadvantage(limitation) of Direct Mode?
❖ Advantage :Direct (absolute) addressing mode provides more flexibility
compared to the immediate mode
❖ Disadvantage : However, it requires the explicit inclusion of the operand
address in the instruction. A more flexible addressing mechanism is
provided through the use of the indirect addressing mode.
Q \ What is the alternative way for getting more flexibility than the direct
(absolute) addressing mode? Explain
Answer: An alternative way for achieving more flexibility than direct addressing
mode is to use indirect addressing mode. In indirect addressing, the operand
does not contain the actual value to be used,. This allows for greater flexibility
as the operand can dynamically point to different locations in memory based on
program logic or data stored in memory..
Indirect Mode
more flexible than the previous modes , customary to include the name of the
register or the memory location in parentheses.
Ex \ LOAD (1000), 𝑹𝒊 , The meaning of this instruction is to load register Ri with the
contents of the memory location whose address is stored at memory address 1000
There are 2 types of indirect Mode :
1-register indirect addressing, if a register is used to hold the address of the
operand, and 2- memory indirect addressing, if a memory location is used to hold
the address of the operand
Indexed Mode
In this addressing mode, the address of the operand is obtained by adding a
constant to the content of a register, called the index register. Consider, for
example: LOAD X(𝑹𝒊𝒏𝒅 ), 𝑹𝒊
loads register 𝑹𝒊 with the contents of the memory location whose address is the
sum of the contents of register 𝑹𝒊𝒏𝒅 and the value X
indexing requires an additional level of complexity over register indirect
addressing
Other Modes : Relative Mode
Relative addressing is the same as indexed addressing except that the program
counter (PC) replaces the index register , for example : LOAD X(PC), 𝑹𝒊
Q\ What similarity and difference between indexed and relative addressing
modes?
Answer. The main similarity between the two is that they both involve adding
an offset to a base address for memory access. The main difference is that in
relative mode, the offset is relative to a specific register, while in indexed
mode, the offset is added to a base address in memory.
Other Modes : Autoincrement
This addressing mode is similar to the register indirect addressing mode in the
sense that the effective address of the operand is the content of a register, call it
the autoincrement register, that is included in the instruction.
Ex \ LOAD (𝑹𝒂𝒖𝒕𝒐 ) + , 𝑹𝒊
This instruction loads register 𝑹𝒊 with the operand whose address is the content
of register 𝑹𝒂𝒖𝒕𝒐 . After loading the operand into register 𝑹𝒊 , the content of
register 𝑹𝒂𝒖𝒕𝒐 is incremented
Other Modes :Autodecrement
Mode
Similar to the autoincrement, the autodecrement mode uses a register to hold
the address of the operand. However, in this case the content of the
autodecrement register is first decremented and the new content is used as the
effective address of the operand.
Ex \ LOAD - (𝑹𝒂𝒖𝒕𝒐 ), 𝑹𝒊
ثم التنفيذ, تتم تنقيص القيمه, أما يف النقصان, ينفذ ثم تتم زيادة القيمه, يف الزياده: مالحظه
Q \What is the similarity and difference between the auto-increment and the
auto-decrement addressing modes?
Answer: Main similarity is In auto increment addressing mode, the memory
address is automatically incremented after each read or write operation, while
in auto decrement addressing mode, the memory address is automatically
decremented after each read or write operation. Main Difference is that impacts
the direction in which the memory locations are accessed during sequential
operations.
INSTRUCTION TYPES
Data movement instructions : are used to move data among the different units
of the machine Like [Move instruction]
يخص الجدول أعاله
أو صح وخطأ, فراغات أو تعريف+ MCQ
Q / Why the most modern architectures do not have Multiply or Divide instruction
on their instruction set ?
Answer:
some machines have MULTIPLY and DIVIDE instructions. These two instructions
are expensive to implement and could be substituted by the use of repeated
addition or repeated subtraction. Therefore, most modern architectures do not
have MULTIPLY or Divide instructions on their instruction set
Control (sequencing) instructions: are used to change the sequence in which
instructions are executed CONDITIONAL BRANCHING (CONDITIONAL JUMP),
UNCONDITIONAL BRANCHING (JUMP), or CALL instructions
Q \ What is the Purpose of Shift Logical Operation? Or What the Meaning?
ى
لباف التعاريف
وصيغة السؤال أعاله مشموله ي, ه التعريف للشفت الموجود بالجدول
تكون االجابه ي
Q \ What is the Purpose of OverFlow Flag ? Or What the Meaning?
ى
لباف التعاريف
وصيغة السؤال أعاله مشموله ي, ه التعريف للفالك الموجود بالجدول
تكون االجابه ي
Q \ What are the main Conditional Code (CC) Register Flags ? List and Explain
Answer :
Q \ What does the following notion mean?
البنامج بالتفصيل لكل عمليه ولكل سطر معناها الزم ر, مثل هكذا صيغ
تشحله ر
Answer:
• LOAD #100, R1: This instruction loads the value 100 into register R1 , #100
indicates an immediate value.
• Loop :ADD → this is a label that marks the start of a loop
• ADD (𝑹𝟐 ) + , 𝑹𝟎 : This is an increment addressing mode operation , the
instruction adds the value pointed to by register 𝑅2 (memory location (𝑅2 ))
to the value in 𝑅0 and stores the result back into 𝑅0 . After the operation,
𝑅2 is incremented by 1 to point to the next memory address.
• DECREMENT 𝑹𝟏 : This decrements the value in register 𝑅1 by 1.
• BRANCH-IF-GREATER-THAN Loop: This instruction checks the value in
𝑅1 after the decrement. If the value in 𝑅1 is greater than 0, the program
branches (jumps) back to the instruction labeled Loop , then The program
iterates 100 times , until reaches 0 and halt (stop) the program.
It’s When that one Free Man do it, one Man Army, the
only one and the right one, but wrong place and time?
- Abdullah Fadil