0% found this document useful (0 votes)
12 views43 pages

CH 4 Instructions 2

Uploaded by

gadisakarorsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views43 pages

CH 4 Instructions 2

Uploaded by

gadisakarorsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

CHAPTER 4: INSTRUCTIONS

 Data Movement Instructions


 MOV Revisited
 PUSH/POP
 Load-Effective Address
 String Data Transfers
 Miscellaneous Data Transfer
Instructions
 Arithmetic and Logic instructions
 Arithmetic Instructions
 Basic
Compiled By: Mr. Abdisa L.Logic
AUWC Instructions
dept of
1 CS  Shift and Rotate
Data movement instructions
The mov instruction allows you to copy the
contents of one register into another register.
The MOV instruction copies a word or byte of
data from a specified source to a specified
destination.
The destination can be a register or a memory
location.
The source can be a register, a memory
location or an immediate number.
The source and destination cannot both be
memory locations.
They must both be of the same type (bytes or
2 words).
Compiled By: Mr. Abdisa L. AUWC dept of
CS
Move Instruction
 Purpose: Data transfer between memory cells, registers
and the accumulator.
 Syntax:
 MOV Destiny, Source
 Where Destiny is the place where the data will be moved
and Source is the place where the data is.
 Example:
MOV AX, 0006h
MOV BX, AX
MOV AX, 4C00h
INT 21H
 This small program moves the value of 0006H to the AX
register, then it moves the content of AX (0006h) to the
BX register, and lastly it moves the 4C00h value to the
3
AXCompiled
register to end the execution with the 4C option of
By: Mr. Abdisa L. AUWC dept of
theCS21h interruption
MOV CX, 037AH Put immediate number
037AH to CX .
 MOV BL, [437AH] Copy byte in DS at offset
437AH to BL.
MOV AX, BX Copy content of register
BX to AX.
MOV DL, [BX] Copy byte from memory at
[BX] to DL.
MOV DS, BX Copy word from BX to DS
register.

4 Compiled By: Mr. Abdisa L. AUWC dept of


CS
Loading instructions
 They are specific register instructions. They are used to load
bytes or chains of bytes onto a register.
LEA INSTRUCTION
 Purpose: To load the address of the source operator
 Syntax:
 LEA destiny, source

LEA – LEA Register, Source


This instruction determines the offset of the variable
or memory location named as the source and puts
this offset in the indicated 16-bit register.
 LEA does not affect any flag.
 LEA BX, PRICES Load BX with offset of PRICE in DS
 LEA BP, SS: STACK_TOP Load BP with offset of STACK_TOP in SS
 LEA CX, [BX][DI] Load CX with EA = [BX] + [DI]
5 Compiled By: Mr. Abdisa L. AUWC dept of
CS
LDS – LDS Register, Memory address of
the first word
 This instruction loads new values into the specified register and
into the DS register from four successive memory locations.
 The word from two memory locations is copied into the specified
register and the word from the next two memory locations is
copied into the DS registers.
 LDS does not affect any flag.
 Example
 LDS BX, [4326] Copy content of memory at displacement
4326H in DS to BL, content of 4327H to BH.
 Copy content at displacement of 4328H and 4329H in DS to DS
register.
 LDS SI, SPTR Copy content of memory at displacement
SPTR and SPTR + 1 in DS to SI register.
 Copy content of memory at displacements SPTR + 2 and SPTR +
3 in DS to DS register.
 DS: SI now points at start of the desired string.

6 Compiled By: Mr. Abdisa L. AUWC dept of


CS
LES – LES Register, Memory address of
the first word
This instruction loads new values into the specified
register and into the ES register from four
successive memory locations.
The word from the first two memory locations is
copied into the specified register, and the word
from the next two memory locations is copied into
the ES register.
LES does not affect any flag.
Example
LES BX, [789AH] Copy content of memory
at displacement 789AH in DS to BL, content of
789BH to BH, content of memory at displacement
789CH and 789DH in DS is copied to ES register.
LES
7 DI, [BX]
Compiled Copy content of memory
By: Mr. Abdisa L. AUWC dept of
CS
Stack instructions
These instructions allow the use of the stack to
store or retrieve data. E.g. POP & PUSH.
POP INSTRUCTION
Purpose: It recovers a piece of information from the
stack
Syntax:
POP destiny
PUSH INSTRUCTION
Purpose: It places a word on the stack.
Syntax:
PUSH source
8 Compiled By: Mr. Abdisa L. AUWC dept of
CS
9 Compiled By: Mr. Abdisa L. AUWC dept of
CS
10 Compiled By: Mr. Abdisa L. AUWC dept of
CS
11 Compiled By: Mr. Abdisa L. AUWC dept of
CS
12 Compiled By: Mr. Abdisa L. AUWC dept of
CS
STRING DATA TRANSFERS

13 Compiled By: Mr. Abdisa L. AUWC dept of


