Computer Architecture 1: 1. Introduction To Assembly Language Programming
Computer Architecture 1: 1. Introduction To Assembly Language Programming
Computer Architecture 1: 1. Introduction To Assembly Language Programming
Lecture 4
A. Addressing MODES
1. Introduction to assembly language programming:
Program is a sequence of commands used to tell a microcomputer
what to do.
Each command in a program is an instruction
Programs must always be coded in machine language before they can
be executed by the microprocessor.
A program written in machine language is often referred to as machine
code.
Machine code is encoded using 0s and 1s
A single machine language instruction can take up one or more bytes
of code
In assembly language, each instruction is described with alphanumeric
symbols instead of with 0s and 1s
Instruction can be divided into two parts : its opcode and operands
Opcode identify the operation that is to be performed.
Each opcode is assigned a unique letter combination called a
mnemonic.
Operands describe the data that are to be processed as the
microprocessor carried out the operation specified by the opcode.
Instruction set includes
1. Data transfer instructions
2. Arithmetic instructions
3. Logic instructions
4. String manipulation instructions
5. control transfer instructions
6. Processor control instructions.
As an example for instructions, next section discusses the MOV
instruction.
1
ًم اثٌر هادي عٌسى الرماح.م
303 ح Computer Architecture 1
Fig 1 The MOV instruction and the valid source and destination variations
3. Addressing modes:
An addressing mode is a method of specifying an operand. The 8086
addressing modes categorized into three types:
3.1 Register operand addressing mode
With register operand addressing mode, the operand to be accessed is
specified as residing in an internal register.
MOV AX, BX
2
ًم اثٌر هادي عٌسى الرماح.م
303 ح Computer Architecture 1
3.3.2 indirect addressing: this mode is similar to the direct addressing but
the offset is specified in a base register (BX), base pointer (BP) or an index
register (SI or DI) within the 8086.
MOV AX, [SI]
• Memory cell pointed to by address field contains the
address of (pointer to) the operand
• EA = (A)
— Look in A, find address (A) and look there for
operand
• e.g. ADD (A)
— Add contents of cell pointed to by contents of A to
accumulator
3
ًم اثٌر هادي عٌسى الرماح.م
303 ح Computer Architecture 1
Example 1: For the figure below. What is the result of executing the following
instruction? XCHG AX , [0002]
Solution:
(c) XLAT:
4
ًم اثٌر هادي عٌسى الرماح.م
303 ح Computer Architecture 1
Example 2: For the figure below, what is the result of executing the following
instruction? XLAT
Solution:
Example 3: For the figure below, what is the result of executing the following
instruction? LEA SI , [ DI + BX + 2H]
Solution: SI= (DI) + ( BX) + 2H = 0062H
Example 4: For the figure below, what is the result of executing the following
instruction? LDS SI , [ DI + BX + 2H]
Solution: SI= (DI) + (BX) + 2H = 0062H
5
ًم اثٌر هادي عٌسى الرماح.م
303 ح Computer Architecture 1
Example 6:What is the result after executing each one of the next
instructions?
LEA BP, [F004]
MOV BP, F004
MOV BP, [F004]
Solution:
The instruction LES is similar to the instruction LDS except that it load the Extra
Segment Register instead of Data Segment Register
2. Arithmetic instruction:
The 8086 microprocessor can perform addition operation between any
two registers except segment register ( CS, DS, ES, and SS) and
instruction pointer (IP).
Addition must occur between similar sizes
6
ًم اثٌر هادي عٌسى الرماح.م
303 ح Computer Architecture 1
ADD AX , [ DI + BX + 2H]
Solution:
EA= [ DI + BX + 2H] =[0020 + 0040 + 02H ]= 0062H
PA = (DS × 10H) + EA = 1000H +0062H= 1062H
Memory word stored at location 1062H is 9067
AX = AX + 9067
(a) Addition instructions (b) Allowed operands for ADD and ADC.
(c) Allowed operands for INC instruction
The instruction add with carry (ADC) work similarly to ADD, but in this
case the content of the carry flag is also added, that is
(S) + (D) + (CF) (D)
ADC is primarily used for multiword add operation.
Solution:
7
ًم اثٌر هادي عٌسى الرماح.م
303 ح Computer Architecture 1
MOV AX , [0200]
MOV BX , [0202]
ADD AX , [0300]
ADC BX , [0302]
MOV [0400] , AX
MOV [0402] , BX
INC instruction add 1 to the specified operand
Note that the INC instruction don’t affect the carry flag
Example 9: For the figure below, what is the result of executing the following
instructions?
INC WORD PTR [0040]
INC BYTE PTR [0042]
Solution:
SI= (DI) + (BX) + 2H = 0062H
AAA instruction specifically used to adjust the result after the operation
of addition two binary numbers which represented in ASCII.
AAA instruction should be executed immediately after the ADD
instruction that adds ASCII data.
Since AAA can adjust only data that are in AL, the destination register
for ADD instructions that process ASCII numbers should be AL.
Example 10: what is the result of executing the following instruction
sequence?
ADD AL , BL
AAA
Assume that AL contains 32H (the ASCII code for number 2), BL contain 34H
(the ASCII code for number 4) , and AH has been cleared.
Solution :
8
ًم اثٌر هادي عٌسى الرماح.م
303 ح Computer Architecture 1
9
ًم اثٌر هادي عٌسى الرماح.م