The Wayback Machine - https://web.archive.org/web/20240818121805/https://www.geeksforgeeks.org/string-manipulation-instructions-8086-microprocessor/
Open In App

String manipulation instructions in 8086 microprocessor

Last Updated : 05 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this Article, We will be going through the String Manipulation Instruction, We will start our Article with the Introduction of the String Manipulation Instruction in the 8086, Then We will go through the different String Manipulation Instructions with some Examples, and At last, we will conclude our Article with Some FAQs.

What are String Manipulation Instructions in 8086 microprocessors?

String Manipulation Instructions in the 8086 microprocessor architecture are the set of Instructions that are used to manipulate strings in memory. The String manipulation Instructions offer different functionality such as copying, Searching, and Modifying Strings of data. Key String manipulation instruction in 8086 instruction sets includes different instructions such as MOVSB, CMPSB, SCASB, LODSB, STOSB, and other instructions which are going to be discussed further.

Different String Manipulation Instructions

The string is a series of data bytes or words available in memory at consecutive locations. It is either referred as byte string or a word string. Their memory is always allocated in a sequential order. Instructions used to manipulate strings are called string manipulation instructions. Following is the table showing the list of string manipulation instructions:

OPCODE OPERAND EXPLANATION EXAMPLE
REP instruction repeat the given instruction till CX != 0 REP MOVSB
REPE instruction repeat the given instruction while CX = 0 REPE
REPZ instruction repeat the given instruction while ZF = 1 REPZ
REPNE instruction repeat the given instruction while CX != 0 REPNE
REPNZ instruction repeat the given instruction while ZF = 0 REPNZ
MOVSB none moves contents of byte given by DS:SI into ES:DI MOVSB
MOVSW none moves contents of word given by DS:SI into ES:DI MOVSW
MOVD none moves contents of double word given by DS:SI into ES:DI MOVD
LODSB none moves the byte at address DS:SI into AL; SI is incr/decr by 1 LODSB
LODSW none moves the word at address DS: SI into AX; SI is incr/decr by 2 LODSW
LODSD none moves the double word at address DS:SI into EAX; SI is incr/decr by 4 LODSD
STOSB none moves contents of AL to byte address given by ES:DI; DI is incr/dec by 1 STOSB
STOSW none moves the contents of AX to the word address given by ES:DI; DI is incr/decr by 2 STOSW
STOSD none moves contents of EAX to the DOUBLE WORD address given by ES:DI; DI is incr/decr by 4 STOSD
SCASB none compares byte at ES:DI with AL and sets flags according to result SCASB
SCASW none compares word at ES:DI with AX and sets flags SCASW
SCASD none compares double word at ES:DI with EAX and sets flags SCASD
CMPSB none compares byte at ES:DI with byte at DS:SI and sets flags CMPSB
CMPSW none compares word at ES:DI with word at DS:SI and sets flags CMPSW
CMPSD none compares double word at ES:DI with double word at DS:SI and sets flags CMPSD

Examples of String manipulation instructions in 8086 microprocessor

Given below are some Examples of the String manipulation instructions in 8086 microprocessor

Example of REP with MOVSB Instruction

MOV AX, 7000H    Assign source segment address to AX
MOV DS, AX Load source segment address into DS
MOV AX, 8000H Assign destination segment address to AX
MOV CX, 0E0H Move the length of the string to the counter register CX
MOV SI, 3000H Assign source index address to SI
MOV DI, 4000H Assign destination index address to DI
CLD Ensure auto-increment mode is set by clearing the direction flag
REP MOVSB Repeat the move byte from source to destination instruction CX times


Example of REPE With CMPSB Instruction

MOV AX, SEG_STRING1         Move the segment address of STRING1 to AX
MOV DS, AX Load it to DS
MOV AX, SEG_STRING2 Move the segment address of STRING2 to AX
MOV ES, AX Load it to ES
MOV SI, OFFSET_STRING1 Move the offset of STRING1 to SI
MOV DI, OFFSET_STRING2 Move the offset of STRING2 to DI
MOV CX, 020H Move the length of the strings to CX
CLD Clear the direction flag, set auto-increment mode
REPE CMPSB Compare the 020H bytes of STRING1 and STRING2,While they are Equal,
If mismatch is found modify the flags and proceed with further Execution

