Assembly Program: 4-Digit Decimal Number Addition
This assembly program takes two 4-digit decimal numbers as input, adds them, and displays the sum using ASCII characters. The program utilizes Linux syscalls for I/O operations and program termination.
Source code
Code Explanation
The provided assembly code performs the following steps:
Conversion Function: The
convert
function is defined to convert ASCII characters to numerical digits.Program Initialization (
_start
):Displays a message asking the user to input the numbers.
Reads the first number, converts it to its numerical form, and stores it.
Reads the '+' character.
Reads the second number, converts it to its numerical form, and stores it.
Computes the sum of the two numbers.
Breaks down the sum into individual digits and displays them.
Data Section (
.data
):Contains messages used in the program.
Defines variables to store input numbers, sum, count, and temporary data.
Example
Suppose the user inputs the first number "1234" and the second number "5678".
Display:
Input:
Display:
Input:
Display:
Output:
Newline:
Program Exits.
Usage
Make sure you are running this code on a Linux environment or emulator that supports the syscalls used in the code.
Assemble the code using an appropriate assembler (e.g., NASM) and linker (e.g., LD).
Run the assembled binary to execute the program.
Follow the instructions to input two 4-digit decimal numbers.
The program will display the sum of the numbers in ASCII form.
Note: Assembly language is highly architecture-specific. Ensure you are using the appropriate assembler and platform for this code.
Last updated