CS
14 Compiled By: Mr. Abdisa L. AUWC dept of
CS
15 Compiled By: Mr. Abdisa L. AUWC dept of
CS
16 Compiled By: Mr. Abdisa L. AUWC dept of
CS
17 Compiled By: Mr. Abdisa L. AUWC dept of
CS
18 Compiled By: Mr. Abdisa L. AUWC dept of
CS
19 Compiled By: Mr. Abdisa L. AUWC dept of
CS
20 Compiled By: Mr. Abdisa L. AUWC dept of
CS
21 Compiled By: Mr. Abdisa L. AUWC dept of
CS
22 Compiled By: Mr. Abdisa L. AUWC dept of
CS
Miscellaneous Data Transfer Instructions
XCHG – XCHG Destination, Source
 The XCHG instruction exchanges the content of a register with the
content of another register or with the content of memory location(s).
 It cannot directly exchange the content of two memory locations.
 The source and destination must both be of the same type (bytes or
words).
 The segment registers cannot be used in this instruction.
 This instruction does not affect any flag.
 Used in programs, data transfer instructions detailed in this section
are XCHG, LAHF, SAHF, XLAT, IN, OUT, BSWAP, MOVSX, MOVZX, and
CMOV.
 Examples
 XCHG AX, DX Exchange word in AX with word in DX
 XCHG BL, CH Exchange byte in BL with byte in CH
 XCHG AL, PRICES [BX] Exchange byte in AL with byte in memory
at Compiled By: Mr. Abdisa L. AUWC dept of
23
CS EA = PRICE [BX] in DS.
Home work
 Read about LAHF, SAHF, XLAT, IN, OUT, BSWAP,
MOVSX, MOVZX, and CMOV Miscellaneous Data
Transfer Instructions

24 Compiled By: Mr. Abdisa L. AUWC dept of


CS
Arithmetic and Logical Instructions
Arithmetic instructions
 They are used to perform arithmetic operations on the
operators. Those instructions are: ADD, SUB, MUL & DIV
 ADD, ADC
 INC
 DEC
 SUB, SBB
 CMP
 AAA, AAS,AAM, AAD
 DAA, DAS
 NEG
 MUL, IMUL
 CBW
 CWD
 DIV, IDIV

25 Compiled By: Mr. Abdisa L. AUWC dept of


CS
ADD INSTRUCTION
 Purpose: Addition of the operators.
 Syntax:
 ADD destiny, source
 It adds the two operators and stores the result on the destiny
operator.
 All flags are affected during its execution.
 Restrictions:-
- Both source and destination operands cannot be
memory locations.
- 2 segment registers cannot be added.
 Examples:-
