Professional Documents
Culture Documents
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
A.6 Flowchart:
PART B
(PART B : TO BE COMPLETED BY STUDENTS)
Grade:
.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
TABLE:
Registers
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.
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.
Ans :
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:
Ans :
Packed BCD:
Format: In packed BCD, two decimal digits are stored in a single 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.