MP Lab Manual
MP Lab Manual
MP Lab Manual
1 Write X86/64 ALP to count number of positive and negative numbers from the array
2 Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without string
specific instructions). Block containing data can be defined in the data segment.
3 Write 64 bit ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit BCD
number into its equivalent HEX number. Make your program user friendly to accept the choice from
user for:
(a) HEX to BCD b) BCD to HEX (c) EXIT.
Display proper strings to prompt the user while accepting the input and displaying the result. (use of 64-
bit registers is expected)
4 Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. Use successive
addition and add and shift method. (use of 64-bit registers is expected)
5 Write X86 ALP to find, a) Number of Blank spaces b) Number of lines c) Occurrence of a particular
character. Accept the data from the text file. The text file has to be accessed during Program_1
execution and write FAR PROCEDURES in Program_2 for the rest of the processing. Use of PUBLIC
and EXTERN directives is mandatory.
6 Write X86/64 ALP to switch from real mode to protected mode and display the values of GDTR,
LDTR, IDTR, TR and MSW Registers.
7 Write X86 program to sort the list of integers in ascending/descending order. Read the input from the
text file and write the sorted data back to the same text file using bubble sort
8 Write X86menu driven Assembly Language Program (ALP) to implement OS (DOS) commands TYPE,
COPY and DELETE using file operations. User is supposed to provide command line arguments in all
cases.
9 Write x86 ALP to find the factorial of a given integer number on a command line by using recursion.
Explicit stack manipulation is expected in the code.
10 Write 80387 ALP to find the roots of the quadratic equation. All the possible cases must be considered
in calculating the roots.
11 Write 80387 ALP to plot Sine Wave, Cosine Wave and Sinc function. Access video memory directly
for plotting.
12 Write a Terminate but Stay Resident (TSR) program for a key-logger. The key-presses during the
stipulated time need to be displayed at the center of the screen. OR
Write a TSR to generate the pattern of the frequency tones by reading the Real Time Clock (RTC). The
duration of the each tone is solely decided by the programmer.
Aim Write an ALP to count no. of positive & negative numbers from the array.
Theory:
If the MSB bit of the number is 0, then it is a positive number else if it is 1, then it is negative
number.
EBX represent file descriptor: 0- Standard Input device. 1- Standard Output device. 2- Standard
Error.
BT: BIT TEST: BT saves the value of the bit indicated by the base (first operand) and the bit
offset (second operand) into the carry flag.
JNC checks the contents of a result of BT instruction. If carry is generated then execute the next
instruction otherwise make a jump on a label mentioned with JNC instruction.
Algorithm:
1) In initialized data segment, declare the variables to display the messages on the standard
output device. Declare the array of 7 elements, Declare arrcnt& equate it with no. of
elements in array. Declare the variable pcnt to hold the count of positive numbers &ncnt
3) Define the macro print with 2 parameters. Call interrupt 80h with function EAX = 4 &
EBX as file descriptor 1for standard output device.
4) In Code Segment display the message “Welcome to count +ve& -ve numbers in the array”
7) Use BT instruction to check the word pointed by ESI with bit 15 to check whether carry
generated.
10) Increment the ESI twice so that ESI can point to the next number in the array.
11) Repeat the steps 7,8,9,10 till all the elements are identified as either positive or negative
number of the array.
13) Move the value of pcnt into bl register & call the procedure disp8num.
15) Move the value of ncnt into bl register & call the procedure disp8num.
FAQ:
Aim: Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and
without string specific instructions). Block containing data can be defined in the data segment
Theory:
All members of the 80x86family support five different string instructions: movs,
cmps, scas, lods, and stos. They are the string primitives since you can build most other
string operations from these five instructions. How you use these five instructions is the
topic of the next several sections This sequence of instructions treats CharArray1 and
CharArray2 as a pair of 384 byte strings. However, the last 383 bytes in the CharArray1
array overlap the first 383 bytes in theCharArray2 array. Let's trace the operation of this
code byte by byte. When the CPU executes the MOVSB instruction, it copies the byte at
ESI (CharArray1) to the byte pointed at by EDI (CharArray2). Then it increments ESI
and EDI, decrements ECX by one, and repeats this process. Now the ESI register points
at CharArray1+1 (which is the address of CharArray2) and the EDI register points at
CharArray2+1. The MOVSB instruction copies the byte pointed at by ESI to the byte
pointed at by EDI. However, this is the byte originally copied from location CharArray1.
So the MOVSB instruction copies the value originally in location CharArray1 to both
locations CharArray2 and CharArray2+1. Again, the CPU increments ESI and EDI,
decrements ECX, and repeats this operation. Now the
movsb instruction copies the byte from location CharArray1+2 (CharArray2+1) to
location CharArray2+2. But once again, this is the value that originally appeared in
location CharArray1. Each repetition of the loop copies the next element in CharArray1
[0] to the next available location in the C charArray2 array. Pictorially, it looks
something like that shown in figure.
The end result is that the MOVSB instruction replicates X throughout the string.
The MOVSB instruction copies the source operand into the memory location which will
If the two strings do not overlap, then you can use either technique to move the strings around in
memory. Generally, operating with the direction flag clear is the easiest, so that makes the most
sense in this case.
You shouldn't use the MOVSx instruction to fill an array with a single byte, word, or double
word value. Another string instruction, STOS, is much better for this purpose. However, for
arrays whose elements are larger than four bytes, you can use the MOVS instruction to initialize
the entire array to the content of the first element.
Conclusion:
Questions:
Aim: Write 64 bit ALP to convert 4-digit Hex number into its equivalent BCD number and 5-
digit BCD number into its equivalent HEX number. Make your program user friendly to accept
the choice from user for: (a) HEX to BCD b) BCD to HEX (c) EXIT. Display proper strings to
prompt the user while accepting the input and displaying the result. (use of 64-bit registers is
expected)
Theory:
We are given a five digit BCD number whose HEX equivalent is to be found i.e. 65535 whose
HEX equivalent is to be found. First we will find the Hex equivalent of 60,000. We will compare
60,000H with 10,000H. Each time we compare a counter is decremented by 10,000 and we add
10,000 decimal (2710 Hex). Then we will find the equivalent of 5000. Now we will compare
5000H with 1000H. Each time we compare the counter decrements by 1000 and we add 1000
decimal (3E8 H). Then we find the equivalent of 500H by comparing it with 100H. Each time
counter decrements by 100 and we add decimal 100 (64 H). Then we find equivalent of 30H by
Comparing it with 10H. Each time counter decrements by 10 and we add 10 decimal (0A H).
Then, equivalent of 5 is 5H. Finally, all the equivalents obtained are added to get the equivalent
of 65535
We have a 4 digit Hex number whose equivalent binary number is to be found i.e. FFFF H.
Initially we compare FFFF H with decimal 10000 ( 2710 H in Hex ). If number is greater than
10,000 we add it to DH register. Also, we subtract decimal 10,000 from FFFF H, each time
comparison is made. Then we compare the number obtained in AX by 1000 decimal. Each time
we subtract 1000 decimal from AX and add 1000 decimal to BX. Then we compare number
obtained in AX by 100 decimals. Each time we subtract 100 decimal from AX and add 100
decimal to BX to obtain BCD equivalent. Then we compare number obtained in AX with 10
decimal. Each time we subtract 10 decimal from AX and we add 10 decimal to BX. Finally we
add the result in BX with remainder in AX. The final result is present in register DH with
contains the 5th bit if present and register AX.
Conclusion:
FAQ:
Aim:-Write an 8086 assembly language program to perform the multiplication of two 8 bit Hex
numbers by
1) Successive Addition
2) Shift & Add Method
Objectives:
1. To study basics of assembly language programming i.e. Software commands to use them,
format of alp, assembler directives.
2. To study step in assembly language programming.
3. To study DOS-DEBUG to execute program and to check the results.
4. To study basic 8086 instructions & an interrupt instruction
1. segment
2. ends
3. macro & endm
4. proc & endp
1. Start
2. Physical initialization of data segment
3. Display the following menu for user :-
Conclusion:
Questions:
1. Explain Logic for the program
2. Explain Successive addition process
3. Explain Shift & rotate method.
Prerequisites:
1. Basic knowledge about String operations
2. Knowledge about procedure in ALP
Objectives:
1. To study basics of assembly language programming i.e. Software development alp, assembler
directives.
2. To study step in assembly language programming.
3. To study dos-debug to execute program and to check the results.
4. To study basic 8086 instructions & interrupt instruction
Theory:
Far CALL and RET Operation
When executing a far call, the processor performs these actions
1. Pushes current value of the CS register on the stack.
2. Pushes the current value of the EIP register on the stack.
3. Loads the segment selector of the segment that contains the called procedure in the CS
register.
4. Loads the offset of the called procedure in the EIP register.
5. Begins execution of the called procedure.
When executing a far return, the processor does the following:
1. Pops the top-of-stack value (the return instruction pointer) into the EIP register.
2. Pops the top-of-stack value (the segment selector for the code segment being returned to) into
the CS register.
3. (If the RET instruction has an optional n argument.) Increments pointer by the number of
bytes specified with the n operand to release parameters from the stack.
4. Resumes execution of the calling procedure.
FAQ:
Q. 1 Explain which instructions are used for string operations in
ALP
Q.2 Explain logic for the program.
Q.3 Explain What is the Procedure in ALP
Q.4 Explain FAR procedure.
Q.5 Which interrupts are used in the program.
Aim:- Write X86/64 ALP to switch from real mode to protected mode and display the values of
GDTR, LDTR, IDTR, TR and MSW Registers.
Theory:-
Computer
Department,
NBNSSOE, Pune.
Instruction Description Mode
LGDT S:- Load the global descriptor table register. S specifies both the memory location that
contains the first byte of the 6 bytes to be loaded into the GDTR.
SGDT D:- Store the global descriptor table register. D specifies both the memory location that
gets the first of the six bytes to be stored from the GDTR.
LIDT S: - Load the interrupt descriptor table register. S specifies both the memory location that
contains the first byte of the 6 bytes to be loaded into the IDTR.
SIDT D:- Store the interrupt descriptor table register. D specifies both the memory location that
gets the first of the six bytes to be stored from the IDTR.
Algorithm:
1) Start
2) Variable declaration in data section with initialization
3) Variable bss. section without initialization
4) Macro definition for display msg on screen
5) Read CRo
6) If PE beat =1
7) Store contains of GDT
8) Store contains of LDT
9) Store contains of IDT
10) Store contains of TR
11) Call display processor to display control of GDT
12) Call display processor to display contain of LDT
13) Call display processor to display contain of IDT
14) Call display processor to display control of TR
15) Call display processor to display control of MSW
Conclusion:
FAQ:
Aim: - Write X86 programs to sort the list of integers in ascending/descending order. Read the
input from the text file and write the sorted data back to the same text file using bubble sort.
Theory:-
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly
steps through the list to be sorted, compares each pair of adjacent items and swaps them if they
are in the wrong order. The pass through the list is repeated until no swaps are needed, which
indicates that the list is sorted. The algorithm, which is a comparison sort, is named for the way
smaller or larger elements "bubble" to the top of the list. Although the algorithm is simple, it is
too slow and impractical for most problems even when compared to insertion sort.[1] It can be
practical if the input is usually in sorted order but may occasionally have some out-of-order
elements nearly in position.
Algorithm
1. Compare each pair of adjacent elements from the beginning of an array and, if they are in
reversed order, swap them.
2. If at least one swap has been done, repeat step 1.
you can imagine that on every step big bubbles float to the surface and stay there. At
the step, when no bubble moves, sorting stops
Conclusion:
FAQ:-
Aim:- Write X86menu driven Assembly Language Program (ALP) to implement OS (DOS)
commands TYPE, COPY and DELETE using file operations. User is supposed to provide
command line arguments in all cases.
Theory:-
• OPEN File
mov rax, 2 ; 'open' syscall
mov rdi, fname1 ; file name
mov rsi, 0 ;
mov rdx, 0777 ; permissions set
Syscall
mov [fd_in], rax
• READ File
mov rax, 0 ; „Read' syscall
mov rdi, [fd_in] ; file Pointer
mov rsi, Buffer ; Buffer for read
mov rdx, length ; len of data want to read
Syscall
• WRITE File
mov rax, 01 ; „Write' syscall
mov rdi, [fd_in] ; file Pointer
mov rsi, Buffer ; Buffer for write
mov rdx, length ; len of data want to read
Syscall
• DELETE File
mov rax,87
• CLOSE File
mov rax,3
mov rdi,[fd_in]
syscall
TYPE Command:-
• Open file in read mode using open interrupt.
• Read contents of file using read interrupt.
• Display contents of file using write interrupt.
• Close file using close interrupt
•
COPY Command
DELETE Command
1. DELETE file using delete interrupt
Algorithm
Conclusion:
FAQ:-
1. Why we use TYPE command?
2. Why we use COPY command?
3. Why we use DEL command?
Aim:- Write x86 ALP to find the factorial of a given integer number on a command line by using
recursion. Explicit stack manipulation is expected in the code.
Theory:-
Algorithm
1.Accept Number from User
2.Call Factorial Procedure
3.Define Recursive Factorial Procedure
4.Disply Result.
Conclusion:
FAQ:-
1. What are the applications of factorial?
2. Why to use factorial?
Computer Department, NBNSSOE, Pune.
Assignment No – 10
Aim:- Write 80387 ALP to find the roots of the quadratic equation. All the possible cases
must be considered in calculating the roots.
Theory:-
Prerequisites:
Knowledge about coprocessor
Objectives:
1. To study basics of assembly language programming i.e. Software development
tools required commands to use them, format of alp, assembler directives.
2. To study step in assembly language programming.
3. To study DOS-DEBUG to execute program and to check the results.
4. To study basic 8086 instructions & an interrupt instruction & addressing modes
Theory:
1.a) Features of 80387:
Fabricated using HMOS III technology and packaged in a 40-pin cerdip package,
68- instructions,
Instruction set includes both simple and complex floating point instructions,
By interfacing 8087 NDP with 80386 processor, programmer can perform various
powerful arithmetic floating point operations. e.g. add, sub, div, square root, logarithm
etc.,
80387 support 7 data types: 16-, 32-, 64-bit integers, 32-, 64-, 80-bit floating point and
18-Digit BCD operands,
Having 8 X 80 bit individually addressable register stack
Available in
5MHz (80387),
8MHz (80387-2) and
10MHz (80387-1),
7- built-in exception handling functions
Compatible with IEEE floating point standard 754,
The data information inside 8087 is always stored in temporary real format (80-bit
floating point representation)
Use of 80387 in 80386 system increases processing speed to perform different
mathematical operations required in CAM, numeric controllers, CAD or Graphics,
Conclusion:
FAQ:-
Aim:- Write 80387 ALP to plot Sine Wave, Cosine Wave and Sinc function. Access video
memory directly for plotting.
• Theory:- The overall display characteristics, such as vertical and horizontal resolution,
background color, and palette, are controlled by values written to I/O ports whose
addresses are hardwired on the adapter,
• whereas the appearance of each individual character or graphics pixel on the display is
controlled by a specific location within an area of memory called the regen buffer or
refresh buffer.
• Both the CPU and the video controller access this memory;
• The software updates the display by simply writing character codes or bit patterns
directly into the regen buffer. (This is called memory-mapped I/O.)
Text Mode
offset = (y*80 + x) *2
Graphics Mode
• More complicated
• Each bit or group of bits in regen buffer corresponds to an addressable point or pixel on
the screen
Sine Wave
Cosine Wave
Sinc function
Conclusion:
FAQ:-
Aim:- Write a Terminate but Stay Resident (TSR) program for a key-logger. The key-
presses during the stipulated time need to be displayed at the center of the screen
Theory:-
Most MS-DOS applications are transient. They load into memory,execute, terminate, and
DOS uses the memory allocated to the application for the next program the user executes.
Resident programs follow these same rules, except for the last. A resident program, upon
termination, does not return all memory back to DOS. Instead, a portion of the program remains
resident, ready to be reactivated by some other program at a future time. Resident programs, also
known as terminate and stay resident programs or TSRs, provide a tiny amount of multitasking
to an otherwise single tasking operating system. Until Microsoft Windows became
popular, resident programs were the most popular way to allow multiple applications to coexist
in memory at one time. Although Windows has diminished the need for TSRs for background
processing, TSRs are still valuable for writing device drivers, antiviral tools, and program
patches
INSTALLING A TSR
Although we‟ve already discussed how to make a program go resident, there are a few aspects to
installing a TSR that we need to address. First, what happens if a user installs a TSR and then
tries to install it a second time without first removing the one that is already resident? Second,
how can we assign a TSR identification number that won‟t conflict with a TSR that is already
installed? This section will address these issues. The first problem to address is an attempt to
reinstall a TSR program. Although one could imagine a type of TSR that allows multiple copies
of itself in memory at one time, such TSRs are few and far in-between. In most cases, having
multiple copies of a TSR in memory will, at best, waste memory and, at worst, crash the system.
Therefore, unless you are specifically written a TSR that allows multiple copies of itself in
memory at one time, you should check to see if the TSR is installed before actually installing it.
This code is identical to the code an application would use to see if the TSR is installed, the only
difference is that the TSR should print a nasty message and refuse to go TSR if it finds a copy of
itself already installed in memory
REMOVING A TSR
Removing a TSR is quite a bit more difficult that installing one. There are three things the
removal code must do in order to properly remove a TSR from memory: first, it needs to stop
any pending activities (e.g., the TSR may have some flags set to start some activity at a future
time); second it needs to restore all interrupt vectors to their former values; third, it needs to
return all reserved memory back to DOS so other applications can make use of it. The primary
difficulty with these three activities is that it is not always possible to properly restore the
interrupt vectors. If your TSR removal code simply restores the old interrupt vector values, you
may
1. The timer interrupt TYPE 8 is initiated by the system 18.2 times per
second. Using this information, For 5 Seconds Can Be Calculated as:
18.2*5 =91
2. The video RAM is distributed in 4 pages of size 2K bytes. The
base address of each is
Page0 – B800H
Page1 – b900h
Algorithm
1. INIT ROUTINE
a. Read vector for interrupt (Type 9) from IVT.
b. Save the vector (CS:IP) in memory variable OLDINT9
c. Write BASE:OFFSET of “keyboard ISR” for “TYPE 9”
entry in IVT.
d. Read vector for interrupt (Type 8) from IVT.
e. Save the vector (CS:IP) in memory variable OLDINT8
f. Write BASE:OFFSET of “TIMER ISR” for “TYPE 8”
entry in IVT.
g. Instruct DOS to make the ISR part of the resident in
memory.
2. Keyboard ISR:
a. Push all registers
Conclusion:
FAQ:-