(ASSEMBLY LANGUAGE) Use the MARS (MIPS) assembler, or equivalent, to develop a p
ID: 3676359 • Letter: #
Question
(ASSEMBLY LANGUAGE)
Use the MARS (MIPS) assembler, or equivalent, to develop a program that will do the following:
1.Write a program that calculates the summation of a number using a loop (iterative). For example if the input is 10, your program will add the numbers 10, 9, 8, ….., 2, and 1 and return a result of 55.
2.Now create a subprogram that iteratively finds the factorial of a number. Make sure and follow all saving and restoring conventions regarding registers of the series $s, $sp, $ra, etc.
3.Create a subprogram that calculates the summation of a number using recursion. Make sure and follow all saving and restoring conventions regarding registers of the series $s, $sp, $ra, etc.
4.Write a program that allocates enough memory to hold 20 integers. Load that memory with consecutive integers from 1 to 20. Generate a sum of those integers by adding the numbers in pairs to the sum using the following pairing scheme. Add the first number in the array to the last number, add the second number in the array to the second to last and so forth. When all 10 number pairs have been added, divide the sum by 2 and print out the result.
Again, remember to preserve $s registers for your non recursive calls, and $s, $sp, and $ra registers for the recursive calls.
Explanation / Answer
1)
Ltext0:
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.globl main
main:
LFB971:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
.LBB2:
movl $0, -8(%rbp)
.LBB3:
movl $10, -4(%rbp)
jmp .L2
.L3:
subl $1, -4(%rbp)
movl -4(%rbp), %eax
addl %eax, -8(%rbp)
.L2:
cmpl $0, -4(%rbp)
jg .L3
.LBE3:
movl -8(%rbp), %eax
movl %eax, %esi
movl $_ZSt4cout, %edi
call _ZNSolsEi
.LBE2:
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE971:
_Z41__static_initialization_and_destruction_0ii:
.LFB972:
movl $_ZStL8__ioinit, %edi
call _ZNSt8ios_base4InitC1Ev
movl $__dso_handle, %edx
movl $_ZStL8__ioinit, %esi
movl $_ZNSt8ios_base4InitD1Ev, %edi
call __cxa_atexit
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L5
cmpl $65535, -8(%rbp)
jne .L5
.L5:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE972:
_GLOBAL__sub_I_main:
.LFB973:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE973:
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I_main
.text
.Letext0:
2) .Ltext0:
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.globl main
main:
.LFB971:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
.LBB2:
movl $1, -12(%rbp)
movl $5, -4(%rbp)
.LBB3:
movl -4(%rbp), %eax
movl %eax, -8(%rbp)
jmp .L2
.L3:
subl $1, -8(%rbp)
movl -12(%rbp), %eax
imull -8(%rbp), %eax
movl %eax, -12(%rbp)
.L2:
cmpl $0, -8(%rbp)
jg .L3
.LBE3:
movl -12(%rbp), %eax
movl %eax, %esi
movl $_ZSt4cout, %edi
call _ZNSolsEi
.LBE2:
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE971:
_Z41__static_initialization_and_destruction_0ii:
.LFB972:
movl $_ZStL8__ioinit, %edi
call _ZNSt8ios_base4InitC1Ev
movl $__dso_handle, %edx
movl $_ZStL8__ioinit, %esi
movl $_ZNSt8ios_base4InitD1Ev, %edi
call __cxa_atexit
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L5
cmpl $65535, -8(%rbp)
jne .L5
.L5:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE972:
_GLOBAL__sub_I_main:
.LFB973:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE973:
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I_main
.text
.Letext0:
3)
Ltext0:
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.globl main
main:
LFB971:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
.LBB2:
movl $0, -8(%rbp)
.LBB3:
movl $10, -4(%rbp)
jmp .L2
.L3:
subl $1, -4(%rbp)
movl -4(%rbp), %eax
addl %eax, -8(%rbp)
.L2:
cmpl $0, -4(%rbp)
jg .L3
.LBE3:
movl -8(%rbp), %eax
movl %eax, %esi
movl $_ZSt4cout, %edi
call _ZNSolsEi
.LBE2:
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE971:
_Z41__static_initialization_and_destruction_0ii:
.LFB972:
movl $_ZStL8__ioinit, %edi
call _ZNSt8ios_base4InitC1Ev
movl $__dso_handle, %edx
movl $_ZStL8__ioinit, %esi
movl $_ZNSt8ios_base4InitD1Ev, %edi
call __cxa_atexit
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L5
cmpl $65535, -8(%rbp)
jne .L5
.L5:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE972:
_GLOBAL__sub_I_main:
.LFB973:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE973:
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I_main
.text
.Letext0:
4) .Ltext0:
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.globl main
main:
.LFB971:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
.LBB2:
movl $1, -12(%rbp)
movl $5, -4(%rbp)
.LBB3:
movl -4(%rbp), %eax
movl %eax, -8(%rbp)
jmp .L2
.L3:
subl $1, -8(%rbp)
movl -12(%rbp), %eax
imull -8(%rbp), %eax
movl %eax, -12(%rbp)
.L2:
cmpl $0, -8(%rbp)
jg .L3
.LBE3:
movl -12(%rbp), %eax
movl %eax, %esi
movl $_ZSt4cout, %edi
call _ZNSolsEi
.LBE2:
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE971:
_Z41__static_initialization_and_destruction_0ii:
.LFB972:
movl $_ZStL8__ioinit, %edi
call _ZNSt8ios_base4InitC1Ev
movl $__dso_handle, %edx
movl $_ZStL8__ioinit, %esi
movl $_ZNSt8ios_base4InitD1Ev, %edi
call __cxa_atexit
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L5
cmpl $65535, -8(%rbp)
jne .L5
.L5:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE972:
_GLOBAL__sub_I_main:
.LFB973:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE973:
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I_main
.text
.Letext0: .cfi_offset 6, -16
0001 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0004 4883EC10 subq $16, %rsp
.LBB2:
0008 C745F401 movl $1, -12(%rbp)
000000
000f C745FC05 movl $5, -4(%rbp)
000000
.LBB3:
0016 8B45FC movl -4(%rbp), %eax
0019 8945F8 movl %eax, -8(%rbp)
001c EB0E jmp .L2
.L3:
0028 836DF801 subl $1, -8(%rbp)
001e 8B45F4 movl -12(%rbp), %eax
0021 0FAF45F8 imull -8(%rbp), %eax
0025 8945F4 movl %eax, -12(%rbp)
.L2:
002c 837DF800 cmpl $0, -8(%rbp)
0030 7FEC jg .L3
.LBE3:
0032 8B45F4 movl -12(%rbp), %eax
0035 89C6 movl %eax, %esi
0037 BF000000 movl $_ZSt4cout, %edi
00
003c E8000000 call _ZNSolsEi
00
.LBE2:
0041 B8000000 movl $0, %eax
00
0046 C9 leave
.cfi_def_cfa 7, 8
0047 C3 ret
.cfi_endproc
.LFE971:
_Z41__static_initialization_and_destruction_0ii:
.LFB972:
0065 BF000000 movl $_ZStL8__ioinit, %edi
00
006a E8000000 call _ZNSt8ios_base4InitC1Ev
00
006f BA000000 movl $__dso_handle, %edx
00
0074 BE000000 movl $_ZStL8__ioinit, %esi
00
0079 BF000000 movl $_ZNSt8ios_base4InitD1Ev, %edi
00
007e E8000000 call __cxa_atexit
00
.cfi_startproc
0048 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0049 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
004c 4883EC10 subq $16, %rsp
0050 897DFC movl %edi, -4(%rbp)
0053 8975F8 movl %esi, -8(%rbp)
0056 837DFC01 cmpl $1, -4(%rbp)
005a 7527 jne .L5
005c 817DF8FF cmpl $65535, -8(%rbp)
FF0000
0063 751E jne .L5
.L5:
0083 C9 leave
.cfi_def_cfa 7, 8
0084 C3 ret
.cfi_endproc
.LFE972:
_GLOBAL__sub_I_main:
.LFB973:
.cfi_startproc
0085 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0086 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0089 BEFFFF00 movl $65535, %esi
00
008e BF010000 movl $1, %edi
00
0093 E8B0FFFF call _Z41__static_initialization_and_destruction_0ii
FF
0098 5D popq %rbp
.cfi_def_cfa 7, 8
0099 C3 ret
.cfi_endproc
.LFE973:
.section .init_array,"aw"
.align 8
0000 00000000 .quad _GLOBAL__sub_I_main
00000000
.text
.Letext0:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.