NOTE: If Both Strings are Equal,CX becomes ZERO,the ZF is set otherwise ZF is reset

Example of REPNE With SCASW Instruction

MOV AX, SEGMENT_STR      Move the segment address of the String to AX
MOV ES, AX Load it to ES
MOV DI, OFFSET_STR Move the offset of String to DI
MOV CX, 020H Move the length of the String to CX
MOV AL, WORD_TO_FIND The word to be scanned for is loaded into AL
CLD Clear the direction flag
REPNE SCASW Scan the 020H words of the String until a match to the word is found


Example of LODSB Instruction

MOV CX, 10                      Set CX to the number of bytes to be read
MOV SI, OFFSET_STR Set SI to point to the start of the string
MOV DI, OFFSET_BUF Set DI to point to the destination buffer
CLD Clear the direction flag for auto-increment

READ_LOOP:
LODSB Load a byte from the memory location pointed to by SI into AL, and increment SI
STOSB Store the byte in AL at the memory location pointed to by DI, and increment DI
LOOP READ_LOOP Decrement CX and loop back if CX is not zero
HLT Halt the processor (assembly language instruction for stopping execution)


Conclusion

In this Article, We have gone through the String manipulation in the 8086 microprocessor which provides efficiently handling operations on strings of data stored in the memory. These instructions enable us to copying, searching and comparing Function in the memory. Also we have gone through the different examples of the Instructions which provides us the clear understanding of the String manipulation instructions set.

FAQs on String manipulation instructions in 8086 microprocessor

How are string manipulation instructions used in assembly language programming?

In assembly language programming, string manipulation instructions are used to implement various string operations directly at the machine level. Programmers can combine these instructions with control flow structures and other operations to implement complex string manipulation algorithms.

Can string manipulation instructions handle strings of variable length?

Yes, string manipulation instructions are designed to handle strings of variable length.

What are some examples of string manipulation instructions in the 8086 microprocessor?

Examples of string manipulation instructions include MOVSB, CMPSB, SCASB, LODSB, STOSB and other Instructions.



Previous Article
Next Article

Similar Reads

Arithmetic instructions in 8086 microprocessor
Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition, subtraction and a few more. Unlike in 8085 microprocessor, in 8086 microprocessor the destination operand need not be the accumulator. Following is the table showing the list of arithmetic instructions: OPCODE OPERAND EXPLANATION EXAMPLE ADD D,
2 min read
Logical instructions in 8086 microprocessor
Introduction : Logical instructions in the 8086 microprocessor are instructions that perform logical operations on data stored in registers or memory locations. These instructions can manipulate bits within a byte, set or clear individual bits, or perform Boolean operations such as AND, OR, XOR, and NOT. Some of the commonly used logical instructio
5 min read
Data transfer instructions in 8086 microprocessor
Introduction : Data transfer instructions in the 8086 microprocessor are used to move data between memory locations, registers, and input/output (I/O) devices. These instructions are essential for manipulating data within a program, as well as for communicating with external devices. Data transfer instructions are a fundamental part of programming
4 min read
Process control instructions in 8086 microprocessor
Process control instructions are the instructions which control the processor's action by setting(1) or resetting(0) the values of flag registers. Following is the table showing the list of process control instructions: OPCODEOPERANDEXPLANATIONEXAMPLESTCnonesets carry flag to 1STCCLCnoneresets carry flag to 0CLCCMCnonecompliments the carry flagCMCS
1 min read
Program execution transfer instructions in 8086 microprocessor
Prerequisite - Branching instructions in 8085 microprocessor Program execution transfer instructions are similar to branching instructions and refer to the act of switching execution to a different instruction sequence as a result of executing a branch instruction. The two types of program execution transfer instructions are: Unconditional Conditio
3 min read
8086 program to transfer a block of 4 bytes by using string instructions
Problem - Write a program to transfer a block of 4 bytes, starting address is 0500 and transfer the block at address 0600 by using string instructions. Example - Assumptions - Assume that there are 4 blocks in memory addresses 0500, 0501, 0502, 0503. Algorithm – Assign value 500 in SI and 600 in DI Assign the value 0000 H to AX Move the content of
2 min read
Data Manipulation Instructions in Computer Organization
Data Manipulation Instructions Data manipulation instructions perform operations on data and provide computational capabilities for the computer. The data manipulation instructions in a typical computer are usually divided into three basic types as follows. Arithmetic instructionsLogical and bit manipulation instructionsShift instructions Let's dis
3 min read
Arithmetic instructions in 8085 microprocessor
Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition, subtraction and a few more. In 8085 microprocessor, the destination operand is generally the accumulator. Following is the table showing the list of arithmetic instructions: OpcodeOperandExplanationExampleADDRA = A + RADD BADDMA = A + McADD 2050
4 min read
Logical instructions in 8085 microprocessor
Introduction : Logical instructions in the 8085 microprocessor are a set of instructions that perform logical operations on data in registers and memory. Logical operations are operations that manipulate the bits of data without affecting their numerical value. These operations include AND, OR, XOR, and NOT. The logical instructions in the 8085 mic
6 min read
Data transfer instructions in 8085 microprocessor
Data transfer instructions are the instructions that transfer data in the microprocessor. They are also called copy instructions. Here is the following is the table showing the list of logical instructions: OPCODEOPERANDEXPLANATIONNo. of bytesMachine cyclesNo. of T-statesEXAMPLEMOVRd, RsRd = Rs11 opcode fetch4MOV A, BMOVRd, MRd = Mc1 1 opcode fetch
4 min read
Branching instructions in 8085 microprocessor
Branching instructions refer to the act of switching execution to a different instruction sequence as a result of executing a branch instruction. The three types of branching instructions are: Jump (unconditional and conditional) Call (unconditional and conditional) Return (unconditional and conditional) 1. Jump Instructions - The jump instruction
5 min read
Machine Control Instructions in Microprocessor
Introduction Microprocessors are electronic devices that process digital information using instructions stored in memory. Machine control instructions are a type of instruction that control machine functions such as Halt, Interrupt, or do nothing. These instructions alter the different type of operations executed in the processor. In this article,
4 min read
Difference between SIM and RIM instructions in 8085 microprocessor
Introduction : The SIM (Set Interrupt Mask) and RIM (Read Interrupt Mask) instructions are two instructions in the 8085 microprocessor that are used to control interrupts. The SIM instruction allows the microprocessor to selectively enable or disable interrupts by setting the appropriate bits in the Interrupt Mask Register (IMR). The IMR is a regis
3 min read
Arithmetic Instructions in 80386 Microprocessor
A Microprocessor is an important part of a computer architecture without which you will not be able to perform anything on your computer. The 80386 offers a large number of directions that take into consideration more effective and flexible processing. Thus, we should make a plunge and investigate the entrancing universe of math guidelines in the 8
4 min read
Flag register of 8086 microprocessor
Prerequisite – Flag register in 8085 microprocessor The Flag register is a Special Introduction : The flag register is a 16-bit register in the Intel 8086 microprocessor that contains information about the state of the processor after executing an instruction. It is sometimes referred to as the status register because it contains various status fla
6 min read
Reset Accumulator (8085 & 8086 microprocessor)
1. Problem - Write the 8085 instructions which reset the accumulator. Solution - There are 4 instructions to reset the accumulator in 8085. These instructions are: S.No.MNEMONICSCOMMENT1MVI A, 00A <- 002ANI 00A AND 003XRA AA XOR A4SUB AA <- A - A Explanation - MVI A, 00: instruction copies 00 to A.ANI 00: instruction performs bit by bit AND o
4 min read
Memory Segmentation in 8086 Microprocessor
Prerequisite - 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
3 min read
Differences between 8085 and 8086 microprocessor
8085 Microprocessor 8085 Microprocessor is a predecessor of version 8086 Microprocessor, designed by Intel in 1976 with the help of NMOS technology. It includes a data bus of 8 bits, and 16 bits of the address bus, having a +5V voltage supply, and operates at 3.2 MHz single segment CLK. It has an internal clock generator and functions on a clock cy
4 min read
Addressing modes in 8086 microprocessor
Prerequisite - Addressing modes, Addressing modes in 8085 microprocessor The way of specifying data to be operated by an instruction is known as addressing modes. This specifies that the given data is an immediate data or an address. It also specifies whether the given operand is register or register pair. Types of addressing modes: Register mode -
2 min read
Pin diagram of 8086 microprocessor
Pin diagram of 8086 microprocessor is as given below: Intel 8086 is a 16-bit HMOS microprocessor. It is available in 40 pin DIP chip. It uses a 5V DC supply for its operation. The 8086 uses a 20-line address bus. It has a 16-line data bus. The 20 lines of the address bus operate in multiplexed mode. The 16-low order address bus lines have been mult
5 min read
Interrupts in 8086 microprocessor
An interrupt is a condition that halts the microprocessor temporarily to work on a different task and then returns to its previous task. An interrupt is an event or signal that requests the CPU's attention. This halt allows peripheral devices to access the microprocessor. Whenever an interrupt occurs, the processor completes the current instruction
3 min read
Bus Cycles of 8086 Microprocessor
The bus cycle is also named as machine cycle. Bus cycle of 8086 is used to access memory, peripheral devices (Input/Output devices), and Interrupt controller. Bus cycle corresponds to a sequence of events that starts with an address being output on system address bus followed by a write or read data transfer. During these operations, a series of co
2 min read
Auxiliary Carry Flag in 8086 Microprocessor
Auxiliary Carry Flag (AF) is one of the six status flags in the 8086 microprocessor. This flag is used in BCD (Binary-coded Decimal) operations.The status of this flag is updated for every arithmetic or logical operation performed by ALU.This flag is set to one if there is a CARRY from the lower nibble or BORROW for the lower nibble in binary repre
1 min read
Minimum mode configuration of 8086 microprocessor (Min mode)
Overview : The 8086 microprocessor operates in minimum mode when MN/MX' = 1.In minimum mode,8086 is the only processor in the system which provides all the control signals which are needed for memory operations and I/O interfacing.Here the circuit is simple but it does not support multiprocessing.The other components which are transceivers, latches
5 min read
Difference Between Minimum Mode and Maximum Mode in 8086 Microprocessor
Introduction : In the 8086 microprocessor, there are two modes of operation: minimum mode and maximum mode. Minimum mode is used when the 8086 microprocessor is operating as a standalone processor without any external coprocessors or support chips. In this mode, the 8086 uses a single 8-bit bus for both data and instructions, and a single 20-bit ad
3 min read
Immediate Addressing Mode in 8086 Microprocessor
Immediate addressing mode in 8086 microprocessor contains the instruction where the first operand may be a register or memory location and the second operand is an immediate value that represents the operand. In this article, we will explore the immediate addressing mode in detail along with the examples of immediate addressing mode. Also, we will
4 min read
Types of Registers in 8086 Microprocessor
A microprocessor is a register-based clock-driven digital device that is used for data processing. It is a multipurpose device that is capable of producing outputs when provided binary data as input. In computers, the microprocessor is like the brain, handling tasks and calculations. Inside the microprocessor are tiny storage units called registers
7 min read
Maximum mode configuration of 8086 microprocessor (Max mode)
The 8086 microprocessor is an 8-bit/16-bit microprocessor designed by Intel in the late 1970s. It is the first member of the x86 family of microprocessors, which includes many popular CPUs used in personal computers. The architecture of the 8086 microprocessor is based on a complex instruction set computer (CISC) architecture, which means that it s
4 min read
General purpose registers in 8086 microprocessor
It is one of the most important chips ever created due to its part in the development of x86-based architecture. One significant aspect of this microprocessor is that it contains general registers. Efficiency and speed of computations in the processor are influenced by these registers since they determine arithmetic operations execution and data ma
6 min read
8086 program to transfer a block of bytes by using string instruction
Problem: Write an assembly language program to transfer a block of bytes from one memory location to another memory location by using string instruction. Example: Example: In this example, the counter value stored in CX register is 4.The block of data which is stored from memory location starting from 501 to 504 offset is transferred to another mem
3 min read
three90RightbarBannerImg