You are on page 1of 9

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

A.6 Flowchart:
PART B
(PART B : TO BE COMPLETED BY STUDENTS)

Roll. No A29 Name: Ritik S Vishwakarma

Class: S.E-A Batch-A-2

Date of Experiment: 31-01-2024 Last Date of Submission:06-02-2024

Grade:

B.1 Software Code written by student:


.model small
.stack 100h
.data
array db 100 dup("$")

.code
main proc
mov ax, @data
mov ds, ax
mov bl, 0 ; variable for counting characters in the string
mov SI, offset array ; SI points to the array's first index

L1:
mov ah, 01h ; input the string from the user
int 21h
cmp al, 13 ; ASCII code for Enter
je StringPrint
mov [SI], al ; store the character in the array
inc SI ; increment index value in the array
inc bl ; increment counting variable
jne L1

StringPrint:
mov dl, 0Ah
mov ah, 02h ; to move to the next line (Line Break)
int 21h

mov dl, bl ; load the count into dl


add dl, '0' ; convert the count to ASCII
mov ah, 02h ; print character function
int 21h

mov ah, 4ch


int 21h
main endp
end main

B.2 Input and Output:

TABLE:

Registers

Address Main Code Operand Mnem AX DX BX CX Comments


IP
AH AL DH DL BH BL CH CL

07270 MOV ax ,@data MOV 0000 00 00 00 00 00 00 01 9c Load the data


ax,@data segment
address to AX

07273 MOV ds,ax ds,ax MOV 0003 07 20 00 00 00 00 01 9c Initialize DS


with the data
segment
address

07275 MOV bl,0 Bl,0 MOV 0005 07 20 00 00 00 00 01 9c Variable for


counting
characters in the
string

07277 MOV SI,Offset MOV 0007 07 20 00 00 00 00 01 9c SI points to the


SI,Offset array array's first
array index

0727A MOV ah,01h MOV 000A 07 20 00 00 00 00 01 9c Input a


ah,01h character from
the user
0727C Int 21h 21h Int 000C 01 20 00 00 00 00 01 9c Invoke DOS
interrupt for
various services

0727E Cmp a1,13 a1,13 Cmp 000E 01 73 00 00 00 00 01 9c Check if the


entered
character is
Enter (ASCII
code 13)

07280 Je StringPrint Je 01 73 00 00 00 00 01 9c If Enter, jump


StringPrint to StringPrint

07282 MOV [SI],al MOV 0012 01 73 00 00 00 00 01 9c Store the


[SI],al character in the
array

07284 Inc SI SI Inc 0014 01 73 00 00 00 00 01 9c Increment index


value in the
array

07285 Inc bl bl Inc 0015 01 73 00 00 00 00 01 9c Increment


counting
variable

07287 JNE L1 L1 JNE 0017 01 73 00 00 00 01 01 9c Jump back if


not Enter

07289 MOV dl, dl,0ah MOV 0019 01 0D 00 00 00 08 01 9c Move to the


0ah next line (Line
Break)

0728B MOV dh, dh,02h MOV 001B 01 0D 00 0A 00 08 01 9c Move 02h to


02h DH register

0728D int 21h 21 h Int 001D 02 0D 00 0A 00 08 01 9c DOS function


to print newline

0728F MOV dl, bl dl,bl MOV 001F 02 0A 00 0A 00 08 01 9c Load the count


into dl

07291 ADD dl, '0' dl ADD 0021 02 0A 00 08 00 08 01 9c Convert the


count to ASCII
07294 MOV Ah,2h MOV 0024 02 0A 00 38 00 08 01 9c Print character
ah,2h function

07296 Int 21h 21h Int 0026 02 0A 00 38 00 08 01 9c DOS function


to print the
length of the
string

07298 MOV ah, ah,4ch MOV 0028 02 0A 00 38 00 08 01 9c DOS function


4ch to terminate the
program

0729A Int 21h 21h Int 002A 02 4C 00 38 00 08 01 9c Execute the


interrupt

OUTPUT:
B.3 Observations and learning:
The assembly language program efficiently iterated through the input string, incrementing a
counter until it reached the null terminator, successfully determining the string's length.This
experiment provided valuable insights into low-level programming, emphasizing the significance
of registers, memory management, and control flow instructions in string manipulation using
assembly language.

B.4 Conclusion:

The assembly language program effectively calculates the length of an input string by traversing
characters until the null terminator is encountered. This experiment enhances understanding of
low-level programming, showcasing the efficiency of assembly language in string manipulation.

B.5 Question of Curiosity

1. How does the CPU identify between 8-bit and 16-bit operations?

Ans :

1)Data Bus Width: The data bus is a communication pathway that allows data to be transferred
between the CPU and other components in the computer system, such as memory and
peripherals. The width of the data bus is a crucial factor in determining the size of data that can
be processed in a single operation. If a CPU has an 8-bit data bus, it can process 8 bits of data in
one operation, and if it has a 16-bit data bus, it can process 16 bits at a time.

2)Instruction Set Architecture (ISA): The instruction set architecture of a CPU defines the set of
instructions that the CPU can execute. Instructions are the binary codes that tell the CPU what
operation to perform. Some instructions are designed to operate on 8-bit data, while others are
designed for 16-bit or larger data.

3)Registers: Registers are small, high-speed storage locations within the CPU. They are used to
store data temporarily during processing. The size of the registers often corresponds to the data
bus width. If a CPU has 8-bit registers, it is more suited for 8-bit operations, and if it has 16-bit
registers, it is designed for 16-bit operations.

4)Execution Context: The context in which an instruction is executed also plays a role. For
instance, an instruction might be designed to work with 8-bit data in one context and 16-bit data
in another. The CPU needs to be aware of the context and interpret the instructions accordingly.

2. What is the ASCII value of ‘@’?

Ans :

The ASCII value of the '@' symbol is 64.


3. How to convert BCD to ASCII and ASCII to BCD?

Ans :

BCD to ASCII:
Group BCD Digits:
● Divide the BCD number into groups of four bits per decimal digit.
Convert each BCD Digit to Decimal:
● Convert each group of four bits into its decimal equivalent.
Add ASCII '0':
● Add the ASCII value of '0' to each decimal digit to obtain the ASCII
representation.

ASCII to BCD:

Subtract ASCII '0':


● Subtract the ASCII value of '0' from each digit to get the decimal value.
Convert Decimal to BCD:
● Convert each decimal digit to its corresponding 4-bit BCD representation.

4. What is the difference between packed BCD and unpacked BCD?

Ans :
Packed BCD:

Format: In packed BCD, two decimal digits are stored in a single byte.

● Representation: Each decimal digit is represented by a 4-bit binary code.


● Example: The decimal number 59 would be represented as 0101 1001 in packed
BCD.
Unpacked BCD:

Format: In unpacked BCD, each decimal digit is stored in a separate byte.

● Representation: Each decimal digit is represented by its own 4-bit binary code.
● Example: The decimal number 59 would be represented as 0101 (for 5) and 1001
(for 9) in unpacked BCD.

5. What are the different machine level instruction codes of 8086 μP?

Ans :
Main categories of machine-level instruction codes for the 8086 microprocessor:
Data Transfer Instructions:
● MOV: Move data from source to destination.
Arithmetic Instructions:
● ADD, SUB, MUL, DIV: Addition, subtraction, multiplication, and division
operations.
● INC, DEC: Increment and decrement.
Logical Instructions:
● AND, OR, XOR, NOT: Logical AND, OR, XOR, and NOT operations.
● TEST: Perform bit-wise AND operation.
Control Transfer Instructions:
● JMP: Unconditional jump.
● JE, JNE, JZ, JNZ: Conditional jumps based on various flags (equal, not equal,
zero, not zero).
● CALL, RET: Call a procedure and return from a procedure.
Flag Control Instructions:
● CLC, STC, CMC: Clear carry flag, set carry flag, complement carry flag.
● CLI, STI: Clear and set interrupt enable flag.
String Instructions:
● MOVS, CMPS, SCAS, LODS, STOS: Move string, compare string, scan string,
load string, store string.
Bit Manipulation Instructions:
● SHL, SHR, ROL, ROR: Shift and rotate instructions.
Processor Control Instructions:
● HLT: Halt the processor.
Input/Output Instructions:
● IN, OUT: Input from and output to specified ports.
Segment Register Instructions:
● MOV: Load values into segment registers.

You might also like