Please Help!! Write a MIPS program using MARS simulator Inputs: A predefined arr
ID: 3691940 • Letter: P
Question
Please Help!!
Write a MIPS program using MARS simulator
Inputs:
A predefined array. The size of the array is 100
Outputs:
1) The sum of all even digits
2) The sum of all odd digits
Requirements:
Please use “loop unrolling” & “rescheduling” to optimize your code.
Use 5-stage pipeline to explain your rescheduling strategy.
Array:
7 99 100 90 34 30 10 29 64 29 88 19 55 98 5 86 68 5 29 60 51 100 39 55
24 52 46 58 76 16 59 37 47 7 57 31 11 23 82 88 76 86 22 73 63 66 41 98
36 82 51 54 7 95 71 19 36 67 46 30 27 36 91 60 94 86 33 47 22 36 64 78
55 83 86 21 22 78 62 29 93 27 93 11 18 47 87 44 18 39 50 90 42 4 3 80
61 99 55 81
Explanation / Answer
Answer:
MIPS program :
.Ltext0:
.section .rodata
.LC0:
0000 20456E74 .string " Enter Array elements"
.LC1:
0016 256400 .string "%d"
0019 00000000 .align 8
.LC2:
0020 20546865 .string " The sum of even Numbers :"
.LC3:
003f 20546865 .string " The sum of odd Numbers :"
.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 4883EC70 subq $112, %rsp
0008 64488B04 movq %fs:40, %rax
0011 488945F8 movq %rax, -8(%rbp)
0015 31C0 xorl %eax, %eax
0017 C7459800 movl $0, -104(%rbp)
001e C7459C00 movl $0, -100(%rbp)
0025 BF000000 movl $.LC0, %edi
002a E8000000 call puts
002f C7459400 movl $0, -108(%rbp)
0036 EB27 jmp .L2
.L3:
005b 83459401 addl $1, -108(%rbp)
0038 488D45A0 leaq -96(%rbp), %rax
003c 8B5594 movl -108(%rbp), %edx
003f 4863D2 movslq %edx, %rdx
0042 48C1E202 salq $2, %rdx
0046 4801D0 addq %rdx, %rax
0049 4889C6 movq %rax, %rsi
004c BF000000 movl $.LC1, %edi
0051 B8000000 movl $0, %eax
0056 E8000000 call __isoc99_scanf
.L2:
005f 837D9463 cmpl $99, -108(%rbp)
0063 7ED3 jle .L3
0065 C7459400 movl $0, -108(%rbp)
006c EB2E jmp .L4
.L7:
006e 8B4594 movl -108(%rbp), %eax
0071 4898 cltq
0073 8B4485A0 movl -96(%rbp,%rax,4), %eax
0077 83E001 andl $1, %eax
007a 85C0 testl %eax, %eax
007c 750E jne .L5
007e 8B4594 movl -108(%rbp), %eax
0081 4898 cltq
0083 8B4485A0 movl -96(%rbp,%rax,4), %eax
0087 014598 addl %eax, -104(%rbp)
008a EB0C jmp .L6
.L5:
008c 8B4594 movl -108(%rbp), %eax
008f 4898 cltq
0091 8B4485A0 movl -96(%rbp,%rax,4), %eax
0095 01459C addl %eax, -100(%rbp)
.L6:
0098 83459401 addl $1, -108(%rbp)
.L4:
009c 837D9463 cmpl $99, -108(%rbp)
00a0 7ECC jle .L7
00a2 8B4598 movl -104(%rbp), %eax
00a5 89C6 movl %eax, %esi
00a7 BF000000 movl $.LC2, %edi
00ac B8000000 movl $0, %eax
00b1 E8000000 call printf
00b6 8B459C movl -100(%rbp), %eax
00b9 89C6 movl %eax, %esi
00bb BF000000 movl $.LC3, %edi
00c0 B8000000 movl $0, %eax
00c5 E8000000 call printf
00ca B8000000 movl $0, %eax
00cf 488B4DF8 movq -8(%rbp), %rcx
00d3 6448330C xorq %fs:40, %rcx
00dc 7405 je .L9
00de E8000000 call __stack_chk_fail
.L9:
00e3 C9 leave
.cfi_def_cfa 7, 8
00e4 C3 ret
.cfi_endproc
.LFE0:
.Letext0: