0% found this document useful (0 votes)
17 views

Microprocessor lecture 10

Uploaded by

davidmucheru33
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)
17 views

Microprocessor lecture 10

Uploaded by

davidmucheru33
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/ 11

Bit Manipulation Instructions 1

 Bit manipulation group is used to perform AND, OR,


XOR and NOT operations on 8, 16 and 32 bit data
contained in the register or memory.
 Shift and rotate operations on bytes and words are

also included with single or multi-bit shifts or rotate


NOT > Invert each bit of a byte or word
 The NOT instruction inverts each bit (forms the 1’s

complement) of a byte or word in the specified


destination.
 The destination can be a register or a memory

location.
 This instruction does not affect any flag.

NOT BX Complement content or BX register


NOT [BX] Complement memory byte at offset
[BX] in data segment
Bit Manipulation Instructions 2
AND >AND each bit of word
OR > OR each bit of word
TEST > AND operands to update flags but don’t
change the operands
SHL > Shift bit of word or byte left. Put 0 on LSB
SHR > Shift bit of word or byte right. Put 0 on MSB
SAR > Shift word or byte right. Copy old MSB into
new LSB
ROL > Rotate bits of byte or word left, MSB to LSB
and CF
ROR > Rotate bits of byte or word right, LSB to MSB
and CF
RCR > Rotate bits of byte or word right, LSB to CF
and CF to MSB
String Instructions 1
 A string is a collection of bytes stored sequentially in
memory whose length can be upto 64 kB.
 Instructions are included in this group to move, scan

and compare strings.


REP > Repeat instruction until CX=0
REPE/REPZ > Repeat instruction until CX=0 or ZF=1
MOVS/MOVSB/MOVSW > Move a byte or word from one
string to another
COMPS/COMPSB/COMPSW > Compare two string bytes
or words
SCAS/SCASB/SCASW > Scan string; Compare a string
byte with byte in AL or string word in AX
LODS/LODSB/LODSW > Load string byte into AL or string
word into AX
STOS/STOSB/STOSW > Store byte from AL or word from
AX into a string
String Instructions 2
Example
 Write an assembly language program to copy a

string of 6 bytes from a memory starting at


2000:0004H into a memory starting at
3000:0014H
Solution
MOV AX,2000H
MOV DS,AX
MOV AX,3000H
MOV ES,AX
MOV SI, 0004H
MOV DI, 0014H
MOV CX,0006H
REP MOVSB
Processor Control Instructions 1
 These are instructions used to directly control the state of
some of the flags, to enable and disable interrupt, and
synchronize the processor with external peripherals. They
are
STC > Set carry flag
CLC > Clear carry flag
CMC > Compliment the state of the carry flag
STD > Set direction flag
CLD > Clear direction flag
STI > Set interrupt flag
CLI > Clear interrupt flag
HLT > Halt until interrupt or rest
WAIT > Wait until signal on the TEST pin is low
ESC > Escape to external coprocessor
NOP > No action except fetch and decode
Loops and Jumps 1
 If we need to perform a specific operation more than once
in a program, we must duplicate the entire sequence of
instructions each time we want to perform the operation.
 Duplicating a sequence of instructions many times in a
program will be frustrating and time consuming.
 Program control instructions help to eliminate this
duplication.

a) JMP
 The JMP instruction makes the microprocessor take its next

instruction from some other place other than the next


consecutive memory.
 JMP instructions can be conditional or unconditional.

 An unconditional JMP instruction is always taken whenever

it occurs an is executed immediately.


 A conditional JMP requires the microprocessor to make a

decision based on the contents of the flag registers


Loops and Jumps 2
 The general format of the JMP instruction is
JMP destination
 The destination can be a label, a memory address or a 16

bit register.
 A direct jump is to a label.

 An indirect jump is to a register that points to the next

instruction
Example
MOV BX, 0001H
SUB AX, AX
REPEAT ADD AX, BX
JMP REPEAT
 In this program, AX will be incremented by 1 continuously

until the computer is turned off.


 There is no condition to stop the program.
Loops and Jumps 3
Example
SUB AX, AX
MOV BX, 0007H
MOV CX, 0003H
MULT ADD AX, BX
DEC CX
JMP MULT
MOV DX, AX
 In this program, JMP instruction is used to control

the number of times a mathematical operation is


performed.
 The program can be used to do multiplication by

repeated addition
Loops and Jumps 4
b) LOOP
 The loop instruction is a special form of jump instruction with a

build in count capability.


 Like the jump instruction, it is used to repeat an operation or

sequence of instructions.
 This is referred to as looping.

 Loop instruction can be conditional or unconditional and are

always used with the CX register.


Example
SUB AX, AX
MOV BX, 0007H
MOV CX, 0003H
MULT ADD AX, BX
DEC CX
LOOP MULT
MOV DX, AX
The loop instruction uses the CX register to determine the number of
times the loop is to be performed.
 When used, a value must first be placed in the CX register.
Loops and Jumps 5
 There are also conditional loop instructions
that use the count register.
LOOPZ > Loop while zero (ZF=1, CX=0)
LOOPNZ > Loop while NOT zero (ZF=0,
CX=0)
 Other jump instructions include

JA/JNBE > Jump if above/ Jump if not below


nor equal
JC > Jump if carry flag is set CF=1
JO > Jump if overflow (OF=1)
JS > Jump if sign flag is set SF=1
JE > Jump if equal
Subroutines and Interrupts 1
 These instructions are required to call and
return from subroutine and handle
interrupt.
 Examples of such instructions are:

INT nn > Interrupt program executions and


call an interrupt service procedure at
location nn
IRET > Return from ISP to the main program
CALL > Call a sub-program, save return
address on stack
RET > Return from sub-program to main
program

You might also like