This program manages user data using NASM for 32-bit architecture. Follow the steps below to compile and link the assembly code (project.asm):
- Open a command prompt or terminal and navigate to the directory containing project.asm.
- Run the following commands:
nasm -f elf32 -g -F dwarf project.asm -o project.o ld -m elf_i386 project.o -o executable
- Explanation:
nasm
: NASM assembler command.-f elf32
: Specifies 32-bit ELF architecture.-g
: Includes debugging symbols in the object file.-F dwarf
: Specifies DWARF debugging information format.project.asm
: Input assembly code file.-o project.o
: Output filename for the object file.ld
: Linker command.-m elf_i386
: Specifies 32-bit Intel x86 architecture.project.o
: Object file created by NASM.-o executable
: Output filename for the final executable file.
-
Initial Setup:
layout asm
: Sets the GDB display layout to show assembly code alongside other information.layout regs
: Displays the register values in the layout.set disassembly-flavor intel
: Specifies that you want to disassemble the code in Intel syntax (common for x86 architecture).
-
Loading the Program:
file executable
: Loads the executable file (generated by NASM) into GDB for debugging.
-
Debugging Commands:
step
: Executes the next instruction in the program, stepping through line by line.break [line]
: Sets a breakpoint at the specified line number in the assembly code. Execution will pause when it reaches that line.delete [breakpoint_number]
: Removes the breakpoint with the given number.info breakpoint
: Lists all currently set breakpoints and their information.print (casting)[variable-name]
: Prints the value of a variable after potentially casting it to a specific data type. Casting ensures GDB interprets the value correctly.display (casting)[variable-name]
: Continuously displays the value of a variable and updates it as the program executes. Casting is again helpful for proper interpretation.
Upon running project.asm, you'll encounter a menu with the following options:
- Create User
- Display All Users
- Display User by ID
- Display Youngest User
- Quit
Input Requirements:
- Enter a number between 1 and 5 corresponding to your desired action.
- Any other input will trigger an "Invalid Input" message.
Specific Actions:
- Create User: Enter the user's name and age separated by a space.
- Display All Users: View all created users.
- Display User by ID: Enter the user's ID to display their details.
- Display Youngest User: View the youngest user's details.
- Quit: Exit the program.
Exceptions:
- The program handles invalid input and user data scenarios with appropriate error messages.
- User data is stored in two string arrays:
name_array
andage_array
. - User IDs are implicit and determined by the position within the arrays.
- Main loop manages user actions and displays the menu.
- User actions include creating users, displaying user information, and quitting.