Write simple MIPS assembly code and simulate it using the simulator that was int
ID: 3688670 • Letter: W
Question
Write simple MIPS assembly code and simulate it using the simulator that was introduced in the lab (QtSpim). Write and execute a program that will copy a given 12 elements array into another. Both arrays are in memory. The first array should contain {0, 1, 2, 3, 4,..., 10, 11} and start at 0x 10010000. The second array should start at the end of the first array. Write and execute a program that finds the minimum of a given set of elements by looping over the set. The elements are stored in memory starting at 0x10010000 and contain {45, 56, 11, 1, 67, 42, 9, 34, 12, 11, 45}. Write and execute a program to add a and b, leaving the result in an leaving the b unmodified. Both a and b are 10 elements arrays stored in memory starting at 0x10010000. Lab Assignment: Provide comments throughout your code. Write a report, which includes: MIPS Code for each program Output Screen for registers/console for each program. Conclusion.Explanation / Answer
Answer:
1.
.Ltext0:
.section .rodata
.LC0:
0000 0A456E74 .string " Enter the values :"
.LC1:
0014 256400 .string "%d"
.LC2:
0017 54686520 .string "The copied array is :"
.LC3:
002d 0A617272 .string " arr2[%d] = %d"
.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 4881EC10 subq $272, %rsp
000b 64488B04 movq %fs:40, %rax
0014 488945F8 movq %rax, -8(%rbp)
0018 31C0 xorl %eax, %eax
001a BF000000 movl $.LC0, %edi
001f B8000000 movl $0, %eax
0024 E8000000 call printf
0029 C785FCFE movl $0, -260(%rbp)
0033 EB30 jmp .L2
.L3:
005e 8385FCFE addl $1, -260(%rbp)
0035 488D8500 leaq -256(%rbp), %rax
003c 8B95FCFE movl -260(%rbp), %edx
0042 4863D2 movslq %edx, %rdx
0045 48C1E202 salq $2, %rdx
0049 4801D0 addq %rdx, %rax
004c 4889C6 movq %rax, %rsi
004f BF000000 movl $.LC1, %edi
0054 B8000000 movl $0, %eax
0059 E8000000 call __isoc99_scanf
.L2:
0065 83BDFCFE cmpl $12, -260(%rbp)
006c 7EC7 jle .L3
006e C785FCFE movl $0, -260(%rbp)
0078 EB22 jmp .L4
.L5:
0095 8385FCFE addl $1, -260(%rbp)
007a 8B85FCFE movl -260(%rbp), %eax
0080 4898 cltq
0082 8B948500 movl -256(%rbp,%rax,4), %edx
0089 8B85FCFE movl -260(%rbp), %eax
008f 4898 cltq
0091 89548580 movl %edx, -128(%rbp,%rax,4)
.L4:
009c 83BDFCFE cmpl $12, -260(%rbp)
00a3 7ED5 jle .L5
00a5 BF000000 movl $.LC2, %edi
00aa B8000000 movl $0, %eax
00af E8000000 call printf
00b4 C785FCFE movl $0, -260(%rbp)
00be EB2A jmp .L6
.L7:
00e3 8385FCFE addl $1, -260(%rbp)
00c0 8B85FCFE movl -260(%rbp), %eax
00c6 4898 cltq
00c8 8B548580 movl -128(%rbp,%rax,4), %edx
00cc 8B85FCFE movl -260(%rbp), %eax
00d2 89C6 movl %eax, %esi
00d4 BF000000 movl $.LC3, %edi
00d9 B8000000 movl $0, %eax
00de E8000000 call printf
.L6:
00ea 83BDFCFE cmpl $12, -260(%rbp)
00f1 7ECD jle .L7
00f3 B8000000 movl $0, %eax
00f8 488B4DF8 movq -8(%rbp), %rcx
00fc 6448330C xorq %fs:40, %rcx
0105 7405 je .L9
0107 E8000000 call __stack_chk_fail
.L9:
010c C9 leave
.cfi_def_cfa 7, 8
010d C3 ret
.cfi_endproc
.LFE0:
.Letext0:
2.
.Ltext0:
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.section .rodata
.LC0:
0000 4D696E69 .string "Minimum number: "
.text
.globl main
main:
.LFB1021:
.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
0011 488945F8 movq %rax, -8(%rbp)
0015 31C0 xorl %eax, %eax
0017 488D55C0 leaq -64(%rbp), %rdx
001b B8000000 movl $0, %eax
0020 B9060000 movl $6, %ecx
0025 4889D7 movq %rdx, %rdi
0028 F348AB rep stosq
002b 4889FA movq %rdi, %rdx
002e 8902 movl %eax, (%rdx)
0030 4883C204 addq $4, %rdx
0034 C745C02D movl $45, -64(%rbp)
003b C745C438 movl $56, -60(%rbp)
0042 C745C817 movl $23, -56(%rbp)
0049 C745CC0B movl $11, -52(%rbp)
0050 C745D001 movl $1, -48(%rbp)
0057 C745D443 movl $67, -44(%rbp)
005e C745D82A movl $42, -40(%rbp)
0065 C745DC09 movl $9, -36(%rbp)
006c C745E022 movl $34, -32(%rbp)
0073 C745E40C movl $12, -28(%rbp)
007a C745E80B movl $11, -24(%rbp)
0081 C745EC2D movl $45, -20(%rbp)
0088 8B45C0 movl -64(%rbp), %eax
008b 8945BC movl %eax, -68(%rbp)
008e 8B45C0 movl -64(%rbp), %eax
0091 8945B4 movl %eax, -76(%rbp)
.LBB2:
0094 C745B800 movl $0, -72(%rbp)
.L4:
009b 837DB80C cmpl $12, -72(%rbp)
009f 7F20 jg .L2
00a1 8B45B8 movl -72(%rbp), %eax
00a4 4898 cltq
00a6 8B4485C0 movl -64(%rbp,%rax,4), %eax
00aa 3B45B4 cmpl -76(%rbp), %eax
00ad 7D0C jge .L3
00af 8B45B8 movl -72(%rbp), %eax
00b2 4898 cltq
00b4 8B4485C0 movl -64(%rbp,%rax,4), %eax
00b8 8945B4 movl %eax, -76(%rbp)
.L3:
00bb 8345B801 addl $1, -72(%rbp)
00bf EBDA jmp .L4
.L2:
.LBE2:
00c1 BE000000 movl $.LC0, %esi
00c6 BF000000 movl $_ZSt4cout, %edi
00cb E8000000 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
00d0 4889C2 movq %rax, %rdx
00d3 8B45B4 movl -76(%rbp), %eax
00d6 89C6 movl %eax, %esi
00d8 4889D7 movq %rdx, %rdi
00db E8000000 call _ZNSolsEi
00e0 BE000000 movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, %esi
00e5 4889C7 movq %rax, %rdi
00e8 E8000000 call _ZNSolsEPFRSoS_E
00ed B8000000 movl $0, %eax
00f2 488B4DF8 movq -8(%rbp), %rcx
00f6 6448330C xorq %fs:40, %rcx
00ff 7405 je .L6
0101 E8000000 call __stack_chk_fail
.L6:
0106 C9 leave
.cfi_def_cfa 7, 8
0107 C3 ret
.cfi_endproc
.LFE1021:
_Z41__static_initialization_and_destruction_0ii:
.LFB1030:
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 .L9
011c 817DF8FF cmpl $65535, -8(%rbp)
0123 751E jne .L9
.L9:
0143 90 nop
0144 C9 leave
.cfi_def_cfa 7, 8
0145 C3 ret
.cfi_endproc
.LFE1030:
_GLOBAL__sub_I_main:
.LFB1031:
.cfi_startproc
0146 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0147 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
014a BEFFFF00 movl $65535, %esi
014f BF010000 movl $1, %edi
0154 E8AFFFFF call _Z41__static_initialization_and_destruction_0ii
0159 5D popq %rbp
.cfi_def_cfa 7, 8
015a C3 ret
.cfi_endproc
.LFE1031:
.section .init_array,"aw"
.align 8
0000 00000000 .quad _GLOBAL__sub_I_main
.text
.Letext0:
3.
.Ltext0:
.section .rodata
.align 8
.LC0:
0000 486F7720 .string "How many Elements in each array..."
.LC1:
0023 256400 .string "%d"
.LC2:
0026 456E7465 .string "Enter Elements of First List"
.LC3:
0043 456E7465 .string "Enter Elements of Second List"
.LC4:
0061 52657375 .string "Resultant List is"
.LC5:
0073 25640A00 .string "%d "
.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 4883EC30 subq $48, %rsp
0008 64488B04 movq %fs:40, %rax
0011 488945F8 movq %rax, -8(%rbp)
0015 31C0 xorl %eax, %eax
0017 BF000000 movl $.LC0, %edi
001c E8000000 call puts
0021 488D45D8 leaq -40(%rbp), %rax
0025 4889C6 movq %rax, %rsi
0028 BF000000 movl $.LC1, %edi
002d B8000000 movl $0, %eax
0032 E8000000 call __isoc99_scanf
0037 8B45D8 movl -40(%rbp), %eax
003a 4898 cltq
003c 48C1E002 salq $2, %rax
0040 4889C7 movq %rax, %rdi
0043 E8000000 call malloc
0048 488945E0 movq %rax, -32(%rbp)
004c 8B45D8 movl -40(%rbp), %eax
004f 4898 cltq
0051 48C1E002 salq $2, %rax
0055 4889C7 movq %rax, %rdi
0058 E8000000 call malloc
005d 488945E8 movq %rax, -24(%rbp)
0061 8B45D8 movl -40(%rbp), %eax
0064 4898 cltq
0066 48C1E002 salq $2, %rax
006a 4889C7 movq %rax, %rdi
006d E8000000 call malloc
0072 488945F0 movq %rax, -16(%rbp)
0076 BF000000 movl $.LC2, %edi
007b E8000000 call puts
0080 C745DC00 movl $0, -36(%rbp)
0087 EB2A jmp .L2
.L3:
00af 8345DC01 addl $1, -36(%rbp)
0089 8B45DC movl -36(%rbp), %eax
008c 4898 cltq
008e 488D1485 leaq 0(,%rax,4), %rdx
0096 488B45E0 movq -32(%rbp), %rax
009a 4801D0 addq %rdx, %rax
009d 4889C6 movq %rax, %rsi
00a0 BF000000 movl $.LC1, %edi
00a5 B8000000 movl $0, %eax
00aa E8000000 call __isoc99_scanf
.L2:
00b3 8B45D8 movl -40(%rbp), %eax
00b6 3945DC cmpl %eax, -36(%rbp)
00b9 7CCE jl .L3
00bb BF000000 movl $.LC3, %edi
00c0 E8000000 call puts
00c5 C745DC00 movl $0, -36(%rbp)
00cc EB2A jmp .L4
.L5:
00f4 8345DC01 addl $1, -36(%rbp)
00ce 8B45DC movl -36(%rbp), %eax
00d1 4898 cltq
00d3 488D1485 leaq 0(,%rax,4), %rdx
00db 488B45E8 movq -24(%rbp), %rax
00df 4801D0 addq %rdx, %rax
00e2 4889C6 movq %rax, %rsi
00e5 BF000000 movl $.LC1, %edi
00ea B8000000 movl $0, %eax
00ef E8000000 call __isoc99_scanf
.L4:
00f8 8B45D8 movl -40(%rbp), %eax
00fb 3945DC cmpl %eax, -36(%rbp)
00fe 7CCE jl .L5
0100 C745DC00 movl $0, -36(%rbp)
0107 EB4A jmp .L6
.L7:
014f 8345DC01 addl $1, -36(%rbp)
0109 8B45DC movl -36(%rbp), %eax
010c 4898 cltq
010e 488D1485 leaq 0(,%rax,4), %rdx
0116 488B45F0 movq -16(%rbp), %rax
011a 4801D0 addq %rdx, %rax
011d 8B55DC movl -36(%rbp), %edx
0120 4863D2 movslq %edx, %rdx
0123 488D0C95 leaq 0(,%rdx,4), %rcx
012b 488B55E0 movq -32(%rbp), %rdx
012f 4801CA addq %rcx, %rdx
0132 8B0A movl (%rdx), %ecx
0134 8B55DC movl -36(%rbp), %edx
0137 4863D2 movslq %edx, %rdx
013a 488D3495 leaq 0(,%rdx,4), %rsi
0142 488B55E8 movq -24(%rbp), %rdx
0146 4801F2 addq %rsi, %rdx
0149 8B12 movl (%rdx), %edx
014b 01CA addl %ecx, %edx
014d 8910 movl %edx, (%rax)
.L6:
0153 8B45D8 movl -40(%rbp), %eax
0156 3945DC cmpl %eax, -36(%rbp)
0159 7CAE jl .L7
015b BF000000 movl $.LC4, %edi
0160 E8000000 call puts
0165 C745DC00 movl $0, -36(%rbp)
016c EB2B jmp .L8
.L9:
0195 8345DC01 addl $1, -36(%rbp)
016e 8B45DC movl -36(%rbp), %eax
0171 4898 cltq
0173 488D1485 leaq 0(,%rax,4), %rdx
017b 488B45F0 movq -16(%rbp), %rax
017f 4801D0 addq %rdx, %rax
0182 8B00 movl (%rax), %eax
0184 89C6 movl %eax, %esi
0186 BF000000 movl $.LC5, %edi
018b B8000000 movl $0, %eax
0190 E8000000 call printf
.L8:
0199 8B45D8 movl -40(%rbp), %eax
019c 3945DC cmpl %eax, -36(%rbp)
019f 7CCD jl .L9
01a1 90 nop
01a2 488B45F8 movq -8(%rbp), %rax
01a6 64483304 xorq %fs:40, %rax
01af 7405 je .L10
01b1 E8000000 call __stack_chk_fail
.L10:
01b6 C9 leave
.cfi_def_cfa 7, 8
01b7 C3 ret
.cfi_endproc
.LFE0:
.Letext0:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.