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: 3665969 • 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 2^n (calculate A[n] using the formula A[n]:=A[n-1]+A[n-1]). (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

Answer:

     .Ltext0:
        .local   _ZStL8__ioinit
        .comm   _ZStL8__ioinit,1,1
        .section   .rodata
        .align 8
    .LC0:
0000 456E7465        .string   "Enter number of elements you want to insert i.e n value of array "

0042 00000000        .align 8
0000
    .LC1:
0048 456E7465        .string   "Enter element between 0 and 15:"

        .align 8
    .LC2:
0068 56616C75        .string   "Value of n'th element of array is:"
    .LC3:
008b 4F757470        .string   "Output Value of A[n] is "

        .text
        .globl   main
    main:
    .LFB1055:
        .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 53        pushq   %rbx
0005 4883EC68        subq   $104, %rsp
        .cfi_offset 3, -24
    .LBB2:
0009 BE000000        movl   $.LC0, %esi

000e BF000000        movl   $_ZSt4cout, %edi

0013 E8000000        call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

0018 488D45A8        leaq   -88(%rbp), %rax
001c 4889C6        movq   %rax, %rsi
001f BF000000        movl   $_ZSt3cin, %edi

0024 E8000000        call   _ZNSirsERi

0029 8B5DA8        movl   -88(%rbp), %ebx
002c 8B45A8        movl   -88(%rbp), %eax
002f BE020000        movl   $2, %esi

0034 89C7        movl   %eax, %edi
0036 E8000000        call   _ZSt3powIiiEN9__gnu_cxx11__promote_2IT_T0_NS0_9__promoteIS2_XsrSt12__is_integerIS2_E7__valueE

003b F20F2CD0        cvttsd2si   %xmm0, %edx
003f 4863C3        movslq   %ebx, %rax
0042 895485B0        movl   %edx, -80(%rbp,%rax,4)
0046 C745AC00        movl   $0, -84(%rbp)
000000
004d EB31        jmp   .L2
    .L3:
007c 8345AC01        addl   $1, -84(%rbp)
004f BE000000        movl   $.LC1, %esi

0054 BF000000        movl   $_ZSt4cout, %edi

0059 E8000000        call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

005e 488D45B0        leaq   -80(%rbp), %rax
0062 8B55AC        movl   -84(%rbp), %edx
0065 4863D2        movslq   %edx, %rdx
0068 48C1E202        salq   $2, %rdx
006c 4801D0        addq   %rdx, %rax
006f 4889C6        movq   %rax, %rsi
0072 BF000000        movl   $_ZSt3cin, %edi

0077 E8000000        call   _ZNSirsERi

    .L2:
0080 8B45A8        movl   -88(%rbp), %eax
0083 3945AC        cmpl   %eax, -84(%rbp)
0086 7CC7        jl   .L3
0088 8B45A8        movl   -88(%rbp), %eax
008b BE020000        movl   $2, %esi

0090 89C7        movl   %eax, %edi
0092 E8000000        call   _ZSt3powIiiEN9__gnu_cxx11__promote_2IT_T0_NS0_9__promoteIS2_XsrSt12__is_integerIS2_E7__valueE

0097 F20F1145        movsd   %xmm0, -104(%rbp)

009c 488B5D98        movq   -104(%rbp), %rbx
00a0 BE000000        movl   $.LC2, %esi

00a5 BF000000        movl   $_ZSt4cout, %edi

00aa E8000000        call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

00af 48895D98        movq   %rbx, -104(%rbp)
00b3 F20F1045        movsd   -104(%rbp), %xmm0

00b8 4889C7        movq   %rax, %rdi
00bb E8000000        call   _ZNSolsEd

00c0 BE000000        movl   $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi

00c5 4889C7        movq   %rax, %rdi
00c8 E8000000        call   _ZNSolsEPFRSoS_E

00cd 8B45A8        movl   -88(%rbp), %eax
00d0 4898        cltq
00d2 8B5C85B0        movl   -80(%rbp,%rax,4), %ebx
00d6 BE000000        movl   $.LC3, %esi

00db BF000000        movl   $_ZSt4cout, %edi

00e0 E8000000        call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

00e5 89DE        movl   %ebx, %esi
00e7 4889C7        movq   %rax, %rdi
00ea E8000000        call   _ZNSolsEi

00ef BE000000        movl   $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi

00f4 4889C7        movq   %rax, %rdi
00f7 E8000000        call   _ZNSolsEPFRSoS_E

00fc B8000000        movl   $0, %eax

    .LBE2:
0101 4883C468        addq   $104, %rsp
0105 5B        popq   %rbx
0106 5D        popq   %rbp
        .cfi_def_cfa 7, 8
0107 C3        ret
        .cfi_endproc
    .LFE1055:
       
    .LFB1057:
        .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 4883EC10        subq   $16, %rsp
0008 897DFC        movl   %edi, -4(%rbp)
000b 8975F8        movl   %esi, -8(%rbp)
    .LBB3:
000e F20F2A4D        cvtsi2sd   -8(%rbp), %xmm1

0013 F20F2A45        cvtsi2sd   -4(%rbp), %xmm0

0018 E8000000        call   pow

001d F20F1145        movsd   %xmm0, -16(%rbp)

0022 488B45F0        movq   -16(%rbp), %rax
    .LBE3:
0026 488945F0        movq   %rax, -16(%rbp)
002a F20F1045        movsd   -16(%rbp), %xmm0

002f C9        leave
        .cfi_def_cfa 7, 8
0030 C3        ret
        .cfi_endproc
    .LFE1057:
        .text
    _Z41__static_initialization_and_destruction_0ii:
    .LFB1066:
0125 BF000000        movl   $_ZStL8__ioinit, %edi

012a E8000000        call   _ZNSt8ios_base4InitC1Ev

012f BA000000        movl   $__dso_handle, %edx

0134 BE000000        movl   $_ZStL8__ioinit, %esi

0139 BF000000        movl   $_ZNSt8ios_base4InitD1Ev, %edi

013e E8000000        call   __cxa_atexit

        .cfi_startproc
0108 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0109 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6
010c 4883EC10        subq   $16, %rsp
0110 897DFC        movl   %edi, -4(%rbp)
0113 8975F8        movl   %esi, -8(%rbp)
0116 837DFC01        cmpl   $1, -4(%rbp)
011a 7527        jne   .L7
011c 817DF8FF        cmpl   $65535, -8(%rbp)

0123 751E        jne   .L7
    .L7:
0143 C9        leave
        .cfi_def_cfa 7, 8
0144 C3        ret
        .cfi_endproc
    .LFE1066:
    _GLOBAL__sub_I_main:
    .LFB1067:
        .cfi_startproc
0145 55        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
0146 4889E5        movq   %rsp, %rbp
        .cfi_def_cfa_register 6
0149 BEFFFF00        movl   $65535, %esi

014e BF010000        movl   $1, %edi

0153 E8B0FFFF        call   _Z41__static_initialization_and_destruction_0ii

0158 5D        popq   %rbp
        .cfi_def_cfa 7, 8
0159 C3        ret
        .cfi_endproc
    .LFE1067:
        .section   .init_array,"aw"
        .align 8
0000 00000000        .quad   _GLOBAL__sub_I_main

        .text
    .Letext0: