Experiment 1
Title
Write an X86-64 ALP to accept five 64-bit hexadecimal numbers from
user, store them in an array and display them.
Objective
To study user input/output operations and array handling in assembly
language.
Problem Statement
Accept five hexadecimal numbers from the user, store them sequentially
in memory and display the accepted numbers.
Outcomes
● Use Linux system calls
● Handle 64-bit registers
● Implement looping
● Store data in array
Hardware Requirement
● Intel/AMD Processor
● Minimum 4GB RAM
Software Requirement
● Ubuntu / Linux OS
● NASM Assembler
● LD Linker
Theory
X86-64 processor supports 64-bit registers such as RAX, RBX, RCX etc.
System calls are used for input/output operations.
Array storage is achieved by using memory addressing.
Algorithm
1. Display message.
2. Initialize counter = 5.
3. Accept number from user.
4. Store into array location.
5. Increment pointer.
6. Repeat till counter = 0.
7. Display array elements.
Program:
Output:
Conclusion:
Experiment 2
Title
Write an X86-64 Assembly Language Program to accept a string
from the user and display its length.
Objective
● To understand string handling in assembly language
● To learn Linux system calls for input and output
● To perform looping and character comparison operations
● To calculate length of a string using memory addressing
Problem Statement
Write an X86-64 assembly language program which accepts a string from
the user and calculates and displays the length of the entered string.
Outcomes
Accept string input using system calls
Traverse string using pointer concept
Implement loop and conditional instructions
Perform string length calculation logic
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux Operating System
● NASM Assembler
● LD Linker
● Terminal
Theory
A string is a sequence of characters stored in consecutive memory
locations.
In Assembly language:
● String is stored byte by byte
● Each character occupies 1 byte
● String length can be calculated by counting characters until:
o Newline character (ASCII = 10)
OR
o Null character
In Linux Assembly:
● sys_read system call is used to accept input
● Register usage:
Regis
Purpose
ter
System call
RAX
number
RDI File descriptor
RSI Buffer address
RDX Number of
Regis
Purpose
ter
bytes
Looping is used to traverse each character and increment a counter.
Algorithm
1. Start
2. Display message to enter string
3. Accept string from user
4. Initialize counter = 0
5. Load starting address of string
6. Compare character with newline
7. If equal → Stop
8. Else → Increment counter
9. Move to next character
10. Repeat Step 6
11. Display length
12. Stop
Program:
Output:
Conclusion:
Experiment 3
Title
Write an X86-64 Assembly Language Program to count the number of
positive and negative elements from a given array.
Objective
● To understand array processing in assembly language
● To learn signed number comparison
● To implement looping and conditional branching
● To perform counter based logic implementation
Problem Statement
Write an assembly language program to scan an array of signed numbers
and count how many numbers are positive and how many are negative.
Outcomes
Traverse array using pointer concept
Perform signed comparison using processor flags
Implement looping structures
Maintain separate counters for different conditions
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux Operating System
● NASM Assembler
● LD Linker
● Terminal
Theory
An array is a collection of elements stored in consecutive memory
locations.
In X86-64 assembly:
● Each QWORD element occupies 8 bytes
● Array traversal is done using pointer register (RBX / RSI)
● Signed comparison is performed using:
CMP instruction
JS (Jump if Sign) instruction
If the sign flag = 1, number is negative
If the sign flag = 0, number is positive or zero
Counters are maintained to store count of positive and negative numbers.
Algorithm
1. Start
2. Initialize positive counter = 0
3. Initialize negative counter = 0
4. Load starting address of array
5. Load array element
6. Compare element with zero
7. If sign flag set → increment negative counter
8. Else → increment positive counter
9. Move pointer to next element
10. Repeat until all elements processed
11. Stop
Program :
Output:
Conclusion:
Experiment 4
Title
Write an X86-64 Assembly Language Program to perform non-overlapped
block transfer without using string specific instructions.
Objective
● To understand block transfer concept in assembly language
● To learn memory addressing and pointer manipulation
● To implement data transfer using basic instructions
● To perform loop based memory operations
Problem Statement
Write an assembly language program to transfer a block of data from a
source memory location to a destination memory location without using
string instructions such as MOVSB, MOVSW, REP etc.
Assume that the source and destination memory blocks are non-
overlapping.
Outcomes
Perform memory-to-memory data transfer
Use pointer registers for block processing
Implement looping for repeated operations
Understand difference between string and non-string instructions
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux Operating System
● NASM Assembler
● LD Linker
● Terminal
Theory
A block transfer operation means copying a sequence of data items from
one memory location (source) to another (destination).
Types of block transfer:
Non-overlapped block transfer
● Source and destination memory regions are completely separate
● Data copying does not affect source block
Overlapped block transfer
● Source and destination blocks share common memory region
In this experiment:
● Each element is 1 byte
● Transfer is done using:
o MOV instruction
o Pointer registers (RSI → source, RDI → destination)
o Loop counter (RCX)
No string instruction is used.
Algorithm
1. Start
2. Initialize counter with number of elements
3. Load source block address in RSI
4. Load destination block address in RDI
5. Move byte from source to register
6. Move byte from register to destination
7. Increment source pointer
8. Increment destination pointer
9. Decrement counter
10. Repeat steps 5–9 till counter = 0
11. Stop
Program:
Output:
Conclusion:
Experiment 5
Title
Write an X86-64 Assembly Language Program to perform overlapped
block transfer using string specific instructions.
Objective
● To understand overlapped memory block transfer concept
● To learn string instructions in assembly language
● To study direction flag usage
● To perform efficient data movement using REP MOVSB
Problem Statement
Write an assembly language program to transfer a block of data within the
same memory region where source and destination overlap.
Use string instructions such as MOVSB along with repeat prefix.
Outcomes
Understand overlapping memory conditions
Use string instructions (MOVSB)
Use Direction Flag (CLD / STD)
Perform block transfer efficiently
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux Operating System
● NASM Assembler
● LD Linker
● Terminal
Theory
In overlapped block transfer, source and destination memory areas
partially share the same region.
Example
Initial block
Address : 1000 1001 1002 1003 1004 1005 1006 1007
Data : 11 22 33 44 55 00 00 00
If we copy first 5 bytes starting at 1000 → destination 1002, the regions
overlap.
To handle this efficiently:
● String instruction MOVSB is used
● RSI → Source pointer
● RDI → Destination pointer
● RCX → Counter
● REP prefix automatically repeats instruction
Direction Flag:
● CLD → Forward transfer
● STD → Backward transfer
Algorithm
1. Start
2. Initialize counter with number of bytes
3. Load source block address in RSI
4. Load destination block address in RDI
5. Clear direction flag for forward transfer
6. Execute REP MOVSB
7. Stop
Program
Output:
Conclusion:
Experiment 6
Title
Write an X86-64 Assembly Language Program to perform multiplication of
two 8-bit hexadecimal numbers using successive addition method only.
Objective
● To understand basic arithmetic implementation in assembly
● To learn loop-based multiplication logic
● To perform 8-bit data processing
● To implement repeated addition algorithm
Problem Statement
Write an assembly language program to multiply two 8-bit hexadecimal
numbers without using built-in multiplication instruction.
The multiplication must be performed using successive addition
technique.
Outcomes
Implement multiplication logic manually
Use loop and counter registers
Perform byte-level arithmetic operations
Store and interpret result of arithmetic operation
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux Operating System
● NASM Assembler
● LD Linker
● Terminal
Theory
Multiplication can be performed using repeated addition.
Example
5×3=5+5+5
In assembly:
● One number acts as multiplicand
● Other acts as multiplier (loop counter)
● Result is accumulated in a register or memory
Registers used:
Register Purpose
AL Multiplicand
BL Multiplier
CL Loop counter
Register Purpose
Result Stores multiplication
memory result
This method helps students understand low-level arithmetic logic
implementation.
Algorithm
1. Start
2. Load multiplicand
3. Load multiplier
4. Initialize result = 0
5. Move multiplier to counter register
6. Add multiplicand to result
7. Decrement counter
8. Repeat until counter = 0
9. Store result
10. Stop
Program
Output:
Conclusion:
Experiment 7
Title
Write an X86-64 Assembly Language Program to find the largest element
from a given array of numbers (Byte / Word / Dword / Qword).
Objective
● To understand array processing in assembly language
● To perform comparison operations
● To learn conditional branching instructions
● To implement searching algorithm at low level
Problem Statement
Write an assembly language program to scan a given array of numbers
and determine the largest element among them.
The program should work for different data sizes such as Byte, Word,
Dword and 64-bit numbers.
Outcomes
Traverse array using pointer registers
Perform comparison using CMP instruction
Implement decision making using jump instructions
Apply searching logic in assembly
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux Operating System
● NASM Assembler
● LD Linker
● Terminal
Theory
Finding the largest element is a linear search operation.
Logic:
Assume first element is largest
Compare next element with current largest
If greater → update largest
Repeat till all elements are checked
In X86-64:
● QWORD element size = 8 bytes
● Pointer increment = +8
● Loop counter maintained in RCX
Conditional jumps used:
● JG → Jump if greater
● JLE → Jump if less or equal
Algorithm
1. Start
2. Load address of array
3. Assume first element as largest
4. Initialize counter = number of elements
5. Load next element
6. Compare with largest
7. If greater → update largest
8. Move pointer to next element
9. Repeat till counter = 0
10. Display largest
11. Stop
Program
Output:
Conclusion:
Experiment 8
Title
Write a switch case driven X86-64 Assembly Language Program to
perform 64-bit hexadecimal arithmetic operations (+, −, ×, ÷) using
suitable macros.
Define separate procedure for each operation.
Objective
● To understand modular programming in assembly
● To learn macro and procedure implementation
● To perform 64-bit arithmetic operations
● To implement menu driven (switch case) logic
Problem Statement
Write an assembly language program which accepts user choice and
performs addition, subtraction, multiplication and division on two 64-bit
hexadecimal numbers.
Each arithmetic operation should be implemented using separate
procedure and repetitive tasks should be implemented using macros.
Outcomes
Implement switch-case logic in assembly
Use procedures and CALL instruction
Use macros for code reusability
Perform 64-bit arithmetic operations
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux OS
● NASM Assembler
● LD Linker
● Terminal
Theory
Macro
A macro is a group of instructions identified by a name.
It reduces code repetition.
Procedure
A procedure is a reusable block of code invoked using CALL instruction.
Switch Case Logic
In assembly, switch case is implemented using:
● CMP instruction
● Conditional jumps (JE, JNE etc.)
Arithmetic Instructions
Instructi
Operation
on
Addition ADD
Subtractio
SUB
n
Multiplicat
MUL
ion
Division DIV
64-bit registers used → RAX, RBX
Algorithm
1. Start
2. Display menu
3. Accept user choice
4. Compare choice
5. Call corresponding procedure
6. Perform arithmetic operation
7. Store result
8. Stop
Program
Output:
Conclusion:
Experient 9
Title
Write an X86-64 Assembly Language Program to convert a 4-digit
hexadecimal number into its equivalent BCD number.
Objective
● To understand number system conversion in assembly
● To learn division-based conversion technique
● To implement loop and stack usage
● To perform register manipulation
Problem Statement
Write an assembly language program to convert a given 4-digit
hexadecimal number into its decimal (BCD) equivalent.
Outcomes
Understand hexadecimal to decimal conversion logic
Use division instruction for repeated conversion
Use stack for reversing digits
Implement loop control instructions
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux Operating System
● NASM Assembler
● LD Linker
● Terminal
Theory
Hexadecimal Number System
Base = 16
Digits → 0–9 and A–F
BCD (Binary Coded Decimal)
Decimal digits are stored separately.
Example
HEX = 1234H
Decimal = 4660
BCD = 4 6 6 0
Conversion Logic
To convert HEX → Decimal:
Divide number by 10
Store remainder (decimal digit)
Continue division until quotient becomes zero
Digits are obtained in reverse order, so stack is used.
Registers used:
Regis
Purpose
ter
RAX Hex number /
Regis
Purpose
ter
Quotient
RDX Remainder
RBX Divisor (10)
RCX Counter
Algorithm
1. Start
2. Load hexadecimal number
3. Initialize divisor = 10
4. Divide number by 10
5. Push remainder onto stack
6. Increment counter
7. Repeat until quotient = 0
8. Pop digits from stack → BCD result
9. Stop
Program
Output
Conclusion
Experiment 10
Title
Write an X86-64 Assembly Language Program to convert a 5-digit BCD
number into its equivalent hexadecimal number.
Objective
● To understand BCD to hexadecimal conversion logic
● To learn multiplication-based number system conversion
● To implement looping and register operations
● To perform multi-digit arithmetic processing
Problem Statement
Write an assembly language program to convert a 5-digit BCD number
stored in memory into its equivalent hexadecimal number.
Outcomes
Understand decimal positional value logic
Use multiplication and addition instructions
Traverse digit array using pointer concept
Implement number system conversion algorithm
Hardware Requirement
● Intel / AMD 64-bit Processor
● Minimum 2 GB RAM
● Keyboard and Monitor
Software Requirement
● Ubuntu / Linux Operating System
● NASM Assembler
● LD Linker
● Terminal
Theory
BCD (Binary Coded Decimal)
In BCD, each decimal digit is stored separately.
Example
BCD digits → 1 2 3 4 5
Decimal value → 12345
Conversion Logic
To convert BCD → Decimal (then Hex):
Use positional weight method
Result = Result × 10 + Next Digit
This process is repeated for all digits.
Registers used:
Regis
Purpose
ter
Result
RAX
accumulator
Pointer to BCD
RBX
digits
RDX Multiplier (10)
RCX Digit counter
Algorithm
1. Start
2. Initialize result = 0
3. Load address of BCD digits
4. Multiply result by 10
5. Add next BCD digit
6. Move pointer to next digit
7. Decrement counter
8. Repeat until all digits processed
9. Store hexadecimal result
10. Stop
Program
Output
Conclusion