You are on page 1of 33

Computer Organization

Lec # 6: Addressing

Bnar Mustafa

bnar.mustafa8@gmail.com

Spring 2022
Video Links

Part 1: https://www.youtube.com/watch?v=3A2Y4NOZXlM&t=3s

Part 2: https://www.youtube.com/watch?v=VOJU9S8EXUM&t=5s

Part 3: https://www.youtube.com/watch?v=hZPKENWoeuA&t=17s
Most of arithmetic and logical operation
used in assembly language
Operation function
ADD adding two integer operands
FADD adding two floating point operands
SUB subtracting two integer operands
FSUB subtracting two floating point operands
MUL multiplying two integer operands
FMUL multiplying two floating point operands
DIV dividing two integer operands
FDIV dividing two floating point operands

OR logically OR ing two operands


AND logically AND ing two operands
NOT logically Negating one operands
SHR logically shift to the right one operands
SHL logically shift to the left one operands
Example:
SHR AC,3
If AC= 00010110 ; (AC is 8 bit register)

AC= 00000010

Computer Organization - Bnar Mustafa


Data Transfer Instructions

• MOV MOV Destination, Source


• PUSH
• POP − MOV CX, 045FH
• PUSHA − MOV BL, [43E4H]
• POPA − MOV AX, DX
• XCHG − MOV DH, [BX]
• XLAT − MOV DS, BX
− MOV RESULTS[BP], AX

Computer Organization - Bnar Mustafa


PUSH Source XCHG Destination, Source
− PUSH BX
− PUSH DS − XCHG AX, BX
− PUSH TABLE[BX] − XCHG AL, CH
− XCHG AL, PRICES[BX]

POP Destination
NOT Destination
− POP BX − NOT BX
− POP DS − NOT BYTE PTR[BX]
− POP TABLE[BX]
− PUSHA AND Destination, Source
− POPA − AND BH, CL
− AND CX, [SI]
− AND BX, 00FFH
− AND DX, BX
Computer Organization - Bnar Mustafa
OR Destination, Source
XOR Destination, Source
− OR BH, CL − XOR BH, CL
− OR CX, [SI] − XOR BP, DI
− OR BX, 00FFH − XOR DX, BX
− OR DX, BX

SAL / SHL Destination, Count


− SAL BX, 01
− SAL BP, CL
− MOV CL, 04H
− SAL AL, CL

Computer Organization - Bnar Mustafa


SHR Destination, Count
SHR BP, 01
SHR AL, CL

SAR Destination, Count


SAR DI, 1
SAR AL, 01

Computer Organization - Bnar Mustafa


ROL Destination, Count
− ROL AX, 1
− ROL BL, CL

RCL Destination, Count


− RCL AX, 1
− RCL BL, CL

Computer Organization - Bnar Mustafa


ROR Destination, Count
ROR BL, 01
ROR AL, CL

RCR Destination, Count


•RCR BL, 01
•RCR AL, CL

Computer Organization - Bnar Mustafa


Homework 1
• What is the difference between SAR, SHR, ROR, RCR
• Explain in short with an example
Bit Manipulation Instructions
Logical Shift Rotate

 NOT  SAL  ROL


 AND  SHL  RCL
 OR  SAR  ROR
 XOR  SHR  RCR
 TEST

Computer Organization - Bnar Mustafa


Transfer of data between processor and
memory

Operation Function
LOAD Register [M]

STOR [M] Register

PUSH copy a data in to the stack from register

POP copy a data from stack to the register

Where the stack is a segment in the memory named as a stack


segment also used for saving the data, but by a special formula.

Computer Organization - Bnar Mustafa


Transfer of Control
• For all the operation types to be execute a sequence of a
program, so the next instruction to be performed immediately
where this will be done by the processor through update the
program counter which contain the address of the instruction in
the memory.
So transfer of control or JMP to be used for:-
 Ability to execute some instructions many times without need to
repeat writing it in the program in each time of used.

 Writing a program that can do the same task by low number of


instruction code so it was gave the ability to use small memory size.

 Ability to perform many jobs depending on decision making of


condition.

Computer Organization - Bnar Mustafa


Branching Instructions
Also called jump instruction has one operand which is the address of
the next instruction that must be executed and the branching
types :-
• Conditional
• Unconditional

1-Unconditional Branching :-
This type of branching will change the program counter PC to new
location of branching without checking any condition;
The form of this instruction was:
BR X or JMP X
, Where X was the location or a label that need to jump to it.

Computer Organization - Bnar Mustafa


Unconditional Branching Examples
cont.
Example 1:
0000 ADD A,B ;A=A+B
0003 SUB B,C ;B=B-C
0006 BR 1000h
.
.
.
1000 MOV A,B

Computer Organization - Bnar Mustafa


Example 2: Example 3:

002 ADD A,B ADD A,B


004 INC A L2: INC A
006 MOV C,A MOV C,A
008 INC C INC C
00A JMP 004 JMP L2
00C END END

Note :
L2 is the label of address
Can be letter , letter number, symbol, symbol number .
Illegal to begin by number ex. 2L
2-Conditional Branching
Changing the program counter in the case of jumping to location
or label depending on conditions of the flags;
Sample of jumping :
JP X ; or BRP X (jump if positive)
JN X ; or BRN X (jump if negative)
JZ X ; or BRZ X (jump if zero)
JO X ; or BRO X (jump if overflow)

In the above type of conditional jumping the flags states to be


checked depending on the most recent result that have been
setting the conditional code.

Computer Organization - Bnar Mustafa


Example 1: Example 2: Example 3:
MOV X, 10 MOV X, 10 MOV C, 4
MOV Y, 20 MOV Y, 20 MOV A, 0
SUB X, Y **: SUB X, Y @1: INC A
JP * JP * DEC C
ADD X , 40 ADD X , 40 JZ @1
*: INC X INC X END
END JMP **
*: END

Computer Organization - Bnar Mustafa


Example4: (if all register size 8 bit ) Example5:

MOV X , 5 MOV X , 50
MOV Y , 5 MOV Y , 50
MUL X, Y MUL X, Y
JO LLO JO LLO
END END
LLO: MOV X, Y LLO: MOV X, Y
END END

X= X value after multiplication will be :

0 0 0 1 1 0 0 1

1001 1 1 0 0 0 1 0 0

Computer Organization - Bnar Mustafa


Some form of branching instruction:

Instruction Function operation


BR X Setting PC by X without checking any condition
BRE X, Y, Z Setting PC by Z if X=Y
BRNE X, Y, Z Setting PC by Z if X≠Y
BLT X, Y, Z Setting PC by Z if X < Y
BGT X ,Y,Z Setting PC by Z if X > Y
BLE X, Y, Z Setting PC by Z if X ≤ Y
BGE X, Y, Z Setting PC by Z if X≥Y
BRE R1, R2, X
Its mean; Branch to X if R1=R2
Else continue

Example:
Check the branching of the following instruction and find PC
values?
203 BRZ 211
Sol. :
If the condition occur (last ALU result before branching equal
zero)
Then PC=211
Else if the condition is false (no zero)
Then PC=PC+1
=204
Computer Organization - Bnar Mustafa
Generating Memory Address
Generating the address of the memory location is either directly or
indirectly by register, so direct addressing must be done using
direct number in square brackets for example:
MOV [2000h], R1
In this instruction R1 is moved to memory location 2000h, so the
location was fixed.

While; In dynamically changed location it must be used indirect


mode of addressing by register (where the location is varied).

Computer Organization - Bnar Mustafa


Example:
Comments
MOV R2, 1000h ; initialize R2
MOV R0, 10 ; initialize counter R0
MOV R1,0 ; initialize R1
back: ADD R1,[R2] ;dynamic addressing
INC R2 ; R2=R2+1
DEC R0 ; R0=R0-1
BRNZ back ; branching if no zero result in R0
Why R0 ?
Because it is the
last ALU result
before branching

Computer Organization - Bnar Mustafa


Homework 2
Write a program to subtract (X-Y) and store the result in Z
register, then:

Check if Z =0, add 50 to X reg. else decrement Y reg.


Let the PC = 100.

Computer Organization - Bnar Mustafa


Memory Segmentation
• Segmentation is the process in which the main memory of the
computer is logically divided into different segments and each
segment has its own base address. It is basically used to
enhance the speed of execution of the computer system, so that
the processor is able to fetch and execute the data from the
memory easily and fast.

• A segment is a logical unit of memory that may be up to 64


kilobytes long. Each segment is made up of contiguous
memory locations. It is an independent, separately addressable
unit. Starting address will always be changing. It will not be
fixed.
• Advantages of the Segmentation The main advantages of
segmentation are as follows:

–It provides a powerful memory management mechanism.


–Data related or stack related operations can be performed in different
segments.
–Code related operation can be done in separate code segments.
–It allows to processes to easily share data.
–It allows to extend the address ability of the processor, i.e.
segmentation allows the use of 16 bit registers to give an addressing
capability of 1 Megabytes. Without segmentation, it would require
20 bit registers.
–It is possible to enhance the memory size of code data or stack
segments beyond 64 KB by allotting more than one segment for
each area.
Types Of Segmentation –
Overlapping Segment – A segment starts at a particular address and
its maximum size can go up to 64kilobytes. But if another segment
starts along with this 64kilobytes location of the first segment, then the
two are said to be Overlapping Segment.
Non-Overlapped Segment – A segment starts at a particular address
and its maximum size can go up to 64kilobytes. But if another
segment starts before this 64kilobytes location of the first segment,
then the two segments are said to be Non-Overlapped Segment.
Rules of Segmentation: segmentation process follows some rules as
follows:
The starting address of a segment should be such that it can be evenly
divided by 16.
Minimum size of a segment can be 16 bytes and the maximum can be
64 kB.
Good luck 

You might also like