Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m trying to learn the Assembly language MIPS using the MARS simulator. The pr

ID: 3666023 • Letter: I

Question

I'm trying to learn the Assembly language MIPS using the MARS simulator. The problem I'm currently working through is: Allocate space for an array A[0..15] in the data section of your assembly code. Each array element is a 32-bit word. Write a program that will do the following two things: (1) It will first fill the nth element of the array with the value of 2An (calculate A[n] using the formula A[n]:=A[n-l]+A[n-l]). (2) It will then ask you to enter any integer value of n between 0 and 15, and out put the value of A[n].

Explanation / Answer

.Ltext0: .local _ZStL8__ioinit .comm _ZStL8__ioinit,1,1 .globl arr .bss .align 32 arr: 0000 00000000 .zero 60 00000000 00000000 00000000 00000000 .section .rodata .align 8 .LC0: 0000 456E7465 .string "Enter length of array .. choose between 1 to 15: " 72206C65 6E677468 206F6620 61727261 .LC2: 0032 74686520 .string "the value of arr[" 76616C75 65206F66 20617272 5B00 .LC3: 0044 5D206973 .string "] is : " 203A2000 .text .globl main main: .LFB971: .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 4154 pushq %r12 0006 53 pushq %rbx 0007 4883EC20 subq $32, %rsp .cfi_offset 12, -24 .cfi_offset 3, -32 .LBB2: 000b BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi 00 0010 BF000000 movl $_ZSt4cout, %edi 00 0015 E8000000 call _ZNSolsEPFRSoS_E 00 001a BE000000 movl $.LC0, %esi 00 001f 4889C7 movq %rax, %rdi 0022 E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 0027 488D45EC leaq -20(%rbp), %rax 002b 4889C6 movq %rax, %rsi 002e BF000000 movl $_ZSt3cin, %edi 00 0033 E8000000 call _ZNSirsERi 00 0038 8B5DEC movl -20(%rbp), %ebx 003b 8B45EC movl -20(%rbp), %eax 003e F20F2AC0 cvtsi2sd %eax, %xmm0 0042 48B80000 movabsq $4611686018427387904, %rax 00000000 0040 004c 660F28C8 movapd %xmm0, %xmm1 0050 488945D8 movq %rax, -40(%rbp) 0054 F20F1045 movsd -40(%rbp), %xmm0 D8 0059 E8000000 call pow 00 005e F20F2CD0 cvttsd2si %xmm0, %edx 0062 4863C3 movslq %ebx, %rax 0065 89148500 movl %edx, arr(,%rax,4) 000000 006c 8B45EC movl -20(%rbp), %eax 006f 4898 cltq 0071 8B1C8500 movl arr(,%rax,4), %ebx 000000 0078 448B65EC movl -20(%rbp), %r12d 007c BE000000 movl $.LC2, %esi 00 0081 BF000000 movl $_ZSt4cout, %edi 00 0086 E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 008b 4489E6 movl %r12d, %esi 008e 4889C7 movq %rax, %rdi 0091 E8000000 call _ZNSolsEi 00 0096 BE000000 movl $.LC3, %esi 00 009b 4889C7 movq %rax, %rdi 009e E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00 00a3 89DE movl %ebx, %esi 00a5 4889C7 movq %rax, %rdi 00a8 E8000000 call _ZNSolsEi 00 00ad B8000000 movl $0, %eax 00 .LBE2: 00b2 4883C420 addq $32, %rsp 00b6 5B popq %rbx 00b7 415C popq %r12 00b9 5D popq %rbp .cfi_def_cfa 7, 8 00ba C3 ret .cfi_endproc .LFE971: _Z41__static_initialization_and_destruction_0ii: .LFB980: 00d8 BF000000 movl $_ZStL8__ioinit, %edi 00 00dd E8000000 call _ZNSt8ios_base4InitC1Ev 00 00e2 BA000000 movl $__dso_handle, %edx 00 00e7 BE000000 movl $_ZStL8__ioinit, %esi 00 00ec BF000000 movl $_ZNSt8ios_base4InitD1Ev, %edi 00 00f1 E8000000 call __cxa_atexit 00 .cfi_startproc 00bb 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 00bc 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 00bf 4883EC10 subq $16, %rsp 00c3 897DFC movl %edi, -4(%rbp) 00c6 8975F8 movl %esi, -8(%rbp) 00c9 837DFC01 cmpl $1, -4(%rbp) 00cd 7527 jne .L3 00cf 817DF8FF cmpl $65535, -8(%rbp) FF0000 00d6 751E jne .L3 .L3: 00f6 C9 leave .cfi_def_cfa 7, 8 00f7 C3 ret .cfi_endproc .LFE980: _GLOBAL__sub_I_arr: .LFB981: .cfi_startproc 00f8 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 00f9 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 00fc BEFFFF00 movl $65535, %esi 00 0101 BF010000 movl $1, %edi 00 0106 E8B0FFFF call _Z41__static_initialization_and_destruction_0ii FF 010b 5D popq %rbp .cfi_def_cfa 7, 8 010c C3 ret .cfi_endproc .LFE981: .section .init_array,"aw" .align 8 0000 00000000 .quad _GLOBAL__sub_I_arr 00000000 .text .Letext0: