0% found this document useful (0 votes)
17 views8 pages

C34 Exp3 MP

The document outlines an assembly language experiment aimed at calculating the length of an input string using BIOS/DOS interrupts on the Intel 8086 processor. It includes prerequisites, expected outcomes, a theoretical background on DOS interrupts, an algorithm for the program, and a sample code. Additionally, it requires students to submit their code, observations, conclusions, and answers to questions related to string operations.
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)
17 views8 pages

C34 Exp3 MP

The document outlines an assembly language experiment aimed at calculating the length of an input string using BIOS/DOS interrupts on the Intel 8086 processor. It includes prerequisites, expected outcomes, a theoretical background on DOS interrupts, an algorithm for the program, and a sample code. Additionally, it requires students to submit their code, observations, conclusions, and answers to questions related to string operations.
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/ 8

PART A

(PART A : TO BE REFFERED BY STUDENTS)

Experiment No.03
A.1 Aim: Write assembly language program to find length of input string. [Use BIOS/DOS
interrupts to read input and display results.]

A.2 Prerequisite: Basic knowledge of DOS/BIOS Interrupts of 8086

A.3 Outcome:
After successful completion of this experiment students will be able to
1. Use appropriate instructions to program microprocessor to perform various
task.
2. Develop the program in assembly/ mixed language for Intel 8086 processor
3. Demonstrate the execution and debugging of assembly/ mixed language program

A.4 Theory
Theory:
The DOS interrupt INT 21H provides a large number of services. A function code has
been allocated to each service provided by INT 21H. The function code should be loaded into
the AH register before calling INT 21H to avail the service provide by the function
INT 21h - The general function dispatcher

Most of the general functions and services offered by DOS are implemented through this
interrupt. The functions available are well standardized and should be common to all MSDOS,
PCDOS and DOS Plus systems. Well behaved programs, therefore, should use these facilities
in preference to any other methods available for the widest range of compatibility.INT 21h in
the 512's implementation of DOS Plus 2.1 provides 77 official functions, two of which are non-
functional and return with no action. Within this range some calls have sub functions which
further extend the range of operations.

In all calls, on entry AH defines the function. Other parameters may also be required in
other registers. Where a memory block is used by the call this is specified in the normal
segment:offset form. In all cases the general programming technique is to set AH to the
function pointer, set up the required register contents (and the memory block if necessary) then
to issue the call by the assembly code INT instruction. To call the recommended program
terminate routine, INT 21h function 4Ch,

Examples of most popular functions can be used here

DOS INT 21H Useful DOS interrupt to input information from the keyboard and display it on
the screen
Function 09 – outputting a string of data to the monitor
AH = 09; function number DX = offset address of the ASCII data to be displayed, data segment
is assumed The ASCII string must end with the dollar sign $
Function 02 – outputting a single character to the monitor
AH = 02; function number DL = ASCII code of the character to be displayed
Function 01 – inputting a single character, with an echo
AH = 01 ; function number After the interrupt AL = ASCII code of the input and is echoed to
the monitor
Function 0A – inputting a string of data from the keyboard
AH = 0A ; function number DX = offset address at which the string of data is stored (buffer
area), data segment is assumed and the string must end with

A.5 Algorithm

1. Defines the memory model


2. Initialize the data segment with variables to store the strings and array, Eg:-msg1 db
“enter your string-$”,msg2 db” length of the sting” and for array eg:-string1 db 50
DUP(“$”)
3. Initialize the code segment
4. Apply the Dos Interrupt with Function 09h to display content on the screen(Eg: Enter
your string)
5. Apply function 0Ah to get the string from key board and 02h for outputting a single
character to the monitor
6. Compare SI with AL(load with 13 ;ascii code for enter that means the end of string)
until JE is zero, if not increment the SI and the string count
7. Store the result and display.
8. Terminate the program
PART B
(PART B : TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded at the end of the practical)

Roll. No:34 Name: Shrinath Babar

Class: SE-C-COMPS Batch:C2


Date of Experiment: Date of Submission:
Grade:

B.1 Software Code written by student:

(Paste your code completed during the 2 hours of practical in the lab here)

ORG 100H ; Start at memory offset 100H

.DATA
BUFFER_SIZE DB 255 ; Max input buffer size
BUFFER DB ? ; Stores actual length of input
STRING DB 255 DUP('$') ; Buffer for storing input string
MSG1 DB 'Enter a string: $' ; Prompt message
MSG2 DB 'Length: $' ; Output message
NEWLINE DB 0DH, 0AH, '$' ; New line characters

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

; Display "Enter a string: "


MOV DX, OFFSET MSG1
MOV AH, 09H
INT 21H

; Read string input


MOV DX, OFFSET BUFFER
MOV AH, 0AH
INT 21H

; Move to a new line


MOV DX, OFFSET NEWLINE
MOV AH, 09H
INT 21H

; Display "Length: "


MOV DX, OFFSET MSG2
MOV AH, 09H
INT 21H

; Get input length


MOV AL, BUFFER+1 ; Actual length of string (excluding Enter key)
AAM ; Convert to ASCII
ADD AX, 3030H ; Convert to ASCII characters

; Display first digit (if any)


MOV DL, AH
CMP DL, '0'
JE SKIP_LEADING_ZERO
MOV AH, 02H
INT 21H
SKIP_LEADING_ZERO:

; Display second digit


MOV DL, AL
MOV AH, 02H
INT 21H

; Move to new line


MOV DX, OFFSET NEWLINE
MOV AH, 09H
INT 21H

; Exit program
MOV AH, 4CH
INT 21H

MAIN ENDP
END MAIN

B.2 Input and Output:

Input:
Ouput:

B.3 Observations and learning:


(Students are expected to comment on the output obtained with clear observations and
learning for each task/ sub part assigned)

Observations:
1. The program correctly displays the string "Rishi" and calculates its length as 5.
2. The loop iterates through each character of the string until the termination
character ('$') is found.
3. String length is stored in the CX register and converted to ASCII for proper
display.
4. The use of DOS interrupts (INT 21H) effectively manages input/output operations.
5. The stack is not required for this program as we process the string in-place.
Learning:
• String operations can be performed using indexed addressing (SI for iteration).
• String termination character ('$') is crucial for output using INT 21H, AH=09H.
• Using looping structures in assembly helps in automating string processing.
• Register-based operations ensure minimal memory usage and faster execution.

B.4 Conclusion:

(Students must write the conclusion as per the attainment of individual outcome listed
above and learning/observation noted in section B.3)

The experiment successfully demonstrated string length calculation in 8086 assembly using
manual character traversal. By implementing string iteration using SI and CX, we
efficiently determined the length without modifying the original string. This program helped
us understand string handling, register-based operations, and DOS interrupt-based
output handling.

B.5 Question of Curiosity

Q1. List and explain any four string operation instruction


MOVS (MOVSB/MOVSW) – Moves a byte (MOVSB) or word (MOVSW) from the
memory location pointed by SI (source index) to the memory location pointed by DI
(destination index). After execution, SI and DI are automatically incremented or decremented
based on the direction flag (DF).
LODS (LODSB/LODSW) – Loads a byte (LODSB) or word (LODSW) from the
memory location pointed by SI into the AL (for byte) or AX (for word) register. SI is
incremented or decremented based on DF.
STOS (STOSB/STOSW) – Stores a byte (STOSB) or word (STOSW) from AL (for byte)
or AX (for word) into the memory location pointed by DI. DI is incremented or decremented
based on DF.
SCAS (SCASB/SCASW) – Compares a byte (SCASB) or word (SCASW) in memory at
DI with AL (for byte) or AX (for word). It updates flags based on the comparison and
increments or decrements DI accordingly.

Q2. Write a assembly language program to transfer a block by using string instructions

ORG 100H
.DATA
SOURCE DB 'HELLO WORLD$', 0 ; Source string
DEST DB 12 DUP('$') ; Destination buffer
MSG1 DB 'Source: $' ; Message for source
MSG2 DB 'Copied: $' ; Message for destination
NEWLINE DB 0DH, 0AH, '$' ; Newline characters

.CODE
MAIN PROC
MOV SI, OFFSET SOURCE ; Load address of source string
MOV DI, OFFSET DEST ; Load address of destination buffer
MOV CX, 11 ; Number of characters to copy ('HELLO WORLD' has 11 chars)
CLD ; Clear direction flag for forward movement

REP MOVSB ; Copy CX bytes from [SI] to [DI]

; Display "Source: "


MOV DX, OFFSET MSG1
MOV AH, 09H
INT 21H

; Display the original string


MOV DX, OFFSET SOURCE
MOV AH, 09H
INT 21H

; Move to a new line


MOV DX, OFFSET NEWLINE
MOV AH, 09H
INT 21H

; Display "Copied: "


MOV DX, OFFSET MSG2
MOV AH, 09H
INT 21H

; Display the copied string


MOV DX, OFFSET DEST
MOV AH, 09H
INT 21H

; Move to new line


MOV DX, OFFSET NEWLINE
MOV AH, 09H
INT 21H

; Exit program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

You might also like