Need the answer to parts D and F. 5.15 Write ASC assembly language programs for
ID: 3606001 • Letter: N
Question
Need the answer to parts D and F.
5.15 Write ASC assembly language programs for the following. Start programs at locations #HO, using ORG O Statement. a. Subtract an integer stored at memory location A from that at B and store the result at C. b. Read several integers from the input device one at a time and store them in a memory location start- ing at Z. The input process should stop when the integer read has a value of O. Change the program in (b) to store only positive integers at a location starting at POS. Modify the program in (b) to store the positive integers starting at POS and the negative integers starting at NEG. Location #H50 contains an address pointing to the first entry in a table of integers. The table is also in the memory and the first entry is the number of entries in the table, excluding itself. Store the maximum and minimum valued integers at memory locations MAX and MIN, respectively. SORT the entries in a table of n entries in increasing order of magnitude. Multiply integers stored at memory locations A and B and store the result in C. Assume the product is small enough and can be represented in 16 bits. Note that multiplication is the repeated addition of multiplicand to itself multiplier times. Compute the absolute value of each of the 50 integers located at the memory block starting at A and store them at the block starting at B. Read a sequence of numbers and compute their minimum, maximum, and average values. Reading a value of 0 should terminate the reading process. What problems arise in computing the average? c. d. e. f. g. h. i.Explanation / Answer
Answer:
1)
.LC0:
.string "Enter the value of N "
.LC1:
.string "%d"
.LC2:
.string "Enter the numbers "
.LC3:
.string "The numbers arranged in ascending order are given below "
.LC4:
.string "%d "
main:
pushq %rbp
movq %rsp, %rbp
subq $144, %rsp
movl $.LC0, %edi
call puts
leaq -16(%rbp), %rax
movq %rax, %rsi
movl $.LC1, %edi
movl $0, %eax
call scanf
movl $.LC2, %edi
call puts
movl $0, -4(%rbp)
.L3:
movl -16(%rbp), %eax
cmpl %eax, -4(%rbp)
jge .L2
leaq -144(%rbp), %rax
movl -4(%rbp), %edx
movslq %edx, %rdx
salq $2, %rdx
addq %rdx, %rax
movq %rax, %rsi
movl $.LC1, %edi
movl $0, %eax
call scanf
addl $1, -4(%rbp)
jmp .L3
.L2:
movl $0, -4(%rbp)
.L8:
movl -16(%rbp), %eax
cmpl %eax, -4(%rbp)
jge .L4
movl -4(%rbp), %eax
addl $1, %eax
movl %eax, -8(%rbp)
.L7:
movl -16(%rbp), %eax
cmpl %eax, -8(%rbp)
jge .L5
movl -4(%rbp), %eax
cltq
movl -144(%rbp,%rax,4), %edx
movl -8(%rbp), %eax
cltq
movl -144(%rbp,%rax,4), %eax
cmpl %eax, %edx
jle .L6
movl -4(%rbp), %eax
cltq
movl -144(%rbp,%rax,4), %eax
movl %eax, -12(%rbp)
movl -8(%rbp), %eax
cltq
movl -144(%rbp,%rax,4), %edx
movl -4(%rbp), %eax
cltq
movl %edx, -144(%rbp,%rax,4)
movl -8(%rbp), %eax
cltq
movl -12(%rbp), %edx
movl %edx, -144(%rbp,%rax,4)
.L6:
addl $1, -8(%rbp)
jmp .L7
.L5:
addl $1, -4(%rbp)
jmp .L8
.L4:
movl $.LC3, %edi
call puts
movl $0, -4(%rbp)
.L10:
movl -16(%rbp), %eax
cmpl %eax, -4(%rbp)
jge .L9
movl -4(%rbp), %eax
cltq
movl -144(%rbp,%rax,4), %eax
movl %eax, %esi
movl $.LC4, %edi
movl $0, %eax
call printf
addl $1, -4(%rbp)
jmp .L10
.L9:
movl $0, %eax
leave
ret
2)
.zero 1
.LC0:
.string "Enter two numbers: "
.LC1:
.string "Product = "
main:
pushq %rbp
movq %rsp, %rbp
subq $32, %rsp
movl $.LC0, %esi
movl std::cout, %edi
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
leaq -8(%rbp), %rax
movq %rax, %rsi
movl std::cin, %edi
call std::basic_istream<char, std::char_traits<char> >::operator>>(float&)
movq %rax, %rdx
leaq -12(%rbp), %rax
movq %rax, %rsi
movq %rdx, %rdi
call std::basic_istream<char, std::char_traits<char> >::operator>>(float&)
movss -8(%rbp), %xmm1
movss -12(%rbp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, -4(%rbp)
movl $.LC1, %esi
movl std::cout, %edi
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
movq %rax, %rdx
movl -4(%rbp), %eax
movl %eax, -20(%rbp)
movss -20(%rbp), %xmm0
movq %rdx, %rdi
call std::basic_ostream<char, std::char_traits<char> >::operator<<(float)
movl $0, %eax
leave
ret
__static_initialization_and_destruction_0(int, int):
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L5
cmpl $65535, -8(%rbp)
jne .L5
movl std::__ioinit, %edi
call std::ios_base::Init::Init()
movl $__dso_handle, %edx
movl std::__ioinit, %esi
movl std::ios_base::Init::~Init(), %edi
call __cxa_atexit
.L5:
nop
leave
ret
pushq %rbp
movq %rsp, %rbp
movl $65535, %esi
movl $1, %edi
call __static_initialization_and_destruction_0(int, int)
popq %rbp
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.