Answered step by step
Verified Expert Solution
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 x 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: E
Enter another number: H
Here's the total: ld
When it should be:
addnumbers
Enter a number:
Enter another number:
Here's the total:
Here's my code: section data
prompt: asciz "Enter a number:
prompt: asciz "Enter another number:
output: asciz "Here's the total: ld
section bss
lcomm num
lcomm num
lcomm result,
section text
globl start
start:
mov $rdi # File descriptor: STDOUT
mov $promptrsi # Message to display
mov $rdx # Length of the message
mov $rax # System call number: write
syscall
mov $rdi # File descriptor: STDIN
mov $numrsi # Buffer to read into
mov $rdx # Maximum number of bytes to read
mov $rax # System call number: read
syscall
mov $rdi # File descriptor: STDOUT
mov $promptrsi # Message to display
mov $rdx # Length of the message
mov $rax # System call number: write
syscall
mov $rdi # File descriptor: STDIN
mov $numrsi # Buffer to read into
mov $rdx # Maximum number of bytes to read
mov $rax # System call number: read
syscall
movq numrax # Load the first number into rax
movq numrbx # Load the second number into rbx
add rbxrax # Add rbx to rax
movq rax, result # Store the result in the 'result' variable
mov $rdi # File descriptor: STDOUT
mov $output, rsi # Message to display
mov $rdx # Length of the message
mov $rax # System call number: write
syscall
mov $rdi # File descriptor: STDOUT
mov resultrsi # Result to display
mov $rdx # Length of the result
mov $rax # System call number: write
syscall
mov $rax # System call number: exit
xor rdi, rdi # Exit code
syscall
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started