0% found this document useful (0 votes)
13 views7 pages

Coal - Lab Sol, 4

The document is a laboratory manual for a Computer Organization and Assembly Language course, specifically focusing on displaying strings in assembly language. It outlines lab objectives, software requirements, and detailed instructions on using the .DATA segment, LEA instruction, and INT 21h function for string manipulation. Additionally, it includes tasks for students to implement and demonstrate their understanding of these concepts through coding exercises.

Uploaded by

mnaseerch007
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)
13 views7 pages

Coal - Lab Sol, 4

The document is a laboratory manual for a Computer Organization and Assembly Language course, specifically focusing on displaying strings in assembly language. It outlines lab objectives, software requirements, and detailed instructions on using the .DATA segment, LEA instruction, and INT 21h function for string manipulation. Additionally, it includes tasks for students to implement and demonstrate their understanding of these concepts through coding exercises.

Uploaded by

mnaseerch007
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/ 7

Laboratory Manual

Computer Organization & Assembly


Language-Lab
COSC-3214 Ms. Mubashra Bibi

BS-INFT 4A,4B,4C
Spring Semester 2025
Roll No INFT231102005

Name Kashif nawaz

Class INFT-4C
THE
CONCEPT OF DISPLAYING
STRING IN
ASSEMBLY LANGUAGE

Lab-04

Note:

• Each code Screenshot must Include your name and roll number in comments at the
start
• Carefully read each statement before attempting the tasks.
• To receive full credit, students must attempt all tasks and questions.
• Paste screenshots of both code and output in each task
• Your solution must be properly formatted, easy to read, and comprehensive.
• Plagiarism is strictly prohibited.
• To attempt Lab Task You are only allowed to use the concepts that have been covered
in the Lab Manual.

Lab Objectives:
To understand the concept of displaying string in assembly language
Contents / Sub Contents
Understanding STRING, .DATA Segment, Loading the Data Segment, LEA Instruction, Function 09h
(INT 21h)

Computer Organization & Assembly Language-Lab [COSC-3214] 1


Software
Required
1. EMU 8086

EMU 8086 is an 8086 microprocessor emulator designed for learning and practicing
assembly language programming. It provides an easy-to-use environment for writing,
assembling, debugging, and executing x86 assembly code.

STRING: A string is a list of characters treated as a unit. In programming languages we


denote a string constant by using quotation marks, e.g. “Enter first number”.

In 8086 assembly language, single or double quotes may be used.

.DATA SEGMENT

The .DATA segment is used to define variables and constants that the program will use.

• Stores Variables and Constants: Any string, integer, or array that needs to be
stored is placed in the .DATA section.
• Allows Easy Access to Data: By setting DS (Data Segment Register), the program can
access these values efficiently.
• Required for Programs that Use Static Data: Programs printing strings or using
predefined values must declare them in .DATA.

Syntax for Defining Data Segment

Whenever your Program Contains Data Segment you need to Write these statement in the
Code Segments

1. Load the Data Segment Address into AX

Loads the starting address of the .DATA segment into the Accumulator Register (AX).

2. Move AX into the Data Segment Register (DS)

Computer Organization & Assembly Language-Lab [COSC-3214] 2


Sets the Data Segment Register (DS) so the program can access variables in .DATA.
Why Move @DATA
into AX First Instead
of Directly into DS?
1. Segment Registers (DS, CS, SS, ES) Cannot Be Loaded Directly from Memory

• The 8086 processor does not allow moving an immediate value (such as @DATA)
directly into a segment register (DS, CS, SS, ES).
• This restriction is built into the CPU architecture to ensure memory segmentation
consistency.
• Example of an invalid instruction: MOV DS, @DATA ; This is not allowed in 8086
assembly

2. General-Purpose Registers (AX, BX, CX, DX) Act as Intermediaries

• The only way to load a segment register (DS) is to first store the value in a
generalpurpose register (AX, BX, CX, or DX) and then move it into DS.
• The Accumulator Register (AX) is typically used because it is the fastest and most
commonly used register for such operations.
• Example of a valid method:

MOV AX, @DATA ; Load segment address into AX (allowed)

MOV DS, AX ; Move AX into DS (allowed)

3. Why Not Use DX Instead of AX?

• While DX is also a general-purpose register, AX is preferred for segment loading


because: o Many segment-related instructions and arithmetic operations are
optimized for AX.
o It's a convention followed in most 8086 assembly programming. o
Some instructions (like MOV DS, DX) may not work properly on all
assemblers.

LEA INSTRUCTION

LEA stands for Load Effective Address. It is an instruction used in 8086 assembly language
to load the memory address of a variable into a register.

Purpose of LEA

Computer Organization & Assembly Language-Lab [COSC-3214] 3


It is used to get the offset (memory address) of a variable instead of its actual value.

Syntax:

• destination_register → A general-purpose register (BX, DX, SI, etc.).


• source → A memory variable whose address needs to be loaded.
EXAMPLE

Why Not Use MOV Instead of LEA?

• LEA DX, message → Loads the address of message into DX.


• MOV DX, message → Would try to load the value at message, which may not work
correctly in string printing.

When to Use LEA?


• When you need to pass the address of a variable (e.g., for string printing with INT
21h).
• When working with pointers and memory addresses in assembly.

From Lab Manual No 2: Function

09h (INT 21h):

Purpose: Display a string of characters.

Usage: The string must be terminated with a dollar sign ($) to indicate the end of the string.

mov ah, 09h ; Function 09h (Display string)


lea dx, message ; Load address of string into DX
int 21h ; Interrupt call

; The string must be terminated with '$'

Task no 1: Write a program to display a string(Paste Screenshot of Code & Output)

Computer Organization & Assembly Language-Lab [COSC-3214] 4


Task no 2: Modify the program given in task no 1 what happens if u repeat line no 16
INT 21H 5 times. (Paste Screenshot of Code & Output)

Task no 3: Write an assembly language program that prints two strings using INT 21h,
function 09h. (Paste Screenshot of Code & Output)

Computer Organization & Assembly Language-Lab [COSC-3214] 5


Task no 4: Write an assembly language program that prints two strings using INT 21h,
function 09h. (Paste Screenshot of Code & Output)

The end ☺

Computer Organization & Assembly Language-Lab [COSC-3214] 6

You might also like