Write a program in assembly that calculates the sum of all t
Write a program in assembly that calculates the sum of all the numbers of a floating point array that are bigger than the user input. Assume you defined an array with 10 floating point elements in your program and you ask the user for a real number. The result will be shown in the output with an appropriate message.
If there are no bigger numbers than the user input in your array provide an appropriate message.
Use array A=[1.35 2.67 3.566 4.56 5.98 9.43 12.34 15.54 23.87 34.33 ] as the floating point array.
For example:
Please give a real number: 16.75
The answer is: 58.2
Solution
.Ltext0: .section .rodata .LC1: 0000 456E7465 .string \"Enter the value of N \" 72207468 65207661 6C756520 6F66204E .LC2: 0016 256400 .string \"%d\" 0019 00000000 .align 8 000000 .LC3: 0020 456E7465 .string \"Enter %d numbers (-ve, +ve and zero) \ \" 72202564 206E756D 62657273 20282D76 .LC4: 0047 496E7075 .string \"Input array elements \" 74206172 72617920 656C656D 656E7473 .LC5: 005d 252B3364 .string \"%+3d\ \" 0A00 0063 00000000 .align 8 00 .LC6: 0068 0A205375 .string \"\ Sum of all negative numbers = %d\ \" 6D206F66 20616C6C 206E6567 61746976 008d 000000 .align 8 .LC7: 0090 53756D20 .string \"Sum of all positive numbers = %d\ \" 6F662061 6C6C2070 6F736974 69766520 00b3 00000000 .align 8 00 .LC8: 00b8 0A204176 .string \"\ Average of all input numbers = %.2f\ \" 65726167 65206F66 20616C6C 20696E70 .text .globl main main: .LFB0: .cfi_startproc 0000 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0001 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0004 4883EC50 subq $80, %rsp 0008 64488B04 movq %fs:40, %rax 25280000 00 0011 488945F8 movq %rax, -8(%rbp) 0015 31C0 xorl %eax, %eax 0017 C745C000 movl $0, -64(%rbp) 000000 001e C745C400 movl $0, -60(%rbp) 000000 0025 660FEFC0 pxor %xmm0, %xmm0 0029 F30F1145 movss %xmm0, -56(%rbp) C8 002e BF000000 movl $.LC1, %edi 00 0033 E8000000 call puts 00 0038 488D45B8 leaq -72(%rbp), %rax 003c 4889C6 movq %rax, %rsi 003f BF000000 movl $.LC2, %edi 00 0044 B8000000 movl $0, %eax 00 0049 E8000000 call __isoc99_scanf 00 004e 8B45B8 movl -72(%rbp), %eax 0051 89C6 movl %eax, %esi 0053 BF000000 movl $.LC3, %edi 00 0058 B8000000 movl $0, %eax 00 005d E8000000 call printf 00 0062 C745BC00 movl $0, -68(%rbp) 000000 0069 EB27 jmp .L2 .L3: 008e 8345BC01 addl $1, -68(%rbp) 006b 488D45D0 leaq -48(%rbp), %rax 006f 8B55BC movl -68(%rbp), %edx 0072 4863D2 movslq %edx, %rdx 0075 48C1E202 salq $2, %rdx 0079 4801D0 addq %rdx, %rax 007c 4889C6 movq %rax, %rsi 007f BF000000 movl $.LC2, %edi 00 0084 B8000000 movl $0, %eax 00 0089 E8000000 call __isoc99_scanf 00 .L2: 0092 8B45B8 movl -72(%rbp), %eax 0095 3945BC cmpl %eax, -68(%rbp) 0098 7CD1 jl .L3 009a BF000000 movl $.LC4, %edi 00 009f E8000000 call puts 00 00a4 C745BC00 movl $0, -68(%rbp) 000000 00ab EB1E jmp .L4 .L5: 00c7 8345BC01 addl $1, -68(%rbp) 00ad 8B45BC movl -68(%rbp), %eax 00b0 4898 cltq 00b2 8B4485D0 movl -48(%rbp,%rax,4), %eax 00b6 89C6 movl %eax, %esi 00b8 BF000000 movl $.LC5, %edi 00 00bd B8000000 movl $0, %eax 00 00c2 E8000000 call printf 00 .L4: 00cb 8B45B8 movl -72(%rbp), %eax 00ce 3945BC cmpl %eax, -68(%rbp) 00d1 7CDA jl .L5 00d3 C745BC00 movl $0, -68(%rbp) 000000 00da EB57 jmp .L6 .L10: 00dc 8B45BC movl -68(%rbp), %eax 00df 4898 cltq 00e1 8B4485D0 movl -48(%rbp,%rax,4), %eax 00e5 85C0 testl %eax, %eax 00e7 790E jns .L7 00e9 8B45BC movl -68(%rbp), %eax 00ec 4898 cltq 00ee 8B4485D0 movl -48(%rbp,%rax,4), %eax 00f2 0145C0 addl %eax, -64(%rbp) 00f5 EB19 jmp .L8 .L7: 00f7 8B45BC movl -68(%rbp), %eax 00fa 4898 cltq 00fc 8B4485D0 movl -48(%rbp,%rax,4), %eax 0100 85C0 testl %eax, %eax 0102 7E0C jle .L8 0104 8B45BC movl -68(%rbp), %eax 0107 4898 cltq 0109 8B4485D0 movl -48(%rbp,%rax,4), %eax 010d 0145C4 addl %eax, -60(%rbp) .L8: 012f 8345BC01 addl $1, -68(%rbp) 0110 8B45BC movl -68(%rbp), %eax 0113 4898 cltq 0115 8B4485D0 movl -48(%rbp,%rax,4), %eax 0119 660FEFC0 pxor %xmm0, %xmm0 011d F30F2AC0 cvtsi2ss %eax, %xmm0 0121 F30F104D movss -56(%rbp), %xmm1 C8 0126 F30F58C1 addss %xmm1, %xmm0 012a F30F1145 movss %xmm0, -56(%rbp) C8 .L6: 0133 8B45B8 movl -72(%rbp), %eax 0136 3945BC cmpl %eax, -68(%rbp) 0139 7CA1 jl .L10 013b 8B45B8 movl -72(%rbp), %eax 013e 660FEFC0 pxor %xmm0, %xmm0 0142 F30F2AC0 cvtsi2ss %eax, %xmm0 0146 F30F104D movss -56(%rbp), %xmm1 C8 014b F30F5EC8 divss %xmm0, %xmm1 014f 0F28C1 movaps %xmm1, %xmm0 0152 F30F1145 movss %xmm0, -52(%rbp) CC 0157 8B45C0 movl -64(%rbp), %eax 015a 89C6 movl %eax, %esi 015c BF000000 movl $.LC6, %edi 00 0161 B8000000 movl $0, %eax 00 0166 E8000000 call printf 00 016b 8B45C4 movl -60(%rbp), %eax 016e 89C6 movl %eax, %esi 0170 BF000000 movl $.LC7, %edi 00 0175 B8000000 movl $0, %eax 00 017a E8000000 call printf 00 017f F30F5A45 cvtss2sd -52(%rbp), %xmm0 CC 0184 BF000000 movl $.LC8, %edi 00 0189 B8010000 movl $1, %eax 00 018e E8000000 call printf 00 0193 90 nop 0194 488B45F8 movq -8(%rbp), %rax 0198 64483304 xorq %fs:40, %rax 25280000 00 01a1 7405 je .L11 01a3 E8000000 call __stack_chk_fail 00 .L11: 01a8 C9 leave .cfi_def_cfa 7, 8 01a9 C3 ret .cfi_endproc .LFE0: .Letext0:
