Manual R8
Manual R8
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:
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
successive_addition:
add rcx, rax ; Add first number to the result
dec rdx ; Decrement the counter
jnz successive_addition ; Repeat until rdx is zero
; Method 2: Add-and-Shift
add_and_shift:
test rdx, rdx ; Check if rdx is zero
jz done ; If zero, we're done
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
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.