MP Pragati
MP Pragati
ASSIGNMENT NUMBER: 4
ASSINGMENT NO. 4
TITLE Menu driven basic arithmetic operations
PROBLEM STATEMENT Write a switch case driven X86/64 ALP to perform 64-bit hexadecimal
/DEFINITION arithmetic operations (+,-,*, /) using suitable macros. Define procedure
for each operation
OBJECTIVE
Debugger- GDB/TD
REFERENCES 1. “Microprocessor and Interfacing Techniques”, Douglas
Hall
2. “IBM PC Assembly language and programming”, Peter
Able
3. INTEL 80386 PROGRAMMER'S REFERENCE MANUAL
1986
1. Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3. Problem definition
4. Learning objective
5. Learning Outcome
6. Concepts related Theory
7. Algorithm
8. Test cases
10. Conclusion/Analysis
Prerequisites’
Concepts related Theory:
Procedure and Call
Procedure
A called procedure (or subroutine) is a section of code that perform a clearly defined task. A code block
may contain any number of procedures. Procedures or subroutines are very important in assembly
language, as the assembly language programs tend to be large in size. Procedures are identified by a
name. Following this name, the body of the procedure is described which performs a well-defined job.
End of the procedure is indicated by a return statement.
Syntax
Following is the syntax to define a procedure –
Proc_name : Procedure body … ret
The procedure is called from another function by using the CALL instruction. The CALL instruction
should have the name of the called procedure as an argument as shown below − CALL proc_name
The called procedure returns the control to the calling procedure by using the RET instruction
Call and ret The CALL instruction is to transfer control to a called procedure (subroutine). The RET instruction
is to return from the called procedure (subroutine) to the original calling procedure. It effects the counterpart of
CALL. Assembly Language allows us to perform basic unsigned integer arithmetic operations. These operations
are:
1. Addition (add)
2. Subtraction (sub)
3. Multiplication (mul)
4. Division (div)
5. 1. Arithmetic Instructions
6. Addition
7. ADD destination, source
8. ADD (Add Integers) replaces the destination operand with the sum of the source and destination
operands. Sets CF if overflow.ADD performs an integer addition of the two operands (DEST and SRC).
The result of the addition is assigned to the first operand (DEST), and the flags are set accordingly.When
an immediate byte is added to a word or doubleword operand, the immediate value is sign-extended to
the size of the word or doubleword operand.
Flags Affected
OF, SF, ZF, AF, CF, and PF
Subtraction SUB destination, source SUB (Subtract Integers) subtracts the source operand from the
destination operand and replaces the destination operand with the result. If a borrow is required, the CF is
set. The operands may be signed or unsigned bytes, words, or doublewords. SUB subtracts the second
operand (SRC) from the first operand (DEST). The first operand is assigned the result of the subtraction,
and the flags are set accordingly. When an immediate byte value is subtracted from a word operand, the
immediate value is first sign- extended to the size of the destination operand.
Flags Affected
OF, SF, ZF, AF, PF, and CF
Multiplication The 80386 has separate multiply instructions for unsigned and signed operands. MUL operates
on unsigned numbers, while IMUL operates on signed integers as well as unsigned. MUL performs unsigned
multiplication. Its actions depend on the size of its operand, as follows: ● A byte operand is multiplied by AL;
the result is left in AX. The carry and overflow flags are set to 0 if AH is 0; otherwise, they are set to 1.
● A word operand is multiplied by AX; the result is left in DX:AX. DX contains the high-order 16 bits
of the product. The carry and overflow flags are set to 0 if DX is 0; otherwise, they are set to 1. ● A
doubleword operand is multiplied by EAX and the result is left in EDX:EAX. EDX contains the high-
order 32 bits of the product. The carry and overflow flags are set to 0 if EDX is 0; otherwise, they are
set to 1. Flags Affected
OF and CF
Division The 80386 has separate division instructions for unsigned and signed operands. DIV operates on
unsigned numbers, while IDIV operates on signed integers as well as unsigned. In either case, an exception
(interrupt zero) occurs if the divisor is zero or if the quotient is too large for AL, AX, or EAX. DIV performs an
unsigned division. The dividend is implicit; only the divisor is given as an operand. The remainder is always
less than the divisor. The type of the divisor determines which registers to use:
Flags Affected
OF, SF, ZF, AR, PF, CF
Algorithm:
1. Begin program and display menu in front of user
2. Read the choice of arithmetic operation from the user
3. Check the value of choice and accordingly perform the respective operation using procedure call
4. Convert the result into ascii value to display the result on the screen
Conclusion:
Hence we performed switch case driven arithmetic operations using procedure calls.
P:F-LTL-UG/03/R1
Name :-Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 5
ASSINGMENT NO. 1
PROBLEM STATEMENT Write X86/64 ALP to count number of positive and negative
/DEFINITION numbers from the array
OUTCOME Students will be e able to use different index registers and find
positive and negative numbers from array.
STEPS Start.
2. Initialize an array of 10 numbers or accept 10 numbers from user
and store them in one array.
3. Initialize pos_counter=0, neg_counter=0, index_reg=array
address, counter=10
2. Read the number from index_reg into a register.
3. Perform addition with 00H and check sign bit
4. If sign bit==1 then increment neg_counter=neg_counter+1 else
increment pos_counter=pos_counter+1
end if
5. Increment index_reg= index_reg+1
6. Decrement counter=counter-1
7. If counter!=0 then goto step number 4 else continue
8. Print message “Positive numbers are:” and print pos_counter.
9. Print message “Negative numbers are:” and print neg_counter.
10. Exit.
P:F-LTL-UG/03/R1
9. Date
INSTRUCTIONS FOR 10. Assignment no.
11. Problem definition
WRITING JOURNAL 12. Learning objective
13. Learning Outcome
14. Concepts related Theory
15. Algorithm
16. Test cases
10. Conclusion/Analysis
Prerequisites: COA
1. Sign-Magnitude representation: -
Negative numbers are essential and any computer not capable of dealing with them would
not be particularly useful. But how can such numbers be represented? There are several
methods which can be used to represent negative numbers in Binary. One of them is
called the Sign-Magnitude Method.
The Sign-Magnitude Method is quite easy to understand. In fact, it is simply an ordinary
binary number with one extra digit placed in front to represent the sign. If this extra digit
is a '1', it means that the rest of the digits represent a negative number. However if the
same set of digits are used but the extra digit is a '0', it means that the number is a
positiveone. The following examples explain the Sign-Magnitude method better. Let us
assume that we have an 8-bit register. This means that we have 7 bits which represent a
number and the other bit to represent the sign of the number (the Sign Bit).This is how
numbers are represented:
The red digit means that the number is positive. The rest of the digits represent 37. Thus, the
above number in sign-magnitude representation means +37.
And this is how -37 is represented:
Binary Value
0000 +0
0001 +1
0010 +2
P:F-LTL-UG/03/R1
0011 +3
0100 +4
0101 +5
0110 +6
0111 +7
1000 -0
1001 -1
1010 -2
1011 -3
1100 -4
1101 -5 1110 -6
1111 -7
Assign the leftmost (most significant) bit to be the sign bit. If the sign bit is 0,
this means the number is positive. If the sign bit is 1, then the number is
negative. The remaining m-1 bits are used to represent the magnitude of the
binary number in the unsigned binary notation.
The 1‟s complement of a binary number is the number that results when we change all 1s to
zeros and the zeros to ones.
Add 1 = 1
1
2‟s complement of number = 00111100
A complete binary table for four bits is shown below:
P:F-LTL-UG/03/R1
Binary Two‟s Comp Value Binary Two‟ Comp
Value
0000 0 1111 -1
0001 +1 1110 -2
0010 +2 1101 -3
0011 +3 1100 -4
0100 +4 1011 -5
0101 +5 1010 -6
0110 +6 1001 -7
0111 +7 1000 -8
Advantages of 2’s complement representation: -
1. There are distinct +0 and -0 representations in both the sign-magnitude and 1‟s
complement systems, but the 2‟s complement system has only a +0 representation.
2. For 4 bit numbers, the value -8 is represent able only in the 2‟s complement
system and not in other systems.
3. It is more efficient for logic circuit implementation, and one often used in
computers for addition and subtraction operations.
Algorithm:
1. Start.
2. Initialize an array of 10 numbers or accept 10 numbers from user and store
them in one array.
P:F-LTL-UG/03/R1
3. Initialize pos_counter=0, neg_counter=0, index_reg=array address, counter=10
4. Read the number from index_reg into a register.
5. Perform addition with 00H and check sign bit
6. If sign bit==1 then increment neg_counter=neg_counter+1 else
increment pos_counter=pos_counter+1
end if
7. Increment index_reg= index_reg+1
8. Decrement counter=counter-1
9. If counter!=0 then goto step number 4 else
continue
10. Print message “Positive numbers are:” and print pos_counter.
11. Print message “Negative numbers are:” and print neg_counter.
12. Exit.
Conclusion:
We are able to use different index registers and find positive and negative numbers from array.
P:F-LTL-UG/03/R1
Name :-Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER:6
ASSINGMENT NO. 6
STEPS A] Overlapping
1. Study system call to read and display character on the screen.
2. Accept the Value of „N‟ i.e. how many numbers to add
3. initialize Sum =0
4. Read a number (two digit)
5. add it to sum
P:F-LTL-UG/03/R1
6. repeat the steps 4 and 5 to add all N numbers
7. Print the result /Sum
8. End.
B] Non Overlapping
1. Declare a source array.
Prerequisites: Instruction set of 80386 Concepts related Theory: One of the frequent operations used
in programming is shifting/ transferring the data form one memory location to another memory
location. These operations can be with simple mov instructions which may result in more number of
operations. We can make use of instructions like MOVSB to transfer the data. The relevant instructions
are LOOP / MOVSB. The data can be transferred either in overlapped fashion or non overlapped
Fashion. In case of overlapped address the two possible situations are for the Source address to be
greater than the destination address in which case the first element in the source is to be moved first or
for the source address to be less than the destination address which requires the last element of the
source to be moved first.
P:F-LTL-UG/03/R1
Algorithm: A] Overlapping
1. Study system call to read and display character on the screen.
2. Accept the Value of „N‟ i.e. how many numbers to add
3. initialize Sum =0
4. Read a number (two digit)
5. add it to sum
6. repeat the steps 4 and 5 to add all N numbers
7. Print the result /Sum
8. End.
B] Non Overlapping
1. Declare a source array.
2. Load the address of source array in one of the registers. (Index register)
4. Increment the pointer/SI by length of array which becomes the starting Address of
destination array.
6. In case of overlapping mode based on the destination address either move the first
Element or last element in beginning of transfer operation.
Conclusion:
We have studied different block transfer instructions and also understood block transfer within
different segments.
P:F-LTL-UG/03/R1
Name :-Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 7
ASSINGMENT NO. 7
PROBLEM STATEMENT Write 64 bit ALP to convert 4-digit Hex number into its equivalent
/DEFINITION 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
OBJECTIVE To learn
• Data representation and conversion
• Understand the stack operations
OUTCOME Students will studuy use of stack operations and number conversion
in ALP.
S/W PACKAGES AND Processor: Core 2 duo/i3/i5/i7
OS: Linux 32bit/64bit OS
HARDWARE APPARATUS Editor: gedit/vi
USED Assembler: NASM
Debugger: GDB
REFERENCES 1. Douglas Hall, “Microprocessors & Interfacing”, McGraw
Hill, Revised 2nd Edition, 2006 ISBN 0-07-100462-9
2. A.Ray, K.Bhurchandi ”Advanced Microprocessors and
peripherals: Arch, Programming & Interfacing”
STEPS 1. Start.
2. Take i/p as hex to bcd or bcd to hex.
3. Convert input to ASCII.
4. Convert i/p to hex or bcd as required using function.
5. Convert answer to ASCII to display
6. Display answer
7. Exit
1. Date
INSTRUCTIONS FOR 2. Assignment no.
P:F-LTL-UG/03/R1
WRITING JOURNAL 3. Problem definition
4. Learning objective
5. Learning Outcome
6. Concepts related Theory
7. Algorithm
8. Test cases
10. Conclusion/Analysis
BCD to HEX
• Initialize sum = 0
• Accept the first digit multiplicand
• Multiply the number by 10,000 multiplier
• Add result to sum
P:F-LTL-UG/03/R1
• Divide the multiplier by 10
• Repeat the step 2 to 4 till multiplier becomes zero
• Display the sum which is result of converting BCD number to HEX
Example
BCD number =4660
4*1000 + 6*100 + 6*10 + 6*0 = 1234H
FA0 + 258 +3C + 0 =1234H
Algorithm:
1. Start.
2. Take i/p as hex to bcd or bcd to hex.
3. Convert input to ASCII.
4. Convert i/p to hex or bcd as required using function.
5. Convert answer to ASCII to display
6. Display answer
7. Exit
Conclusion:
We have studied use of stack operations and number conversion in ALP.
P:F-LTL-UG/03/R1
Name :-Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 8
ASSINGMENT NO. 8
OBJECTIVE To learn
• Overlapped / Non – overlapped data transfer in segments
• Block transfer instruction of 8086
• Data storage in the memory and segments
OUTCOME Students will study different block transfer instructions and also
understood block transfer within different segments.
P:F-LTL-UG/03/R1
9. repeat the steps 4 and 5 to add all N numbers
10. Print the result /Sum
11. End.
B] Non Overlapping
7. Declare a source array.
8. Load the address of source array in one of the registers. (Index
register)
9. Read the first byte from the source array.
10. Increment the pointer/SI by length of array which becomes the
starting Address of destination array.
11. Move the source element to the destination address.
12. In case of overlapping mode based on the destination address
either move the first Element or last element in beginning of transfer
operation.
1. Date
INSTRUCTIONS FOR 2. Assignment no.
P:F-LTL-UG/03/R1
Add and Shift Method: Consider that one byte is present in the AL register and another byte is present
in the BL register. We have to multiply the byte in AL with the byte in BL. We will multiply the
numbers using add and shift method. In this method, you add number with itself and rotate the other
number each time and shift it by one bit to left alongwith carry. If carry is present add the two numbers.
Initialize the count to 4 as we are scanning for 4 digits. Decrement counter each time the bits are
added. The result is stored in AX. Display the result.
For example : AL = 11 H, BL = 10 H, Count = 4
Step I : AX = 11 + 11 22 H
Rotate BL by one bit to left along with carry.
BL = 10 H 0 ¬ 0 0 0 1 0 0 0 0
CY BL = 0 0 0 10 0000
CY 20
Step II : Now decrement counter count = 3.
Check for carry, carry is not there so add number with itself.
AX = 22 + 22 44 H Rotate BL to left,
BL = 0 ¬0 100 0000
CY 4 0 Carry is not there. Decrement count, count=2
Step III : Add number with itself AX = 44 + 44 88 H Rotate BL to left,
BL = 0 1 000 0000
CY 8 0 Carry is not there.
Step IV : Decrement counter count = 1. Add number with itself as carry is not there.
AX = 88 + 88 110 H Rotate BL to left,
BL = 1 0000 0000
CY 0 0 Carry is there.
Step V : Decrement counter = 0. Carry is present. \ add AX, BX\ 0110 i.e. 11 H + 0000 ´ 10 H
0110 H 0110 H
P:F-LTL-UG/03/R1
Algorithm:
Successive Addition:
1. Start
2. Accept two 2-digit numbers. (Multiplier and Multiplicand)
3. Set Multiplicand value as a counter value.
4. Add Multiplier with itself “Counter-1” number of times.
5. Print The answer.
1. Start
2. Accept two 2-digit numbers. (Multiplier and Multiplicand)
3. Store multiplier to BL and Multiplicand to CL, Initialize AXwith 00. 4.
Shift BL to left by 1 bit. (Shifted bit will be stored to carryflag)
5. If carry flag is set, Add CL to AL, and shift AL to left by 1bit.
6. If carry flag is reset, shift AL to left by 1 bit.
7. Repeat step 4 to 6 for 8 times. (As 2 digit numbers contains 8
bits)
8. Print the result from AX.
9. Stop
Conclusion:
We have studied following multiplication techniques in ALP.
1. Successive Addition
2. Add and Shift Method.
P:F-LTL-UG/03/R1
Name :-Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 9
ASSINGMENT NO. 9
OUTCOME Students will study NEAR and FAR procedure and there
application.
S/W PACKAGES AND Processor: Core 2 duo/i3/i5/i7
OS: Linux 32bit/64bit OS
HARDWARE Editor: gedit/vi
APPARATUS USED Assembler: NASM
Debugger: GDB
REFERENCES ➢ “The Intel microprocessor”, Barry B. Brey.
➢ “Introduction to 64 bit Intel Assembly Language
Programming for Linux”, 2nd Edition, Ray Seyfarth,
➢ “80386 Microprocessor Handbook”, Chris H. Papas.
P:F-LTL-UG/03/R1
Aim: Write X-86 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 GLOBAL
and EXTERN directives is mandatory.
• Prerequisites : Program Transfer control instruction, File system
• Concept related Theory:
• OPEN File mov rax, 2 ; 'open' syscall mov rdi, fname1 ; file name
mov rsi, 2 ; File access mode
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
Conclusion
We have studied Near and Far process and there application.
Name :-Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 10
P:F-LTL-UG/03/R1
• Concept related Theory:
GDTR and IDTR
These registers hold the 32-bit linear base address and 16-bit limit of the GDT and IDT,
respectively.
The GDT and IDT segments, since they are global to all tasks in the system, are defined by 32-
bit linear addresses (subject to page translation if paging is enabled) and 16-bit limit values.
LDTR and TR
These registers hold the 16-bit selector for the LDT descriptor and the TSS descriptor, respectively. The
LDT and TSS segments, since they are task specific segments, are defined by selector values stored in
the system segment registers. Note that a segment descriptor register (programmer- invisible) is
associated with each system segment register.
Conclusion
We have studied different Descriptor tables in system also different registers associated with it.
P:F-LTL-UG/03/R1
Name :- Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER : 11
INSTRUCTIONS 1. Title
FOR 2. Problem Definition
WRITING 3. Objective: Intention behind study
JOURNAL
4. Software & Hardware requirements
5. Explanation of the assignment
6. Algorithm
7. State Diagram
8. Test cases for program.
9. Print outs
10. Conclusion.
P:F-LTL-UG/03/R1
• Aim: 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
Conclusion
We have studied how to implement bubble sort using ALP.
P:F-LTL-UG/03/R1
Name :- Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER : 12
P:F-LTL-UG/03/R1
INSTRUCTIONS FOR 1. Title
2. Problem Definition
WRITING JOURNAL 3. Objective: Intention behind study
4. Software & Hardware requirements
5. Explanation of the assignment
6. Algorithm
7. State Diagram
8. Test cases for program.
9. Print outs
10. Conclusion.
Aim:Write X86 menu 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.
• Prerequisites : Linux commands, Command Line
• Concept related 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
• OPEN File/Create file mov rax, 2 ; 'open' syscall
mov rdi, fname1 ; file name mov rsi, 0102o ; read
and write mode, create if not mov rdx, 0666o ;
permissions set Syscall mov [fd_in], rax
• READ File
mov rax, 0 ; „Read' syscall
Conclusion
We have studied different DOS commands and file operations.
P:F-LTL-UG/03/R1
Name :- Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 13
TITLE 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.
PROBLEM STATEMENT Write x86 ALP to find the factorial of a given integer nu
/DEFINITION command line by using recursion. Explicit stack manip
expected in the code.
OBJECTIVE To understand how to use stack segment for recursion.
OUTCOME Students will study recursion using stacki n ALP.
S/W PACKAGES AND Processor: Core 2 duo/i3/i5/i7
OS: Linux 32bit/64bit OS
HARDWARE Editor: gedit/vi
APPARATUS USED Assembler: NASM
Debugger: GDB
REFERENCES • “The Intel microprocessor”, Barry B. Brey.
• “Introduction to 64 bit Intel Assembly Language
Programming for Linux”, 2nd Edition, Ray Seyfarth,
• “80386 Microprocessor Handbook”, Chris H. Papas.
STEPS ➢ Start.
➢ Accept the number from user.
➢ Convert that number into Hexadecimal(ASCII TO HEX).
➢ Compare accepted number with 1,If it is equal to 1 go to step
5,else push the number on stack and decrement the number
and go to step 4
➢ pop the content of stack and multiply with number
➢ repeat the step until stack become empty.
➢ Convert the number from HEX to ASCII
➢ Print the number.
➢ End.
11. Conclusion: In this way we studied to use stack segment for recursion.
P:F-LTL-UG/03/R1
Name :- Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 14
ASSINGMENT NO.
TITLE Write 80387 ALP to find the roots of the quadratic equation. All the
possible cases must be considered in calculating the roots.
PROBLEM STATEMENT Write 80387 ALP to find the roots of the quadratic equation. All the
/DEFINITION possible cases must be considered in calculating the roots.
OBJECTIVE To be able to solve mathematical problems in Assembly language
programming
OUTCOME Students will be efficient in handling and solving mathematical
problems using ALP
S/W PACKAGES AND Processor: Core 2 duo/i3/i5/i7
OS: Linux 32bit/64bit OS
HARDWARE APPARATUS
USED
Editor: gedit/vi
Assembler: NASM
Debugger: GDB
REFERENCES ➢ “The Intel microprocessor”, Barry B. Brey.
➢ “Introduction to 64 bit Intel Assembly Language
Programming for Linux”, 2nd Edition, Ray Seyfarth, “80386
Microprocessor Handbook”, Chris H. Papas.
STEPS 1. Write msg to enter the Quadratic equation
2. Write msg to enter first coefficient a
3. Read first coefficient
4. Convert the no from ascii to hex
5. Write msg to enter second coefficient b
6. Read second coefficient
7. Convert the no from ascii to hex
8. Write msg to enter third coefficient c
9. Read third coefficient
10. Convert the no from ascii to hex
11. Write down the quadratic formula
12. Identify the values of a, b, and c in the
quadratic equation.
P:F-LTL-UG/03/R1
The variable a is the coefficient of the x term, b is the
coefficient of the x term, and c is the constant. For the
equation 3x2 -5x - 8 = 0, a = 3, b = -5, and c = -8. Write this
down.
13. Substitute the values of a, b, and c into the equation. Now
that you know the values of the three variables, you can just
plug them into the equation like this:
a. {-b +/-√ (b2 - 4ac)}/2
b. {-(-5) +/-√ ((-5)2 - 4(3)(-8))}/2(3) =
c. {-(-5) +/-√ ((-5)2 - (-96))}/2(3)
14. Do the math. After you've plugged in the
a. numbers, do the remaining math to simplify
b. positive or negative signs, multiply, or square the
c. remaining terms. Here's how you do it:
d. {-(-5) +/-√ ((-5)2 - (-96))}/2(3) =
e. {5 +/-√(25 + 96)}/6
f. {5 +/-√(121)}/6
15. Simplify the square root. If the number under the radical
symbol is a perfect square, you will get a whole number. If
the number is not a perfect square, then simplify to its
simplest radical version. If the number is negative, and
you're sure it's supposed to be negative, then the roots will be
complex. In this example, √(121) = 11. You can write that x
= (5 +/- 11)/6.
16. Convert the final roots from hex to ascii
17. Print the final roots. Real and imaginary.
1. Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3. Problem definition
4. Learning objective
5. Learning Outcome
6. Concepts related Theory
7. Algorithm
8. Test cases
10. Conclusion/Analysis
P:F-LTL-UG/03/R1
Aim: Write 80387 ALP to find the roots of the quadratic equation. All the possible cases must be
considered in calculating the roots.
The 80387 (387 or i387) is the first Intel coprocessor to be fully compliant with the IEEE 754-
1985 standard. Released in 1987, a full two years after the 386 chip, the i387 includes much
improved speed over Intel's previous 8087/80287 coprocessors, and improved characteristics of
its trigonometric functions. The 8087 and 80287's FPTAN and FPATAN instructions are limited
to an argument in the range ±π/4 (±45°), and the 8087 and 80287 have no direct instructions for
the sin and cos functions.
Without a coprocessor, the 386 normally performs floating-point arithmetic through (slow)
software routines, implemented at runtime through a software exception-handler. When a math
coprocessor is paired with the 386, the coprocessor performs the floating point arithmetic in
hardware, returning results much faster than an (emulating) software library call.
The i387 is compatible only with the standard i386 chip, which has a 32-bit processor bus. The
later cost-reduced i386SX, which has a narrower 16-bit data bus, can not interface with the i387's
32-bit bus. The i386SX requires its own coprocessor, the 80387SX, which is compatible with the
SX's narrower 16-bit data bus.
Instruction set:
All instructions of 80386 MOV, JC,JNC,JG,JZ,JNZ,PUSH POP,INC DEC,CMP, ADD ETC are
used in this program.
Algorithm:
1. Write msg to enter the Quadratic equation
2. Write msg to enter first coefficient a
3. Read first coefficient
4. Convert the no from ascii to hex
5. Write msg to enter second coefficient b
6. Read second coefficient
7. Convert the no from ascii to hex
8. Write msg to enter third coefficient c
9. Read third coefficient
P:F-LTL-UG/03/R1
10. Convert the no from ascii to hex
11. Write down the quadratic formula
12. Identify the values of a, b, and c in the quadratic equation. The variable a is the
coefficient of the x2 term, b is the coefficient of the x term, and c is the constant. For
the equation 3x2 -5x - 8 = 0, a = 3, b = -5, and c = -8. Write this down.
13. Substitute the values of a, b, and c into the equation. Now that you know the values of
the three variables, you can just plug them into the equation like this:
14. Do the math. After you've plugged in the numbers, do the remaining math to simplify
positive or negative signs, multiply, or square the remaining terms. Here's how you do
it:
{5 +/-√(25 + 96)}/6
{5 +/-√(121)}/6
14. Simplify the square root. If the number under the radical symbol
is a perfect square, you will get a whole number. If the number is
not a perfect square, then simplify to its simplest radical version.
If the number is negative, and you're sure it's supposed to be
negative, then the roots will be complex. In this example, √(121)
= 11. You can write that x = (5 +/- 11)/6.
15. Convert the final roots from hex to ascii 16. Print the final roots.
Real and imaginary.
Conclusion: Thus Roots of Quadratic equations are calculated following above steps.
P:F-LTL-UG/03/R1
Name :- Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 15
TITLE Write 80387 ALP to plot Sine Wave, Cosine Wave and Sinc
function. Access video memory directly for plotting.
PROBLEM STATEMENT Write 80387 ALP to plot Sine Wave, Cosine Wave and Sinc
/DEFINITION function. Access video memory directly for plotting.
OBJECTIVE To understand how to how to access video memory for plotting.
OUTCOME Students will study video memory plotting and regen buffer
concepts..
S/W PACKAGES AND Processor: Core 2 duo/i3/i5/i7
OS: Linux 32bit/64bit OS
HARDWARE Editor: gedit/vi
APPARATUS USED Assembler: NASM
Debugger: GDB
REFERENCES ➢ “The Intel microprocessor”, Barry B. Brey.
➢ “Introduction to 64 bit Intel Assembly Language
Programming for Linux”, 2nd Edition, Ray Seyfarth,
➢ “80386 Microprocessor Handbook”, Chris H. Papas.
Graphics Mode:
• More complicated
• Each bit or group of bits in regen buffer corresponds to an addressable point or pixel on
the screen
• E.g. 640-by-200, 2-color graphics display mode of the CGA
• Each pixel is represented by a single bit
• (x,y) range (0,0) through (639,199)
• The memory map is set up so that all the even y coordinates are scanned as a set and all
the odd y coordinates are scanned as a set; this mapping is referred to as the memory
interlace.
• Offset = ((y AND 1)*2000H) + (y/2*50H)+ (x/8)
• Bit position = 7 – (x MOD 8)
( 8 byte table or array of bit masks and operation „x AND 7‟)
Sine Wave:
• Y = 100 – 60 sin ({pi/180}*x)
Cosine Wave:
• Y = 100 – 60 cos ({pi/180}*x)
Sinc Function:
Conclusion
We have studied video memory plotting to plot sine wave, cosine wave and sin function.
P:F-LTL-UG/03/R1
Name :- Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 16
ASSINGMENT NO. 12
TITLE Write 80387 ALP to obtain: i) Mean ii) Variance iii) Standard
Deviation Also plot the histogram for the data set. The data elements
are available in a text file.
PROBLEM STATEMENT Write 80387 ALP to obtain: i) Mean ii) Variance iii) Standard
/DEFINITION Deviation Also plot the histogram for the data set. The data elements
are available in a text file.
OBJECTIVE To be able to solve mathematical problems in Assembly language
programming
To be able to handle file and data set from file in ALP,
To be able to include mathematical histogram using ALP
OUTCOME Students will be efficient in handling and solving mathematical
problems through file using ALP
S/W PACKAGES AND Processor: Core 2 duo/i3/i5/i7
OS: Linux 32bit/64bit OS
HARDWARE APPARATUS
USED Editor: gedit/vi
Assembler: NASM
Debugger: GDB
REFERENCES ➢ “The Intel microprocessor”, Barry B. Brey.
➢ “Introduction to 64 bit Intel Assembly Language
Programming for Linux”, 2nd Edition, Ray Seyfarth,
“80386 Microprocessor Handbook”, Chris H. Papas.
STEPS 1. Create a one Folder which contain 1 program file and 1
text file.
2. Write all input text to the text file.
3. Define all parameter required to execute above procedure
in 1st program file.
P:F-LTL-UG/03/R1
4. Define all the procedures
a. Ascii to Hex
b. Hex to ascii
c. Find Mean
d. Find Variance
e. Find Standard Deviation
1. Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3. Problem definition
4. Learning objective
5. Learning Outcome
6. Concepts related Theory
7. Algorithm
8. Test cases
10. Conclusion/Analysis
Aim: Write 80387 ALP to obtain: i) Mean ii) Variance iii) Standard Deviation Also plot
the histogram for the data set. The data elements are available in a text file.
Prerequisites: Basic instructions of Assembly Language programming
Concepts related Theory:
OPEN File mov rax, 2 ; 'open' syscall
mov rdi, fname1 ; file name
mov rsi, 2 ; File access mode 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
Algorithm: Data set: Measured height of the dogs The heights (at the shoulders) are: 600mm,
470mm, 170mm, 430mm and 300mm. Mean = Addition of all the values /no of values Mean =
600 + 470 + 170 + 430 + 3005 = 19705 = 394 Variance : Variance = s2 To calculate the Variance,
take each difference, square it, and then average the result:
And the Standard Deviation is just the square root of Variance, so:
Standard Deviation
σ = √21,704
= 147.32...
= 147 (to the nearest mm)
Conclusion:. Thus we have calculated Mean ,Variance and Standard deviation using ALP
P:F-LTL-UG/03/R1
Name :- Shirole Pragati Jagnnath Roll No:-32 Div:-B
ASSIGNMENT NUMBER: 17
ASSIGNMENT NO 13
TITLE Write a Terminate but Stay Resident (TSR) program for a
key- logger. The key-presses during the stipulated time need
tobe displayed at the center of the screen
PROBLEM STATEMENT Write a Terminate but Stay Resident (TSR) program for a
/DEFINITION key- logger. The key-presses during the stipulated time need
tobe displayed at the center of the screen
OBJECTIVE To understand Terminate but Stay Resident program.
OUTCOME Students will study Terminate but Stay Program for a key-logger..
S/W PACKAGES AND Processor: Core 2 duo/i3/i5/i7
OS: Linux 32bit/64bit OS
HARDWARE S/W: key-logger
APPARATUS USED Assembler: NASM
Debugger: GDB
REFERENCES ➢ “The Intel microprocessor”, Barry B. Brey.
➢ “Introduction to 64 bit Intel Assembly Language
Programming for Linux”, 2nd Edition, Ray Seyfarth,
➢ “80386 Microprocessor Handbook”, Chris H. Papas.
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 Prerequisites : MS
DOS, DOS interrupts
P:F-LTL-UG/03/R1
• Terminate and Stay Resident (TSR) generally refers to a special class of programs for PC-
compatible computers running DOS.
• When a user exits a normal program running in DOS, the memory that the program used
is usually freed for other programs and tasks; therefore, the program must be reloaded
from a disk back into memory for it to be used again. When you run a TSR program,
however, it loads itself into the computer's memory and remains there for later use. You
may run other programs while the TSR is still alive in memory, and these programs may
invoke the TSR or be affected by the behavior of the TSR program. For this reason, TSR
programs may give DOS the appearance of multitasking (the ability to perform several
tasks at once) which is built into many other operating systems.
• You may use TSR programs for a wide variety of tasks. Some of these programs are
active only when you press a hot key (a special key or combination of keystrokes that
activates the TSR). An example would be a pop-up calculator program that appears on
thescreen whenever you press Alt-Shift-c, even from within a separate word processing
program. Other TSR programs run continuously in the background and may normally be
invisible. Examples of such programs are some network and communications programs
and special virus scanner programs that monitor the use of a computer's memory and
diskdrives. Still other TSR programs may operate in both ways. A visually impaired user
might call up a TSR that intercepts text information sent to the screen and displays it in a
larger, easier-to- read format.
• TSR programs may be quite complex, and are often difficult to program reliably. TSR
programmers must make sure that their programs do not conflict with other programs
active in the computer's memory. The TSR must also not interfere with other programs'
use of the disk drives or other hardware. Whenever a TSR becomes active, it must
carefully record information in memory being used by another program, and restore this
information exactly when it transfers control.
• Because of this complexity, TSR programs are often likely culprits when a PC is
behaving strangely or crashing. Some TSR programs may not be compatible with other
programs because of the way they use memory, or they may conflict with other TSR
programs that are also active. When installing TSR programs, it is a good idea to install
them one at a time, and make sure that other programs such as word processors and
spreadsheets are behaving normally despite the presence of the TSR.
• Another drawback to TSR programs is their consumption of memory. Because a TSR
retains a block of the computer's memory as its own, less space is then available to other
programs. If several TSR programs are present in memory, there may not be enough
space left over to load other large, demanding programs such as spreadsheets. Beginning
with version 5.0, however, DOS supports the ability to load high most of a TSR program's
contents into expanded and extended memory, which have fewer demands on their use
than the computer's main memory, where most programs are executed and consumption
of space is critical.
• Conclusion
We have studied Terminate but Stay Resident program for key-logger
P:F-LTL-UG/03/R1