- ADD AX, 0100H (Immediate)
- ADD AX,BX (Register)
- ADD AX, [SI] (Register Indirect)
- ADD AX, [5000H] (Direct)
- ADD [5000H], 0100H (Immediate)
- ADD 0100H (Destination AX, implicit)
26 Compiled By: Mr. Abdisa L. AUWC dept of
CS
ADC: Add with Carry
- Same as ADD but adds the carry to the result.
- All flags are affected.
• Examples:-
- ADC 0100H (Immediate, AX implicit)
- ADC AX, BX (Register)
- ADC AX, [SI] (Register Indirect)
- ADC AX, [5000H] (Direct)
- ADC [5000H, 0100H (Immediate)
INC: Increment
- Increases the content of specified register or memory
location by 1.
- All condition code flags affected except Carry Flag (CF)
- Immediate data cannot be operand of this instruction.
- Examples:-
INC AX (Register)
INC [BX] (Register Indirect)
INC [5000H] (Direct)
Compiled By: Mr. Abdisa L. AUWC dept of
27
CS
DEC: Decrement
- Subtracts 1 from the contents of specified
register or memory location.
- All condition code flags affected except Carry
Flag
(CF)
- Immediate data cannot be operand of this
instruction.
- Examples:-
- DEC AX (Register)
- DEC [5000H] (Direct)

28 Compiled By: Mr. Abdisa L. AUWC dept of


CS
SUB INSTRUCTION
Purpose: Subtraction.
Syntax:
SUB destiny, source
It subtracts the source operator from the destiny.
 Condition code flags affected by this instruction.
- Restrictions:-
 Both source and destination cannot be memory
operands.
 Destination cannot be immediate data.
• Examples:-
- SUB AX, 0100H [Immediate, destination is AX]
- SUB AX, BX [Register]
- SUB AX , [5000H] [Direct]
- SUB [5000H], 0100 [Immediate]
29 Compiled By: Mr. Abdisa L. AUWC dept of
CS
SBB : Subtract with Borrow
- Subtracts the source and carry flag together
from the
destination.
- Carry (Borrow) Flag should be set for this
instruction.
- Condition Code flags are affected.
- Examples:-
➢ SUB AX, 0100H [Immediate, destination is AX]
➢ SUB AX, BX [Register]
➢ SUB AX , [5000H] [Direct]
➢ SUB [5000H], 0100 [Immediate]

30 Compiled By: Mr. Abdisa L. AUWC dept of


CS
CMP: Compare
- Compares the source operand(register or
immediate data or memory location) with the
destination (register or memory location)
- Flags are affected.
- Source = Destination (Zero Flag=1)
- Source > Destination (Carry Flag = 1)
- Source < Destination (Carry Flag = 0)
• Examples:-
- CMP BX, 0100H [Immediate]
- CMP AX, 0100H [Immediate]
- CMP [5000H], 0100H [Direct]
- CMP BX, [SI] [Register Indirect]
- CMP BX,CX [Register]

31 Compiled By: Mr. Abdisa L. AUWC dept of


CS
 Purpose: Multiplication with sign.
MUL INSTRUCTION

 Syntax:
 MUL source
 The assembler assumes that the multiplicand will be of the same
size as the multiplier, therefore it multiplies the value stored on
the register given as operator by the one found to be contained in
AH if the multiplier is 8 bits or by AX if the multiplier is 16 bits.
 When a multiplication is done with 8-bit values, the result is stored
on the AX register and when the multiplication is with 16 bit values
the result is stored on the even DX:AX register.
 Examples:-
- IMUL BH
- IMUL CX
- IMUL [SI]
- Restrictions:-
Immediate data cannot be a source in this case.

32 Compiled By: Mr. Abdisa L. AUWC dept of


CS
CBW: Convert Signed Byte to Word
- Converts the signed byte to
signed word
- Does not affect any word.
 CWD: Convert Word to Double
Word
- Operation is done before signed
division
- Does not affect any flag.

33 Compiled By: Mr. Abdisa L. AUWC dept of


CS
DIV INSTRUCTION
Purpose: Division without sign.
Syntax:
DIV source
The divider can be a byte or a word and it is the
operator which is given the instruction.
If the divider is 8 bits, the 16 bits AX register is taken
as dividend and if the divider is 16 bits the even
DX:AX register will be taken as dividend, taking the
DX high word and AX as the low.
If the divider was a byte then the quotient will be
stored on the AL register and the residue on AH, if it
was a word then the quotient is stored on AX and the
residue on DX.
34 Compiled By: Mr. Abdisa L. AUWC dept of
CS
Logic instructions
 They are used to perform logic operations on the
operators.
 Those instructions are:
 AND (Logical AND)
• OR (Logical OR)
• NOT (Logical Invert)
• XOR (Logical Exclusive OR)
• TEST (Logical Compare Instruction)
• SHL/SAL (Shift Logical/ Arithmetic Left)
• SHR (Shift Logical Right)
• SAR (Shift Arithmetic Right)
• ROR (Rotate Right without carry)
• ROL (Rotate Left without carry)
• RCR (Rotate Right through carry)
• RCL (Rotate Left through carry)

35 Compiled By: Mr. Abdisa L. AUWC dept of


CS
AND INSTRUCTION
Purpose: It performs the conjunction of the
operators’ bit by bit.
Syntax:
AND destiny, source
With this instruction the "y" logic operation for
both operators is carried out:
Source Destiny | Destiny
-----------------------------
1 1|1
1 0|0
0 1|0
0 0|0
The result of this operation is stored on the
destiny operator.
36 Compiled By: Mr. Abdisa L. AUWC dept of
CS

NEG INSTRUCTION
Purpose: It generates the complement to 2.
Syntax:
NEG destiny
This instruction generates the complement to
2 of the destiny operators and stores it on the
same operator.
For example, if AX stores the value of 1234H,
then:
NEG AX
This would leave the EDCCH value stored on
the AX register.
37 Compiled By: Mr. Abdisa L. AUWC dept of
CS
OR INSTRUCTION
 Purpose: Logic inclusive OR
 Syntax:
 OR destiny, source
 The OR instruction carries out, bit by bit, the
logic inclusive disjunction of the two operators:
 Source Destiny | Destiny
 -----------------------------------
 1 1|1
 1 0|1
 0 1|1
 0 0|0

38 Compiled By: Mr. Abdisa L. AUWC dept of


CS
Shift and Rotate
SHL/SAL : Shift Logical/Arithmetic Left

SHR : Shift Logical Right

39 Compiled By: Mr. Abdisa L. AUWC dept of


CS
SAR : Shift Arithmetic Right

ROR : Rotate Right without


carry

40 Compiled By: Mr. Abdisa L. AUWC dept of


CS
ROL : Rotate left without carry

RCR : Rotate Right through


carry

41 Compiled By: Mr. Abdisa L. AUWC dept of


CS
RCL : Rotate Left through carry

42 Compiled By: Mr. Abdisa L. AUWC dept of


CS
String Comparisons
 CMPS : Compare string byte or word
- Compares two bytes or words
- If both are equal, ZF is set.
- Example:-
MOV AX,SEG1 [Seg add. of string1 to AX]
MOV DS,AX [Load it to DS]
MOV AX, SEG2 [Seg. add. Of string2 to AX]
MOV ES,AX [Load it to ES]
MOV SI, OFFSET STRING1
MOV DI, OFFSET STRING2
MOV CX, 010H [Length of string to CX]
CLD
REPE CMPSW [compare 010H words of string1 and string2,
if equal
then CX=0 and ZF is set, else ZF is reset]

43 Compiled By: Mr. Abdisa L. AUWC dept of


CS

You might also like