Question: I made a program in x 8 6 6 4 assembly that reads two single digit numbers from the user, adds them and displays the

I made a program in x8664 assembly that reads two single digit numbers from the user, adds them and displays the result. But it's not working properly. These are the errors: as -o addnumbers.o addnumber.s ld -o addnumbers addnumbers.o
./addnumbers
Enter a number: E4
Enter another number: H5
Here's the total: %ld
4
When it should be:
./addnumbers
Enter a number: 4
Enter another number: 5
Here's the total: 9
Here's my code: .section .data
prompt1: .asciz "Enter a number: "
prompt2: .asciz "Enter another number: "
output: .asciz "Here's the total: %ld
"
.section .bss
.lcomm num1,8
.lcomm num2,8
.lcomm result, 8
.section .text
.globl _start
_start:
mov $1,%rdi # File descriptor: STDOUT
mov $prompt1,%rsi # Message to display
mov $18,%rdx # Length of the message
mov $1,%rax # System call number: write
syscall
mov $0,%rdi # File descriptor: STDIN
mov $num1,%rsi # Buffer to read into
mov $8,%rdx # Maximum number of bytes to read
mov $0,%rax # System call number: read
syscall
mov $1,%rdi # File descriptor: STDOUT
mov $prompt2,%rsi # Message to display
mov $24,%rdx # Length of the message
mov $1,%rax # System call number: write
syscall
mov $0,%rdi # File descriptor: STDIN
mov $num2,%rsi # Buffer to read into
mov $8,%rdx # Maximum number of bytes to read
mov $0,%rax # System call number: read
syscall
movq (num1),%rax # Load the first number into %rax
movq (num2),%rbx # Load the second number into %rbx
add %rbx,%rax # Add %rbx to %rax
movq %rax, (result) # Store the result in the 'result' variable
mov $1,%rdi # File descriptor: STDOUT
mov $output, %rsi # Message to display
mov $26,%rdx # Length of the message
mov $1,%rax # System call number: write
syscall
mov $1,%rdi # File descriptor: STDOUT
mov (result),%rsi # Result to display
mov $8,%rdx # Length of the result
mov $1,%rax # System call number: write
syscall
mov $60,%rax # System call number: exit
xor %rdi, %rdi # Exit code 0
syscall

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!