Write an assembly language program in a file, hw6.asm, that will add the countin
ID: 3837405 • Letter: W
Question
Write an assembly language program in a file, hw6.asm, that will add the counting numbers from 1 up to an integer that is supplied in a word in memory. So if the integer is 5, the sum would be l + 2 + 3 + 4 + 5 rightarrow 15. The result should be written to a word in memory. If the original number is negative, it should just place this negative number into memory as the result. Additionally, it should write the character + or the character - to memory based on the status of the number given. Your data segment will thus contain something like: limit dw 48 result dw ? sign db ?Explanation / Answer
.LC0:
.string "Enter the number of integers you want to add"
.LC1:
.string "%d"
.LC2:
.string "Enter %d integers "
.LC3:
.string "Sum of entered integers = %d "
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], 0
mov edi, OFFSET FLAT:.LC0
call puts
lea rax, [rbp-12]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-12]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov DWORD PTR [rbp-8], 1
.L3:
mov eax, DWORD PTR [rbp-12]
cmp DWORD PTR [rbp-8], eax
jg .L2
lea rax, [rbp-16]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-16]
add DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-8], 1
jmp .L3
.L2:
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
mov eax, 0
leave
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.