MPL Writeup 2
MPL Writeup 2
MPL Writeup 2
Aim: Write an ALP to program to use GDTR, LDTR and IDTR in Real Mode.
Theory:
Conclusion:-
Thus we have studied ALP program to use GDTR, LDTR and IDTR in Real Mode.
Conclusion:
Thus we have studied X86/64 ALP to perform multiplication of two 8-bit hexadecimal
numbers. Use addand shift method. Accept input from the user.
Aim: Write X 86 Menus 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.
8.1 Software/Hardware Required:
Core 2 duo/i3/i5/i7 - 64bit processor Operating System – ubuntu/Fedora 64bit OS Assembler: NASM
Editor Used – gedit
8.2 THEORY:
Basics of Disk Operating System
An operating system (OS) is the software that controls a computer's hardware and peripheral devices and
allows other programs to function. Early computers did not have disk drives but were hard-wired to carry
out specific computations. Later, computers were able to store instructions loaded into the computer's
memory using punch cards and later magnetic tapes. Computer memory space was limited and when the
instructions to control a computer were moved onto a disk drive, such as a floppy disk or internal hard
drive, it was considered cutting-edge technology. Today, any modern operating system would be
considered a disk operating system. Convert command into Computer actions
The structure of DOS
- The BIOS (Basic Input/Output System)
- The DOS kernel
- The command processor (shell)
MS-DOS Kernel
The kernel provides a collection of hardware-independent services called system functions.
- File Management
- Memory Management
- Device Input and Output
- Process control
@ The kernel is a proprietary program and provides a collection of hardware-independent services called
system functions.
@ These functions include the following:
◦ File and record management
◦ Memory management
◦ Character-device input/output
◦ spawning of other programs
◦ Access to the real-time clock
@ External commands
@ Batch files
1. TYPE COMMAND
Type: Internal
Syntax: TYPE [d:][path]filename Purpose: Displays the contents of a file.
Discussion when you use the TYPE command, the file is displayed with limited on-screen formatting. Tabs
are expanded and generally displayed as eight spaces wide. If you display files that contain special (non-
text) characters, these characters may have unpredictable effects on your dispaly. Wild card characters (?
and *) cannot be used with this command in either the filename or the extension.
2. COPY COMMAND
Type: Internal
Syntax:
COPY [/Y|-Y] [/A][/B] [d:][path]filename [/A][/B] [d:][path][filename] [/V]
or
COPY [/Y|-Y] [/A][/B] [d:][path]filename+[d:][path]filename[...] [d:][path][filename] [/V] Purpose: Copies or
appends files. Files can be copied with the same name or with a new name.
Discussion: COPY is usually used to copy one or more files from one location to another. However, COPY
can also be used to create new files. By copying from the keyboard console (COPY CON:) to the screen, files
can be created and then saved to disk. The first filename you enter is referred to as the source file. The
second filename you enter is referred to as the target file. If errors are encountered during the copying
process, the COPY program will display error messages using these names. Unlike the BACKUP command,
copied files are stored in the same format they are found in. The copied files can be used just as you would
use the original (whether the copied file is a data file or a program). COPY can also be used to transfer data
between any of the system devices. Files may also be combined during the copy process.
3. DELETE COMMAND
Type: Internal
Syntax: DEL (ERASE) [d:][path]filename [/P]
Purpose: Deletes (erases) files from disk.
Conclusion:
Thus we have studied X 86 Menus driven Assembly Language Program (ALP) to implement
OS (DOS) commands TYPE, COPY and DELETE using file operations. User is supposed to provide
command linearguments in all cases.
Theory:
Near Procedure: Far Procedure Explanation:
Open given text file. Read the content of file and store it in a buffer. Call far procedure which will calculate
the number of blank spaces, lines and occurrence of a particular character from the buffer.
Assembler Directives Used: (Explain it by your own)
• Extern:
• Global:
Main Algorithm:
A1: Algorithm for program_1
i. Start
ii. Initialize all the sections needed in programming
iii. Display “Enter file name” message using Print macro expansion
iv. Accept file name using Accept macro and store in filename buffer
v. Display “Enter character to search” message with the expansion of Print macro
vi. Read character using Accept macro expansion
vii. Open file using fopen macro
viii. Compare RAX with -1H if equal then display error message “Error in Opening File” with Print macro
expansion else go to step ix ix. Read content of opened file in buffer
x. Store file length in abuf_len
xi. Call far_procedure
xii. Stop
Macro 3
1. Name: fopen
2. Purpose: to open a file in given mode
3. I/P: sys_write call Number i.e rax=2, File name in rdi, Mode of file in rsi
(R=0, W=1, RW=2), and file permission in rdx. Then Call syscall.
Macro 4
1. Name: fread
2. Purpose: to read the content of file
3. I/P: sys_read call Number i.e rax=0, File descriptor in rdi , Buffer Address in rsi, and length of Buffer in
rdx. Then Call syscall.
Macro 5
3. Name: fclose
4. Purpose: to close opened file
5. I/P: sys_read call Number i.e rax=3, File handler in rdi. Then Call syscall.
Procedure: 1
1. Name: far procedure
2. Purpose: to count 1. Number of Blank spaces 2. Number of lines 3. Occurrence of a particular character.
3. I/P: Content stored in buffer
4. Algorithm for Procedures
i. Start
ii. Load effective address of buffer in RSI
iii. Load content of abuf_len in RCX
iv. Load content of char in BL
v. Move value of RSI in AL
vi. Compare AL with 20H (ASCII value of space) if not equal then go to step
vii else increment content of scount
Conclusions:
Thus we have studied 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.
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.[2] 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 Start
i. Start
ii. Initialize all the sections needed in programming
iii. Display “Enter file name” message using Print macro expansion iv. Accept file name using
Accept macro and store in filename buffer
vi. Read character using Accept macro expansion
vii. Open file using fopen macro
viii. Compare RAX with -1H if equal then display error message “Error in
Opening File” with Print macro expansion else go to step ix
ix. Read content of opened file in buffer
x. Store file length in abuf_len
xi. Call Buff_array
xii. Stop
Algorithm 02
1) Initialize pointer ESI to file buffer
2) Initialize pointer EDI to array buffer
3) Initialize counter to some register
4) Read the Element From file one by one and store it into buffer
5) Increment ESI by 002 so point to next element
6) Increment edi by 01 to buffer
7) Check whether count=0 yes stop otherwise repeat the steps go to step 01
8) Stop
Conclusion:
Thus we have studied X86 program to sort the list of integers in ascending/descending
order. Readthe input from the text file and write the sorted data back to the same text file using
bubble sort