MPL Lab Manual
MPL Lab Manual
PUNE
Laboratory Manual
For
A.Y. 2023-2024
210257: Microprocessor
Laboratory Prof. Bhairavi Pawar
10
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.
Department of Computer Engineering Microprocessor Laboratory (2019 course)
Experiments No:01
Name of Student……………………………………………….. Roll No.:…… Batch:
4 4 4 4 4 20
Problem Statement: Write an X86/64 ALP to accept five 64 bit Hexadecimal numbers from
user and store them in an array and display the accepted numbers.
Objective:
Hardware Requirement: NA
Software Requirement: OS:Ubuntu Assembler: NASM version 2.10.07 Linker: ld
Theory Contents :
Introduction to Assembly Language Programming:
Each personal computer has a microprocessor that manages the computer's arithmetical, logical
and control activities. Each family of processors has its own set of instructions for handling
various operations like getting input from the keyboard, displaying information on screen and
performing various other jobs. These set of instructions are called 'machine language instruction'.
Processor understands only machine language instructions which are strings of 1s and 0s.
However machine language is too obscure and complex for using in software development. So the
low level assembly language is designed for a specific family of processors that represents various
instructions in symbolic code and a more understandable form. Assembly language is a low-level
programming language for a computer, or other programmable device specific to particular
computer architecture in contrast to most high-level programming languages, which are generally
portable across multiple systems. Assembly language is converted into executable machine code
by a utility program referred to as an assembler like NASM, MASM etc.
The order in which these sections fall in your program really isn’t important, but by convention
the.data section comes first, followed by the .bss section, and then the .text section.
The .data Section
The .data section contains data definitions of initialized data items. Initialized data is data that has
a value before the program begins running. These values are part of the executable file. They are
loaded into memory when the executable file is loaded into memory for execution. You don’t
have to load them with their values, and no machine cycles are used in their creation beyond what
it takes to load the program as a whole into memory. The important thing to remember about
the
.data section is that the more initialized data items you define, the larger the executable file will
be, and the longer it will take to load it from disk into memory when you run it.
Labels
A label is a sort of bookmark, describing a place in the program code and giving it a name that’s
easier to remember than a naked memory address. Labels are used to indicate the places where
jump instructions should jump to, and they give names to callable assembly language procedures.
Here are the most important things to know about labels:
Labels must begin with a letter, or else with an underscore, period, or question mark. These
last
three have special meanings to the assembler, so don’t use them until you know how
NASM interprets them.
Labels must be followed by a colon when they are defined. This is basically what tells NASM
that the identifier being defined is a label. NASM will punt if no colon is there and will not flag
an error, but the colon nails it, and prevents a mistyped instruction mnemonic from being
mistaken for a label. Use the colon!
Labels are case sensitive. So yikes:, Yikes:, and YIKES: are three completely different labels.
NA ALGORITHM:
INPUT: ARRAY
OUTPUT: ARRAY
STEP 1: Start.
STEP 8: Decrement
Counter.
Counter.
FLOWCHART:
Conclusion:
2 2
Explain the difference between 32bit and 64bit
processors?
3 1 Explain steps of running an ALP program?
Sign of Student
Experiments No:03
Name of Student……………………………………………….. Roll No.:…… Batch:
4 4 4 4 4 20
Problem Statement: Write an X86/64 ALP to find the largest of given Byte/Word/Dword/64-
bit numbers.
Objective:
Hardware Requirement: NA
Software Requirement: OS:Ubuntu Assembler: NASM version 2.10.07 Linker: ld
● Bit
● Bit Field: A group of at the most 32 bits (4bytes)
● Offset: 16/32-bit displacement that points a memory location using any of the
addressing modes.
● Pointer: This consists of a pair of 16-bit selector and 16/32-bit offset.
● Strings: These are the sequences of bytes, words or double words. A string may contain
minimum one byte and maximum 4 Gigabytes.
● BCD: Decimal digits from 0-9 represented by unpacked bytes.
● Packed BCD: This represents two packed BCD digits using a byte, i.e. from 00 to 99.
Registers in 80386:
EAX AX AH,AL
EBX BX BH,BL
ECX CX CH,CL
EDX DX DH,DL
EBP BP
EDI DI
ESI SI
ESP
2 2
What is difference between byte,word and
double word?
3 1 What is format of instruction?
Sign of Student
Experiments No:04
Name of Student……………………………………………….. Roll No.:…… Batch:
4 4 4 4 4 20
Problem Statement: Write an X86/64 ALP to count number of positive and negative numbers
from the array.
Hardware Requirement: NA
Software Requirement: OS:Ubuntu Assembler: NASM version 2.10.07 Linker: ld
Theory Contents :
Mathematical numbers are generally made up of a sign and a value (magnitude) in which the sign
indicates whether the number is positive, ( + ) or negative, ( – ) with the value indicating the size
of the number, for example 23, +156 or -274. Presenting numbers is this fashion is called
“sign-magnitude” representation since the left most digit can be used to indicate the sign and the
remaining digits the magnitude or value of the number.
Sign-magnitude notation is the simplest and one of the most common methods of representing
positive and negative numbers either side of zero, (0). Thus negative numbers are obtained simply
by changing the sign of the corresponding positive number as each positive or unsigned number
will have a signed opposite, for example, +2 and -2, +10 and -10, etc.
But how do we represent signed binary numbers if all we have is a bunch of one’s and zero’s. We
know that binary digits, or bits only have two values, either a “1” or a “0” and conveniently for
us, a sign also has only two values, being a “+” or a “–“.
Then we can use a single bit to identify the sign of a signed binary number as being positive or
negative in value. So to represent a positive binary number (+n) and a negative (-n) binary
number, we can use them with the addition of a sign.
For signed binary numbers the most significant bit (MSB) is used as the sign bit. If the sign bit is
“0”, this means the number is positive in value. If the sign bit is “1”, then the number is negative
in value. The remaining bits in the number are used to represent the magnitude of the binary
number in the usual unsigned binary number format way.
Then we can see that the Sign-and-Magnitude (SM) notation stores positive and negative values
by dividing the “n” total bits into two parts: 1 bit for the sign and n–1 bits for the value which is a
pure binary number. For example, the decimal number 53 can be expressed as an 8-bit signed
binary number as follows.
ALGORITHM:
STEP 1: Initialize index register with the offset of array of signed numbers
STEP 2: Initialize ECX with array element count
STEP 3: Initialize positive number count and negative number count to zero
STEP 4: Perform MSB test of array element
STEP 5: If set jump to step 7
STEP 6: Else Increment positive number count and jump to step 8
STEP 7: Increment negative number count and continue
STEP 8: Point index register to the next element
STEP 9: Decrement the array element count from ECX, if not zero jump to step 4, else continue
STEP 10: Display Positive number message and then display positive number count
STEP 11: Display Negative number message and then display negative number count
STEP 12: EXIT
Assignment Questions:
1. Write Down Write, Read, Exit System Call for 32bits Operating System?
2. What is the difference between Macros & Procedure?
3. Explain BT Instruction?
4. Explain Significance of Sign Bit?
5. Explain How Loop Instruction Works?
6. Explain resb,resw,resq, db, dw,dq?
7. Explain the role of Section .data, section .bss, section .text?
Conclusion:
Hence we counted and displayed the number of positive and negative numbers from the
array of signed numbers.
Sign of Student
Experiments No:05
4 4 4 4 4 20
Problem Statement: Write X86/64 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. (Wherever
necessary, use 64-bit registers).
Hardware Requirement: NA
Theory Contents :
These directives instruct the assembler as to how large the various segment (code,
data, stack, etc) can be and what sort of segmentation register will be required.
.MODEL
<model >
Where <model>is one of the following options:
Tiny- code and data fit into single 64k and accessed via near pointers.
Small- code and segment both less than 64k and accessed via near pointers. Compact –
Code segment is <64K (near ptr) and data segment is <1MB (far ptr ) Medium- Code
segment is <1Mb (far ptr) and data segment is <64K (near ptr) Large- code and data
segment both less than 1MB and accessed via far pointers. Huge- Like “large” model, but
also permits arrays larger then 64K
Segment directives
These directives indicate to assembler the order in which to load segment. When it
encounter one of these directives, it interprets all subsequent instructor as belonging to the
indicated segment (until the ne xt directives is encounter).
. data
.stack <size>; specified .code
As has been previously discu ssed, data can be of several different lengths and assembler must
be able to decide what length a specific constant (or variable) is. This can be down using data type
declaration in conjunction with a constant declaration or variable assignment .this is akin to strong
typing of variable in high level language .the data types are:
Byte (8 bit quantity)—synonyms are byte and db
Word (16) -- synonyms are word dw
Dword (32bit) -- synonyms are dword and dd
Qword (64bit) -- synonyms with dq
Tword (128bit) -- synonyms with dt
An example of their use is:
MOV AX, word VAR; moves a 16-bit Variable VAR into AX
2. Instruction Used:
1. PUSH:-Push word onto stack.
2. POP:-Pop word off stack.
3. DIV:-Divide byte/word
4. XOR: - Exclusive or byte/word
5. JA/JNBE:-Jump if above/not below or equal
6. JB/JNAE:-Jump if below /not above or equal
7. JG/JNLE:-Jump if /not less nor equal
8. JL/JNGE:-Jump if less /not greater nor equal
9. INT:-It allows ISR to be activated by programmer & external H\W device
5. Algorithm:
HEX to BCD
1. Define variable on data segment.
2. Display message on screen ENTER 4-DIGIT HEX NO.
3. Accept BCD NO from user.
4. Transfer 0AH as a divisor in one of the register.
5. Divide the no by 0AH
6. PUSH reminder in one of the register
BCD to HEX
1. Define variables in data segment
2. Display message on screen ENTER 5-DIGIT BCD NO.
3. Accept single digit from user
4. Transfer 10000 to multiplier
5. Multiply accepted BCD digit by multiplier & add it to RESULT variable.
6. Accept single digit from user
7. Transfer 1000 to multiplier
8. Multiply accepted BCD digit by Multiplier & Add it to RESULT variable.
9. Accept single digit from user
10. Transfer 100 to multiplier
11. Multiply accepted BCD digit by Multiplier & Add it to RESULT variable.
12. Accept single digit from user
13. Transfer 10 to multiplier
14. Multiply accepted BCD digit by multiplier & add it to RESULT variable.
15. Accept single digit from user
16. Transfer 1 to multiplier
17. Multiply accepted BCD digit by multiplier & add it to RESULT variable.
18. Display result by calling display procedure
19. Stop.
a. Compare its ASCII with 30H if No is less than 0 (i.e case of -ve no given) then go
to step f else go to step c.
b. Compare its ASCII with 39H if No is greater than 9 (i.e case of character A – F given
HEX to BCD
and we are pushing Reminder on stack and then printing it in reverse order
BCD to HEX
Hence final result is in EAX = 65535 which is 1111 1111 1111 1111 and when we print this it is
represented as FFFF
Assignment Questions:
1. Explain various addressing modes of 8086 microprocessor used in this program.
2. Explain Different assembler directives used in this program.
3. Explain various Number Systems used in Digital Electronics.
4. What is HEX Number? Explain the steps to convert HEX No to BCD No
5. What is BCD Number? Explain the steps to convert BCD No to HEX No.
Conclusion: In this way we studied about hex to BCD and hex to BCD number conversion.
Sign of Student
Experiments No:06
Name of Student……………………………………………….. Roll No.:…… Batch:
4 4 4 4 4 20
Problem Statement: Write X86/64 ALP to detect protected mode and display the values
of GDTR, LDTR, IDTR,TR and MSW Registers also identify CPU type using CPUID
instruction.
Objective:
Hardware Requirement: NA
Software Requirement: OS:Ubuntu Assembler: NASM version 2.10.07 Linker: ld
I/O addresses and peripheral hardware. Real mode provides no support for memory protection,
multitasking, or code privilege levels.
Protected Mode:
In computing, protected mode, also called protected virtual address mode is an operational
mode of x86-compatible central processing units (CPUs). It allows system software to use
features such as virtual memory, paging and safe multi-tasking designed to increase an
operating system's control over application software.
When a processor that supports x86 protected mode is powered on, it begins executing
instructions in real mode, in order to maintain backward compatibility with earlier x86
processors. Protected mode may only be entered after the system software sets up several
descriptor tables and enables the Protection Enable (PE) bit in the control register 0 (CR0).
Control Register :
Algorithm :
1. Start
Conclusion: Hence we performed an ALP to program to use GDTR, LDTR and IDTR in
Real Mode
Assignment Question:
1. Explain instruction set of SMSW,SGDT,SLDT, STR?
2. What is GDT and GDTR?
3. What is LDT and LDTR?
4. What is IDT and IDTR?
5. What is selector?
6. Function of Descriptor (GDT ,LDT ,IDT) ?
7. What is mean by Interrupt Handler?
8. Explain Difference between Real Mode & Protected Mode?
9. Explain CR0 in Detail:
10. Explain POST Sequence?
11. Explain Flowchart of Real to Protected Mode Switch?
MPL Practical Oral Question Bank
Sr B Questions Oral 1 Oral 2 Remark
No L (improve
ment)
2 1
What is LDT and LDTR?
3 1 What is IDT and IDTR?
Sign of Student
Experiments No:07
Name of Student……………………………………………….. Roll No.:…… Batch:…….
(Div-A/B)
4 4 4 4 4 20
Problem Statement: Write X86/64 ALP to perform non-overlapped block transfer without string
specific instructions. Block containing data can be defined in the data segment.
Objective:
● Understand the memory Addressing
● Understand the localization of Data
Hardware Requirement: NA
Software Requirement: OS:Ubuntu Assembler: NASM version 2.10.07 Linker: ld
Theory Contents :
2.3.1 Registers
Registers are places in the CPU where a number can be stored and manipulated. There are three
sizes of registers: 8-bit, 16-bit and on 386 and above 32-bit. There are four different types of
registers:
Following are the registers that are used for general purposes in
8086 AX accumulator (16 bit)
AH accumulator high-order byte (8 bit)
AL accumulator low-order byte (8 bit)
BX accumulator (16 bit)
BH accumulator high-order byte (8 bit)
BL accumulator low-order byte (8 bit)
CX count and accumulator (16 bit)
CH count high order byte (8
bit) CL count low order byte (8
bit)
DX data and I/O address (16
bit) DH data high order byte (8
bit) DL data low order byte (8
bit)
2.3.1.4 Pointers –
These registers are used with the segment register to obtain 20 bit
The offset can be calculated in a number of ways. Their are three elements that can
make up an offset. The first element is a base register, this can be one of the BX of BP
registers (the BP register defaults to the stack segment). The second element is one of
the index register, SI or DI. The third element is a displacement. A displacement can
be a numerical value or an offset to a label. An offset can contain one to three of these
elements, making a total of sixteen possibilities.
BX SI
or + or +
Displacement BP
DI
(base) (index)
The offset to a label in calculated using the assembler directive OFFSET.
This directive
makes the assembler calculattehe distant from the start of the segment that the label
CS E S Fragmentation
SS D Stack • Index Registers:
S
–Contain Offset
Data Value
• Notation (Segmented
Address):
Note that segments can overlap. This means that two different logical addresses can refer to
the same physical address (aliasing).
The blocks are said to be overlapped if some of the memory locations are common for
both the blocks.
Case I: If address in SI is greater than address in DI then start the data transfer from last
memory location keeping DF=1.
Case II: If address in SI is less than address in DI, then start the data transfer from first
memory location by keeping DF=0.
2.3.4 Algorithm:
2.3.4.1 Non-overlapped mode
1. Initialize 2 memory blocks pointed by source and destination registers.
2. Initialize counter.
3. Move the contents pointed by source register to a register.
4. Increment address of source register.
5. Move the contents from register into location pointed by destination register.
6. Increment destination registers.
7. Decrement counter.
8. Repeat from steps 3 to step 6 until counter is 0.
9. End.
Input:
Array of number stored in location pointed by source and destination register Example:
Array 1 db 10h, 20h, 30h, 40h, 33h, 0ffh, 44,55h, 23h, 45h
Array2 db 00h, 00h, 00h, 00h, 00h, 00h, 00,00h, 00h, 00h
Output:
NON OVER LAPPED BLOCK TRANSFER
Array2 db 10h, 20h, 30h, 40h, 33h, 0ffh, 44,55h, 23h, 45h OVER
LAPPED BLOCK TRANSFER
Array2 db 00h, 00h, 00h, 00h, 00h,10h, 20h, 30h, 40h, 33h, 0ffh, 44,55h, 23h, 45h
Assignment Questions:
1. Memory: Even and odd banks
2. Address decoding techniques.
3. Comparison between memory mapped I/O and I/O mapped I/O.
4. Diagrammatic representation of the overlapped and non-overlapped block transfer
5. Comparison of overlapped and non-overlapped block transfer
Oral Questions:
1. Specify all the memory addressing instruction
2. What is the use of the Direction flag in Block transfer?
3. What is use of Source and Destination Index in above program
4. What is the change in the contents of memory locations
in overlapped and non- overlapped mode?
5. Which interrupt is used to terminate the program in 8086 kit?
2 1
What is the use of the Direction flag in Block
transfer?
3 1 What is use of Source and Destination Index in
above program
4 1 What is the change in the contents of memory
locations in overlapped and non- overlapped
mode?
5 1 Which interrupt is used to terminate the
program in 8086 kit?
Sign of Student
Experiments No:08
Name of Student……………………………………………….. Roll No.:…… Batch:
4 4 4 4 4 20
Problem Statement: 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).
Hardware Requirement: NA
Theory Contents :
Multiplying unsigned numbers in binary is quite easy. Recall that with 4 bit numbers
we can represent numbers from 0 to 15. Multiplication can be performed done exactly as
with decimal numbers, except that you have only two digits (0 and 1). The only number
facts to remember are that 0*1=0, and 1*1=1 (this is the same as a logical "and").
Multiplication is different than addition in that multiplication of an n bit number by an m
bit number results in an n+m bit number. Let's take a look at an example where n=m=4
and the result is 8 bits
Decimal Binary
1010
x011 0
10 0000
x6 1010
60 1010
+0000
In this case the result was 7 bit, which can be extended to 8 bits by adding a 0 at the left. When
multiplying larger numbers, the result will be 8 bits, with the leftmost set to
1, as shown.
Decimal Binary
1101
x111
13 0
x14 0000
182 1101
1101
+1101
As long as there are n+m bits for the result, there is no chance of overflow. For 2 four
bit multiplicands, the largest possible product is 15*15=225, which can be represented in
8 bits.
Multiplying signed numbers
There are many methods to multiply 2's complement numbers. The easiest is to simply
find the magnitude of the two multiplicands, multiply these together, and then use the
original sign bits to determine the sign of the result. If the multiplicands had the same sign,
the result must be positive, if they had different signs, the result is negative. Multiplication
by zero is a special case (the result is always zero, with no sign bit).
Multiplication and division can be performed on signed or unsigned numbers. For
unsigned numbers, MUL and DIV instructions are used, while for signed numbers IMUL
and IDIV are used.
The format of the multiplication & division instruction does not specify the multiplicand as
15 x 13 =195
4.1 Algorithm:
1. Start
2. Read multiplication& Multiplier for multiplication
3. Display menu
a. Successive
BHARATI VIDYPEETH’S COLLEGE OF ENGINEERING, LAVALE, Page
Department of Computer Microprocessor Laboratory (2019
Addition b.Add
& shift method
c.Exit
4. Read choice .if choice =a go to next step, if choice
= b go to Sep 9, if choice =c go to step 15
5. Assign sum =0 count= Multiplier
6. Sum =sum Multiplicand
7. Decrement count .if count >0 go to step 8
8. Print sum & go to step 3
9. Assign count =no of digit in multiplier, sum=0, shiftvar=0
10. Shift right Multiplier by 1
11. If carry flag set, sum =sum+ (Left shifted multiplicand by shiftvar)
12. Shitvar =shitvar+1
13. If count> 0 go to step 14
14. Print sum & go to step 3
15. Exit
Directive Recommended:
1) MACRO- Start of MACRO statement
2) ENDM-end
Conclusion:In this way we studied shifting operation and multiplication using successive addition
and add-shift method.
Sign of Student
Experiments No:09
Name of Student……………………………………………….. Roll No.:…… Batch:
4 4 4 4 4 20
Problem Statement: 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.
Objective:
Hardware Requirement: NA
Software Requirement: OS:Ubuntu Assembler: NASM version 2.10.07 Linker: ld
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:
_
Instructions:
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
Macros: Macro 1
i. Name : Print
ii. Purpose: to display the messages by replacing the whole code by simple
macro declaration
iii. I/P: sys_write call Number i.e eax= , File descriptor (for Standard
output ebx=1), Buffer Address in rsi, and
length of Buffer in rdx. Then Call int 80h.
Macro 2
1. Name : Accept
2. Purpose: to accept input from the user by replacing the whole code by simple
macro Declaration
3. I/P: sys_read call Number i.e eax= , File descriptor (for Standard input
rdi=0), Buffer Address in ecx, and length of Buffer in edx then call int 80h
Macro 3
1. Name : fopen
2. Purpose: to open a file in given mode
3. I/P: sys_write call Number i.e eax= File name in ebx, Mode of file
in ecx (R=0,W=1,RW=2), and file permission in edx then call int 80h.
Macro 4
1. Name: fread
2. Purpose: to read the content of file
4. I/P: sys_read call Number i.e eax=3, File descriptor in ebx , Buffer Address in ecx, and
Length of Buffer in edx. Then Call int 80h
Macro 5
1. Name: fclose
2. Purpose: to close opened file
3. I/P: sys_read call Number i.e eax=6, File handler in ebx. Then Call int 80h.
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 ECX
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 vii. Compare AL with 10H (ASCII value of
line) if not equal then go to step
viii else increment content of ncount viii. Compare AL with BL if not equal then go
to step ix else increment content of ccount
ix. Increment RSI
x. Repeat from step
vi if RCX is not equal to zero
xi. Display “Number of space” message with the expansion of Print macro.
xii. Move content of scount in EBX
xiii. Call display8num procedure
xiv. Display “Number of lines” message with the expansion of Print macro.
xv. Move content of ncount in EBX
xvi. Call display8num procedure
xvii. Display “Number of Occurrence of Character” message
with the expansion of Print macro. xviii. Move content of ccount in
EBX
Procedure: 2
1. Name: display8num
2. Purpose: Convert
2 digit hex number into 2 ASCII character to display Positive and Negative Number count
on Standard output (stdout).
3. I/P : bl=pcnt/ncnt
4. Algorithm for Procedures
a. Move RSI with effective address of dispbuff.
b. Initialize rcx by 2
c. Rotate the contents of bl to the left side by 4 bits.
d. Move the contents of bl into al
e. And the contents of al with 0fH
f. Compare al with 09h
i. If al is below or equal then add 30H in al
ii. Else add 37H in al
g. Move the content of al into memory pointed by ESI
h. Increment ESI i. Repeat from step c to h until rcx is not equal to 0
Conclusions:
Assembly Level Program to find,
a) Number of Blank spaces
b) Number of lines
c) Occurrence of a particular character is assembled and executed successfully.
Assignment Questions
Q1 Explain ‘EXTERN’ and ‘EXTRN’ directive.
Q2 Explain ‘GLOBAL’ and ‘PUBLIC’ directive.
2 1
What is difference between Far and Near
Procedure?
3 1 What is use Far Procedure?
Sign of Student
Experiments No:10
Name of Student……………………………………………….. Roll No.:…… Batch:
4 4 4 4 4 20
Problem Statement: 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.
Objective:
Hardware Requirement: NA
Software Requirement: OS:Ubuntu Assembler: NASM version 2.10.07 Linker: ld
Theory Contents : A recursive procedure is one that calls itself. There are two kind of recursion:
direct and indirect. In direct recursion, the procedure calls itself and in indirect recursion, the first
procedure calls a second procedure, which in turn calls the first procedure.
Recursion could be observed in numerous mathematical algorithms. For example,
consider the case of calculating the factorial of a number. Factorial of a number is given
by the equation −
jmp
Recursive
ret
Recursive endp
There is however one major difference between these two implementations. The former
version of Recursive pushes a return address onto the stack with each invocation of the
subroutine. This does not happen in the example immediately above (since the jmp
instruction does not affect the stack).
Recursive
proc dec
ax
jzQuitRecurse
call
Recursive
QuitRecurse:
Ret
Recursiveend
p
This modification to the routine causes Recursive to call itself the number of times
appearing in the ax register. On each call Recursive decrements the ax register by one
and calls itself again. Eventually Recursive decrements ax to zero and returns. Once this
happens the CPU executes a string of ret instructions until control returns to the original
call to Recursive.
So far however there hasn't been a real need for recursion. After all you could efficiently
code this procedure as follows:
Recursive
proc
RepeatAgain:
dec ax
jnzRepeatAgai
n ret
Recursive endp
Both examples would repeat the body of the procedure the number of times passed in
the ax register. As it turns out there are only a few recursive algorithms that you cannot
implement in an iterative fashion. However many recursively implemented algorithms
are more efficient than their iterative counterparts and most of the time the recursive
form of the algorithm is much easier to understand.
Assignment Questions: -
1. State the difference between Iteration and Recursion?
BHARATI VIDYPEETH’S COLLEGE OF ENGINEERING, LAVALE, Page
Department of Computer Microprocessor Laboratory (2019
2. By using which instruction recursion method pushes a return address onto the stack?
3. State the Difference between CALL and JMP instruction.
Sign of Student