Lab - Manual - ML
Lab - Manual - ML
Prepared by,
SE COMP
Preface
Microprocessor Lab is a core subject of computer engineering focusing on the study,
modeling, operation and control of processor registers & memory.
In contrast to most high-level programming languages, which are often portable across many
platforms, assembly language (ALP) is a low-level programming language for a computer or
other programmable device that is specialized to a single computer architecture. A utility
software known as an assembler, such as NASM, MASM, and others, converts assembly
language into executable machine code. ALP is one of the most complex programming
languages.
These 80386 extensive system programming studies include:
∙ Technical information about your microprocessor system.
∙ Understanding and applying various addressing modes and instruction set to implement
assembly language programs
∙ Applying assembly language concepts to develop programs andAnalyzing and apply logic to
demonstrate processor mode of operation
Syllabus
Course Objectives:
∙ To understand assembly language programming instruction set
∙ To understand different assembler directives with example
∙ To apply instruction set for implementing X86/64 bit assembly language programs
Course Outcomes:
On completion of the course, learner will be able to–
CO1. Understand and apply various addressing modes and instruction set to implement
assembly language programs
CO2. Apply logic to implement code conversion
CO3. Analyze and apply logic to demonstrate processor mode of operation
Virtual Laboratory:
∙ http://209.211.220.205/vlabiitece/mi/MI3.php
1 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.
4 Write a switch case driven X86/64 ALP to perform 64-bit hexadecimal arithmetic
operations (+,-,*, /) using suitable macros. Define procedure for each operation.
5 Write an X86/64 ALP to count number of positive and negative numbers from the array.
6 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).
7 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.
8 Write X86/64 ALP to perform non-overlapped block transfer without string specific
instructions. Block containing data can be defined in the data segment.
9 Write X86/64 ALP to perform overlapped block transfer with string specific
instructions Block containing data can be defined in the data segment.
10 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).
12 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.
13 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.
15 Study Assignment:
Motherboards are complex. Break them down, component by component, and
Understand how they work. Choosing a motherboard is a hugely important part of
building a PC. Study- Block diagram, Processor Socket, Expansion Slots, SATA, RAM,
Form Factor, BIOS, Internal Connectors, External Ports, Peripherals and Data Transfer,
Display, Audio, Networking, Overclocking, and Cooling. 4.
https://www.intel.in/content/www/in/en/support/articles/000006014/boards-and
kits/desktop-boards.html
210257.1 2 1 - 1 - - - - - - - 1 - 1
210257.2 2 1 - 1 - - - - - - - 1 - 1
210257.3 2 1 - 1 - - - - - - - - - -
INDEX
2 2 Write an X86/64 ALP to accept five 64 bit Hexadecimal numbers from user and 1,2 1,2,4,
store them in an array and display the accepted numbers 12
3 3 Write an X86/64 ALP to accept a string and to display its length. 1,2 1,2,4,
12
4 4 Write an X86/64 ALP to find the largest of given Byte/Word/Dword/64-bit 1,2 1,2,4,
numbers. 12
5 5 Write an X86/64 ALP to count the number of positive and negative numbers from 1,2 1,2,4,
the array. 12
6 6 Write X86/64 ALP to convert 4-digit Hex number into its equivalent BCD number 1,2 1,2,4,
and 5- digit BCD number into its equivalent HEX number. Make your program 12
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).
7 7 Write X86/64 ALP to detect protected mode and display the values of GDTR, 3 1,2,4
LDTR, IDTR, TR and MSW Registers also identify CPU type using CPUID
instruction.
8 8 Write X86/64 ALP to perform non-overlapped block transfer without string 1,2 1,2,4,
specific instructions. Blocks containing data can be defined in the data segment. 12
9 9 Write X86/64 ALP to perform overlapped block transfer with string specific 1,2 1,2,4,
instructions Block containing data can be defined in the data segment. 12
10 10 Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. 1,2 1,2,4,
Use successive addition and add and shift methods. (use of 64-bit registers is 12
expected).
11 11 Write X86 Assembly Language Program (ALP) to implement following OS 1,2 1,2,4,
commands 12
i) COPY, ii) TYPE Using file operations. User is supposed to provide command
line arguments
Use Assembly language/machine language to implement the problem statements using NASM
Software Required:
1. OS- 64 bit Linux Mint
2. CPU- 64 bit core-2Duo
3. Assembler Used- NASM
4. Linker Used- Ld (GNU Linker)
Assignment No.
Title
Problem Statement
Course Objectives
Outcome
Theory(in brief)
Algorithm
Test Cases
Conclusion
FAQs
Output:
ASSIGNMENT NO: 1
TITLE: To study Assembly Language Programming
OUTCOME: 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY:
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.
Advantages of Assembly Language
An understanding of assembly language provides knowledge of:
Interface of programs with OS, processor and BIOS;
Representation of data in memory and other external devices;
How processor accesses and executes instruction;
How instructions accesses and process data;
How a program access external devices.
Other advantages of using assembly language are:
It requires less memory and execution time;
It allows hardware-specific complex jobs in an easier way;
It is suitable for time-critical jobs;
Computer Engineering, MMCOE, Pune-52. 13
MP Lab Manual SE COMP, Sem-II, 2023-24
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. This differs from practice in a lot of other languages (Pascal particularly), so keep
it in mind.
Assembly Language Statements
Computer Engineering, MMCOE, Pune-52. 15
MP Lab Manual SE COMP, Sem-II, 2023-24
used the system calls sys_write and sys_exit for writing into the screen and exiting from the
program respectively.
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
FAQs:
1. MINT is how many bit operating systems?
Ans.
Ans:
ASSIGNMENT NO: 2
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
OUTCOME: 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY:
DX::AX) A single colon is used for memory addresses. XF or XF=b - A flag's value after an
instruction can be 0 or 1 and usually depends on the result of the instruction. A flag being set to
'?' by an instruction indicates that the flag is undefined after the operation.
ALGORITHM:
TEST CASES:
2 ID2 Take hard 1110000001010101 anything other than anything other than Fail
coded data and input input
display result 11111111111111111
11111111111111111
11111111111111111
11111111111111111
CONCLUSION: Hence we accepted five 64 bit Hexadecimal numbers from user and store
them in an array and display the accepted numbers
FAQs:
1. What is an Array?
Ans.
Ans.
Ans:
4. Explain DB,DW,DQ,DD
Ans:-
ASSIGNMENT NO: 3
PROBLEM STATEMENT: Write an X86/64 ALP to accept a string and to display its length.
OUTCOME: 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY:
The variable length strings can have as many characters as required. Generally, we
specify the length of the string by either of the two ways −
$ points to the byte after the last character of the string variable msg. Therefore, $-msg gives the
length of the string. We can also write
msg db 'Hello, world!',0xa ;our dear string
Alternatively, you can store strings with a trailing sentinel character to delimit a string instead of
storing the string length explicitly. The sentinel character should be a special character that does
not appear within a string.
For example −
message DB 'I am loving it!', 0
String Instructions
Each string instruction may require a source operand, a destination operand or both. For 32-bit
segments, string instructions use ESI and EDI registers to point to the source and destination
operands, respectively.
For 16-bit segments, however, the SI and the DI registers are used to point to the source and
destination, respectively.
There are five basic instructions for processing strings. They are −
● MOVS − This instruction moves 1 Byte, Word or Doubleword of data from memory
location to another.
● LODS − This instruction loads from memory. If the operand is of one byte, it is loaded
into the AL register, if the operand is one word, it is loaded into the AX register and a
doubleword is loaded into the EAX register.
● STOS − This instruction stores data from register (AL, AX, or EAX) to memory.
● CMPS − This instruction compares two data items in memory. Data could be of a byte
size, word or doubleword.
● SCAS − This instruction compares the contents of a register (AL, AX or EAX) with the
contents of an item in memory.
Each of the above instruction has a byte, word, and doubleword version, and string instructions
can be repeated by using a repetition prefix.
These instructions use the ES:DI and DS:SI pair of registers, where DI and SI registers contain
valid offset addresses that refers to bytes stored in memory. SI is normally associated with DS
(data segment) and DI is always associated with ES (extra segment).
The DS:SI (or ESI) and ES:DI (or EDI) registers point to the source and destination operands,
respectively. The source operand is assumed to be at DS:SI (or ESI) and the destination operand
at ES:DI (or EDI) in memory.
For 16-bit addresses, the SI and DI registers are used, and for 32-bit addresses, the ESI and EDI
registers are used.
ALGORITHM:
When you want to display number on screen you need to convert number from hex to ascii
format
FAQs:
Ans.
2. What is string?
Ans.
Ans:
4. Explain RESB,RESW,RESQ,RESD?
Ans:-
ASSIGNMENT NO: 4
OUTCOME: 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY:
ASCII Representation
In ASCII representation, decimal numbers are stored as string of ASCII characters. For
example, the decimal value 1234 is stored as −
31 32 33 34H
Where, 31H is ASCII value for 1, 32H is ASCII value for 2, and so on. There are four
instructions for processing numbers in ASCII representation −
● AAA − ASCII Adjust After Addition
● AAS − ASCII Adjust After Subtraction
● AAM − ASCII Adjust After Multiplication
● AAD − ASCII Adjust Before Division
These instructions do not take any operands and assume the required operand to be in the AL
register.
ALGORITHM:
TEST CASES:
CONCLUSION: Hence we accepted the numbers and find the largest number from them and
display.
FAQs:
Ans.
Ans.
Ans:
Ans:-
5. What is flag?
Ans:-
ASSIGNMENT NO: 5
TITLE: ALP to count number of positive and negative numbers from the array
PROBLEM STATEMENT: Write X86/64 ALP to count number of positive and negative numbers from
the array
OUTCOME: 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY:
The early days of digital computing were marked by a lot of competing ideas about both
hardware technology and mathematics technology (numbering systems). One of the great debates
was the format of negative numbers, with some of the era's most expert people having very
strong and different opinions. One camp supported two's complement, the system that is
dominant today. Another camp supported ones' complement, where any positive value is made
into its negative equivalent by inverting all of the bits in a word. A third group supported "sign &
magnitude" (sign-magnitude), where a value is changed from positive to negative simply by
toggling the word's sign (high-order) bit.
In mathematics, negative numbers in any base are represented by prefixing them with a −
sign. However, in computer hardware, numbers are represented in bit vectors only, without extra
symbols. The four best-known methods of extending the binary numeral system to represent
signed numbers are: sign -and- magnitude, ones' complement, two's complement, and excess-K.
Some of the alternative methods use implicit instead of explicit signs, such as negative binary,
using the base −2. Corresponding methods can be devised for other bases, whether positive,
negative, fractional, or other elaborations on such themes. There is no definitive criterion by
which any of the representations is universally superior. The representation used in most current
computing devices is two's complement
ALGORITHM:
TEST CASES:
1 ID1 Take hard coded 855h, 90ffh, 87h, Count of Positive Count of Positive Pass
data and display 88h, 8a9fh, 0afh, no.: 6 no.: 6
result 02h Count of Negative Count of Negative
no.: 1 no.: 1
2 ID2 Take hard coded 855h, 90ffh, 87h, Count of Positive Count of Positive Fail
data and display 88h, 8a9fh, 0afh, no.: 6 no.: 3
result 02h Count of Negative Count of Negative
no.: 1 no.: 4
CONCLUSION: Hence we counted and displayed the number of positive and negative numbers
from the array of signed numbers.
FAQs:
Ans.
Ans.
Ans:
4. What is Microprocessor
Ans:-
ASSIGNMENT NO: 6
TITLE: Write bit ALP to convert 4-digit HEX to BCD and 5-digit BCD to HEX.
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)
Display appropriate messages to prompt the user while accepting the input and displaying the
result.
COURSE OBJECTIVES: To understand assembly language programming instruction set
To understand different assembly directives with example
OUTCOME :1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY:
ALGORITHM :
1 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
7. Increment Count _1.
8. Repeat Till BCD NO is not zero go to step 5.
9. Pop the content of Reminder.
10. Display result by calling display procedure.
11. Decrement Count _1, till Count is not zero repeat step 9 else go to step 12.
12. Stop
2 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 di ULT variable.
9. Accept single digit from u
10. Transfer 100 to multiplier
11. Multiply accepted BCD di ULT variable.
12. Accept single digit from u
13. Transfer 10 to multiplier
14. Multiply accepted BCD digit by multiplier & add it to RESULT variable.
TEST CASES:
CONCLUSION: Hence we have executed programs to convert 4-digit HEX to BCD and 5-digit
BCD to HEX.
FAQ’s :
1. Write syntax of DIV instruction.
Ans:
Ans:
Ans:
Ans:
ASSIGNMENT NO: 7
TITLE: ALP to switch from real mode to protected mode and display the values of GDTR,
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.
OUTCOME : 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY :
When the processor is reset or powered up it is initialized in Real Mode. Real Mode has the same
base architecture as the 8086, but allows access to the 32-bit register set of the Intel386 DX. The
addressing mechanism, memory size, interrupt handling, are all identical to the Real Mode on the
80286.
unlocked when the processor operates in Protected Virtual Address Mode (Protected Mode).
Protected Mode vastly increases the linear address space to four gigabytes (2 32 bytes) and
allows
the running of virtual memory programs of almost unlimited size (64 terabytes or 2 46 bytes). In
addition Protected Mode allows the Intel386 DX to run all of the existing 8086 and 80286
protection mechanism. Protected Mode allows the use of additional instructions especially
optimized for supporting multitasking operating systems. The base architecture of the Intel386
The descriptor tables define all of the segments which are used in an Intel386 DX system. There
are three types of tables on the Intel386 DX which hold descriptors: the Global Descriptor Table,
Local Descriptor Table, and the Interrupt Descriptor Table. All of the tables are variable length
memory arrays. They can range in size between 8 bytes and 64K bytes. Each table can hold up to
8192 8 byte descriptors.
The upper 13 bits of a selector are used as an index into the descriptor table. The tables have
registers associated with them which hold the 32-bit linear base address, and the 16-bit limit of
each table. Each of the tables has a register associated with it the GDTR, LDTR, and the IDTR.
The LGDT, LLDT, and LIDT instructions, load the base and limit of the Global, Local, and
Interrupt Descriptor Tables, respectively, into the appropriate register. The SGDT, SLDT, and
SIDT instructions store the base and limit values. These tables are manipulated by the operating
system. Therefore, the load descriptor table instructions are privileged instructions. Local
Descriptor Table Register (LDTR) and Task Register (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.
CR0:
PG (Paging Enable, bit 31): The PG bit is set to enable the on-chip paging unit. It is reset to
disable the on-chip paging unit.
R (reserved, bit 4): This bit is reserved by Intel. When loading CR0 care should be taken to not
alter the value of this bit.
TS (Task Switched, bit 3): TS is automatically set whenever a task switch operation is
performed.
EM (Emulate Coprocessor, bit 2): The EMulate coprocessor bit is set to cause all coprocessor
opcodes to generate a Coprocessor Not Available fault (exception 7). It is reset to allow
coprocessor opcodes to be executed on an actual Intel387 DX coprocessor (this is the default
case after reset).
MP (Monitor Coprocessor, bit 1): The MP bit is used in conjunction with the TS bit to determine
if the WAIT opcode will generate a Coprocessor Not Available fault (exception 7) when TS = 1.
When both MP = 1 and TS = 1, the WAIT opcode generates a trap. Otherwise, the WAIT opcode
does not generate a trap. Note that TS is automatically set whenever a task switch operation is
performed.
PE (Protection Enable, bit 0): The PE bit is set to enable the Protected Mode. If PE is reset, the
processor operates again in Real Mode. PE may be set by loading MSW or CR0. PE can be reset
only by a load into CR0. Resetting the PE bit is typically part of a longer instruction sequence
needed for proper transition from Protected Mode to Real Mode.
ALGORITHM:
CONCLUSION: Hence we check the mode of operation of 80386 and read and displayed the
GDTR, IDTR, LDTR, TR and MSW with appropriate messages.
FAQs:
Ans..
2. What is TR?
Ans.
Ans:
Ans: .
ASSIGNMENT NO: 8
TITLE: Write X86/64 Assembly language program (ALP) to perform non-overlapped block
transfer.
OUTCOME : 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY
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:
2. Segment Registers,
3. Index Registers,
4. Stack Registers.
General Registers – Following are the registers that are used for general purposes in 8086
CH count high order byte (8 bit) CL count low order byte (8 bit)
DH data high order byte (8 bit) DL data low order byte (8 bit)
Segment Registers - These registers are used to calculate 20 bit address from 16 bit registers.
CS code segment (16 bit) DS data segment (16 bit) SS stack segment (16 bit)
Index Registers - These registers are used with the string instructions.
SP stack pointer (16 bit) BP base pointer (16 bit) IP instruction pointer (16 bit)
Used with SP or BP
Used with SS
The 8086 uses a 20 bit address bus but the registers are only sixteen bit. To derive twenty bit
addresses from the registers two registers are combined. Every memory reference uses one of the
four segment registers plus an offset and/or a base pointer and/or a index register. The segment
register is multiplied by sixteen (shifted to the left four bits) and added to the sixteen bit result of
the offset calculation.
The 8086 provides four segment registers for address calculations. Each segment register is
assigned a different task. The code segment register is always used with the instruction pointer
(also called the program counter) to point to the instruction that is to be executed next. The stack
segment register is always used with the stack pointer to point to the last value pushed onto the
stack. The extra segment is general purpose segment register. The data segment register is the
default register to calculate data operations, this can be over ridden by specifying the segment
register. For example mov ax,var1 would use the offset var1 and the data segment to calculate the
memory reference but mov ax,ss:var1 would use the offset var1 and the stack segment register to
calculate the memory reference.
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)
Memory Segmentation
– x386: can have 6 active segments ( CS, SS, DS, ES, FS, GS)
Program for non-overlapped and overlapped block transfer of array elements.Takes the
array elements from the user and also the number of elements to be overlapped in overlapped
transfer.Block transfer here, refers to moving of block of data within the memory to a different
location.In non-overlapped transfer we move the data to a completely new location. It is easily
accomplished by copying the data using two pointers, one data byte at a time.In overlapped
transfer the data block is shifted slightly from the present position,thus, some of the starting
elements may overlap with the old position of the last elements in the array. They are therefore
copied in reverse order.
Read 2 arrays (block) of 2 digit numbers. The numbers may be HEX or BCD. In
nonoverlapped block transfer data block is transferred in empty memory space. In overlapped
block transfer data block transferred in occupied memory space. New data will overwrite on old.
Display both block.
ALGORITHM
Non-overlapped mode
2. Initialize counter.
5. Move the contents from register into location pointed by destination register.
7. Decrement counter.
9. End.
TEST CASES:
1 ID1 Take hard coded Source block: Destination block: Destination block: Pass
data and display 11 11 11
result for Non 22 22 22
33 33 33
Overlapped
44 44 44
memory block 55 55 55
FAQ’s:
Ans:
Ans:
Ans:
Ans.
Ans.
ASSIGNMENT NO: 9
TITLE: Write X86/64 Assembly language program (ALP) to perform overlapped block transfer.
PROBLEM STATEMENT: Write X86/64 ALP to perform overlapped block transfer with
string specific instructions Block containing data can be defined in the data segment.
COURSE OBJECTIVES: To understand assembly language programming instruction set
To understand different assembly directives with example
OUTCOME : 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY-
ALGORITHM
Overlapped mode
2. Initialize counter.
5. Move the contents from variable into location pointed by destination register [di+count]
7. Decrement counter.
9. End.
TEST CASES:
1 ID3 Take hard coded Source block: Destination block: Destination block: Pass
data and display 11 11 11
result for 22 22 22
33 11 11
Overlapped
44 22 22
memory block 55 33 33
44 44
55 55
2 ID4 Take hard coded Source block: Destination block: 55 Fail
data and display 11 11 44
result for 22 22 33
33 11 22
Overlapped
44 22 11
memory block 55 33 11
44 22
55 33
FAQ’s:
Ans:
Ans:
Ans:
Ans.
Ans.
ASSIGNMENT NO: 10
OUTCOME : 1. Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY:
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
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.
In Successive addition multiplicand is added in result multiplier number of times.
Successive Addition Method for 8-bit numbers
Consider that a byte is present in the AL register and second byte is present in BL Register.
We have to multiply the in AL with the byte in BL
Multiply the number using the Successive Addition Method.
In this method, one number is accepted and other number is taken as a counter.
The first number is added with itself, till the counter decrements to zero.
Result is stored in DX register, Display the result, using display routine
In add & shift method multiplicand is added after shifting if multiplier bit is rotated
through carry generator operation is perform on multiplicand then shift multiplier towards left by
1.Sequential Shift/Add-Method
• shift register for partial product and multiplier with each cycle,
ALGORITHM :
TEST CASES:
CONCLUSION: Hence we have executed programs to perform multiplication of two 8-bit hex
numbers using successive addition and add-shift method.
FAQ’s :
1. Write shift instructions with syntax.
Ans:
Ans.
ASSIGNMENT NO: 11
TITLE: Implement x86 program for File Operation
PROBLEM STATEMENT:
Write X86 Assembly Language Program (ALP) to implement following OS commands
i) COPY, ii) TYPE Using file operations. User is supposed to provide command line arguments
OUTCOMES Understand and apply various addressing modes and instruction sets to
implement assembly language programs.
THEORY:
Stack When You Run Program
SYSTEM CALL
• OPEN File
mov rax, 2 ; 'open' syscall
syscall
• CLOSE File
mov rax,3
mov rdi,[fd_in]
syscall
ALGORITHM:
COPY:
• Open file in read mode using open interrupt.
• Read contents of file using read interrupt.
• Create another file using read interrupt change only attributes.
• Open another file using open interrupt.
• Write contents of buffer into opened file.
• Close both files using close interrupt.
TYPE:
• 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
DELETE:
• DELETE file using delete interrupt.
TEST CASES:
1 ID1 Enter program Mlpro p.txt ml.txt Correct file name Correct file name Pass
name with text correct extension correct extension
file Correct file name Correct file name
correct extension correct extension
file written file written
successfully successfully
2 ID2 Enter program Mlpro p.txt CCorrect file name Correct file name Fail
name with text mlprog.txt correct extension correct extension
file Correct file name Incorrect file name
correct extension
file written
successfully
3 ID3 Enter program Mlpro p.txt Correct file name Correct file name Pass
name with text correct extension correct extension
file file opened file opened
successfully successfully
Successfully Successfully
reading of file: reading of file:
Contents Contents
4 ID4 Enter program Mlpro Correct file name Incorrect file name Fail
name with text correct extension
file file opened
successfully
Successfully
reading of file:
Contents
CONCLUSION: All options stated above are tested and executed successfully.
FAQ's:
1. What is File Descriptor?
Ans:
Ans
Ans:
Ans:
Ans: