Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions