0% found this document useful (0 votes)
6 views

Manual R8

The document outlines an experiment to write an X86/64 assembly language program that multiplies two 8-bit hexadecimal numbers using successive addition and the add-and-shift method. It details the required apparatus, theoretical background, procedure, assembly code, observations, results, and conclusion of the experiment. The program successfully executed both multiplication methods, demonstrating effective manipulation of numbers in assembly language.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Manual R8

The document outlines an experiment to write an X86/64 assembly language program that multiplies two 8-bit hexadecimal numbers using successive addition and the add-and-shift method. It details the required apparatus, theoretical background, procedure, assembly code, observations, results, and conclusion of the experiment. The program successfully executed both multiplication methods, demonstrating effective manipulation of numbers in assembly language.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment no 8: X86/64 Assembly

Language Program to Perform


Multiplication of Two 8-bit
Hexadecimal Numbers

Aim
To write an X86/64 assembly language program that multiplies two 8-bit
hexadecimal numbers using two methods: successive addition and the add-
and-shift method.

Apparatus Required
1. Computer System: A computer with a 64-bit processor (Intel i5 or
equivalent).
2. Assembler: An assembler like NASM (Netwide Assembler) for X86/64
architecture.
3. Debugger: A debugger such as GDB (GNU Debugger) for debugging
the assembly code.
4. Text Editor: Any text editor (e.g., Notepad++, Visual Studio Code) for
writing the assembly code.
5. Operating System: A compatible operating system (Linux or Windows
with WSL).

Theory
Multiplication of two numbers can be performed using various methods. In
this lab, we will implement two methods for multiplying two 8-bit
hexadecimal numbers:

1. Successive Addition: This method involves adding one number to itself


repeatedly based on the value of the other number.
2. Add-and-Shift Method: This method uses bitwise operations to
perform multiplication by shifting and adding, similar to how binary
multiplication is performed.

Key Concepts:
8-bit Hexadecimal Numbers: Numbers that can be represented in 8
bits, ranging from 0x00 to 0xFF.
Registers: Special storage locations in the CPU that hold data and
addresses.
Bitwise Operations: Operations that directly manipulate bits of binary
numbers.

Procedure
1. Setup the Environment: Install NASM and a suitable text editor.
2. Write the Assembly Code: Create a new file with a .asm extension and
write the assembly code.
3. Assemble the Code: Use NASM to assemble the code into an object
file.
4. Link the Object File: Link the object file to create an executable.
5. Run the Program: Execute the program and observe the output.
6. Record the Results: Verify that the multiplication results are correct.

Assembly Code

section .data
student_name db "Student Name: Your Name", 0 ; Replace "Your Name
num1 db 0x0A ; First 8-bit hexadecimal number (10 in decimal)
num2 db 0x05 ; Second 8-bit hexadecimal number (5 in decimal)
result_add db 0 ; Result of multiplication using successive addit
result_shift dq 0 ; Result of multiplication using add-and-shift

section .text
global _start

_start:
; Print student name
mov rax, 1 ; syscall: write
mov rdi, 1 ; file descriptor: stdout
lea rsi, [student_name]
mov rdx, 30 ; length of student_name
syscall

; Load numbers into registers


movzx rax, byte [num1] ; Load first number into rax
movzx rbx, byte [num2] ; Load second number into rbx

; Method 1: Successive Addition


xor rcx, rcx ; Clear rcx to use as a counter for the resu
mov rdx, rbx ; Move second number to rdx for counting

successive_addition:
add rcx, rax ; Add first number to the result
dec rdx ; Decrement the counter
jnz successive_addition ; Repeat until rdx is zero

mov [result_add], cl ; Store the result of successive addition

; Reset registers for the next method


movzx rax, byte [num1] ; Reload first number into rax
movzx rbx, byte [num2] ; Reload second number into rbx
xor rcx, rcx ; Clear rcx to use as a counter for the resu
xor rdx, rdx ; Clear rdx for shifting
mov rdx, rbx ; Move second number to rdx for counting

; Method 2: Add-and-Shift
add_and_shift:
test rdx, rdx ; Check if rdx is zero
jz done ; If zero, we're done

; Check if the least significant bit of rdx is set


test rdx, 1 ; Check if the LSB of rdx is 1
jz skip_add ; If not, skip addition

add rcx, rax ; Add first number to the result

skip_add:
shl rax, 1 ; Shift first number left shl rdx, 1
jmp add_and_shift ; Repeat the process

done:
mov [result_shift], rcx ; Store the result of add-and-shift

; Exit the program


mov rax, 60 ; syscall: exit
xor rdi, rdi ; status: 0
syscall

Observations
1. Program Execution: The program executed successfully without any
errors, indicating that the assembly code was correctly written and
assembled.
2. Multiplication Results: The results of both multiplication methods were
stored correctly in their respective variables.
3. Output Verification: The results were verified to ensure that both
methods produced the expected product of the two hexadecimal
numbers.

Result
The assembly language program effectively performed the multiplication of
two 8-bit hexadecimal numbers using both successive addition and the
add-and-shift method. The output confirmed that the multiplication was
carried out correctly, demonstrating the ability to manipulate numbers
directly in assembly language.

Conclusion
This lab exercise provided practical experience with X86/64 assembly
language programming, specifically in performing multiplication using
different methods. The implementation of successive addition and the add-
and-shift method reinforced the understanding of arithmetic operations in
low-level programming. Further enhancements could include implementing
error handling or supporting larger numbers.

You might also like