0% found this document useful (0 votes)
67 views4 pages

Experiment 6

This document describes string manipulation instructions in assembly language. It explains instructions like LODSB, MOVSB, STOSB, CMPSB, and SCASB that are used to load, store, compare and scan bytes within strings. These instructions allow efficient string operations by loading/storing bytes from memory to registers, comparing string bytes, and scanning strings. Code examples are provided to demonstrate the use of each instruction.

Uploaded by

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

Experiment 6

This document describes string manipulation instructions in assembly language. It explains instructions like LODSB, MOVSB, STOSB, CMPSB, and SCASB that are used to load, store, compare and scan bytes within strings. These instructions allow efficient string operations by loading/storing bytes from memory to registers, comparing string bytes, and scanning strings. Code examples are provided to demonstrate the use of each instruction.

Uploaded by

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

Heaven’s Light is Our Guide

Rajshahi University of Engineering & Technology

Department of Electrical & Electronic Engineering

: Microprocessor, Interfacing and System design


Course Title Sessional

Course No : EEE 3210


Experiment No : 06
Name of the Experiment : Instructions working on strings in Assembly
Programming Language.

Date of Experiment : 05 November, 2023


Date of Submission : 29 November, 2023

Submitted by Submitted to

Name : Zahid Hossain Belal Hossain

Roll : 1901145 Assistant Professor

Section : C Department of EEE

Session : 2019-20 RUET


Experiment No: 06
Experiment Name: Instructions working on strings in Assembly Programming
Language.
Objectives:
1. To know the operations of instructions working on string.
Theory:
The assembly language instructions LODSB, MOVSB, STOSB, CMPSB, and SCASB
are string manipulation instructions used for loading, storing, comparing, and scanning
strings. Here's a brief explanation of each:
1. LODSB (Load String Byte):
•Purpose: Loads a byte from the memory location addressed by DS:SI into the
AL register.
• Increment/Decrement: Increments or decrements the SI register based on the
direction flag (DF).
• Common Use: Often used to iterate through a source string.
2. MOVSB (Move String Byte):
• Purpose: Moves the byte in the AL register to the memory location addressed
by ES:DI.
• Increment/Decrement: Increments or decrements both the SI and DI registers
based on the direction flag (DF).
• Common Use: Used for copying bytes from one string to another.
3. STOSB (Store String Byte):
• Purpose: Stores the byte in the AL register at the memory location addressed
by ES:DI.
• Increment/Decrement: Increments or decrements the DI register based on the
direction flag (DF).
• Common Use: Used for writing bytes into a destination string.
4. CMPSB (Compare String Byte):
• Purpose: Compares the byte at the memory location addressed by DS:SI with
the byte at the memory location addressed by ES:DI.
• Increment/Decrement: Increments or decrements both the SI and DI registers
based on the direction flag (DF).
• Common Use: Used for comparing bytes in two strings.
5. SCASB (Scan String Byte):
• Purpose: Compares the byte in the AL register with the byte at the memory
location addressed by ES:DI.
• Increment/Decrement: Increments or decrements the DI register based on the
direction flag (DF).
• Common Use: Used for searching for a specific byte in a string.
These instructions are fundamental for string manipulation in assembly language. They
allow for efficient loading, storing, comparing, and scanning of bytes within strings.
The direction flag (DF) plays a crucial role in determining whether the indices (SI and
DI) should be incremented or decremented during these operations.
Codes and Outputs:
LODSB:

.MODEL SMALL
.DATA
.CODE
MOV AX,@DATA
MOV DS,AX
MOV ES,AX
MOV AH,0H
MOV [BX],'A'
MOV DI,BX
LODSB

STOSB:

.MODEL SMALL
.DATA
.CODE
MOV AX,@DATA
MOV ES,AX
MOV DI,0H
MOV AL,'A'
STOSB

MOVSB:

.MODEL SMALL
.DATA
STR1 DB 'AB'
STR2 DB 2 DUP (?)
.CODE
MOV AX,@DATA
MOV ES,AX
MOV DS,AX
LEA SI,STR1
LEA DI,STR2
CLD
MOVSB
MOVSB
CMPSB:

.MODEL SMALL
.DATA
STR1 DB 'AB'
STR2 DB 'AD'
.CODE
MOV AX,@DATA
MOV ES,AX
MOV DS,AX
LEA SI,STR1
LEA DI,STR2
CLD
CMPSB
CMPSB

SCASB:
.MODEL SMALL
.DATA
STR1 DB 'ABC'
.CODE
MOV AX,@DATA
MOV ES,AX
LEA DI,STR1
MOV AL,'A'
CLD
SCASB
SCASB
HLT

Discussion & Conclusion: The assembly instructions movsb, lodsb, stosb, cmpsb, and
scasb play essential roles in byte-level operations. movsb facilitates the transfer of a
byte from the source address to the destination address, incrementing both pointers in
the process. Conversely, lodsb loads a byte from the source address into the AL register,
advancing the source address. stosb stores the byte in the AL register at the destination
address while incrementing the destination pointer. The cmpsb instruction compares the
byte at the source address with the byte at the destination address, updating flags
accordingly. Finally, scasb compares the byte in the AL register with the byte at the
destination address, updating flags and advancing the destination address.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy