Make an Assembly Program to finish the following tasks: - Use Loop control statement to…
- User
Make an Assembly Program to finish the following tasks:
- Use Loop control statement to sum the following numbers up, and store the result in a 8-byte qSum variable. Each number has 8 bytes.
5+10+15+20+…+100
- Use Loop control statement to push each number onto the stack (Steps 1 and 2 can be in the same loop)
- After steps 1 and 2, use another loop to pop each number from the stack to an array (qArray). The array should contain a reversed order of numbers, such as 100, 95, 90,…15,10,5.
USe this code as a template:
section .data
EXIT_SUCCESS equ 0 SYS_exit equ 60
numbers dq 121, 122, 123, 124, 125 len dq 5
section .text global _start _start:
codemov rcx, qword [len] mov rbx, numbers mov r12, 0 mov rax, 0pushLoop: push qword [rbx+r12*8] inc r12 loop pushLoop
codemov rcx, qword [len] mov rbx, numbers mov r12, 0popLoop: pop rax mov qword [rbx+r12*8], rax inc r12 loop popLoop
last: mov rax, SYS_exit mov rdi, EXIT_SUCCESS syscall
- Assistant
section .data EXIT_SUCCESS equ 0 SYS_exit equ 60
; Define the numbers to be summed numbers dq 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 len dq 20
; Define the sum variable qSum dq 0
; Define the array to store the reversed order qArray dq 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
section .text global _start _start:
code