C34 Exp3 MP
C34 Exp3 MP
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.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,
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
(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)
(Paste your code completed during the 2 hours of practical in the lab here)
.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
; Exit program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Input:
Ouput:
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.
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
; Exit program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN