Write simple MIPS assembly code and simulate it using the simulator that was int
ID: 3687628 • 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 0x10010000. 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, 23, 11, 1, 67, 42, 9, 34, 12, 11, 45}. Write and execute a program to add a and b, leaving the result in a and leaving the b unmodified. Both a and b are 10 elements arrays stored in memory starting at 0x10010000. Provide comments throughout your code. Write a report, which includes: MIPS Code for each program Output Screen shot for registers/console for each program. Conclusion.Explanation / Answer
coping one array to another:
===================
.LC0:
.ascii "copying...."
.LC1:
.ascii "
...."
.LC2:
.ascii "
Finished"
main:
push {r7, lr}
sub sp, sp, #168
add r7, sp, #0
movs r3, #0
str r3, [r7, #4]
movs r3, #0
str r3, [r7, #4]
b .L2
.L3:
ldr r3, [r7, #4]
lsls r3, r3, #2
add r1, r7, #168
add r3, r3, r1
ldr r2, [r7, #4]
str r2, [r3, #-80]
ldr r3, [r7, #4]
adds r3, r3, #1
str r3, [r7, #4]
.L2:
ldr r3, [r7, #4]
cmp r3, #11
ble .L3
movw r0, #:lower16:.LC0
movt r0, #:upper16:.LC0
bl printf
movs r3, #0
str r3, [r7, #4]
b .L4
.L5:
ldr r3, [r7, #4]
lsls r3, r3, #2
add r2, r7, #168
add r3, r3, r2
ldr r2, [r3, #-80]
ldr r3, [r7, #4]
lsls r3, r3, #2
add r1, r7, #168
add r3, r3, r1
str r2, [r3, #-160]
movw r0, #:lower16:.LC1
movt r0, #:upper16:.LC1
bl puts
ldr r3, [r7, #4]
adds r3, r3, #1
str r3, [r7, #4]
.L4:
ldr r3, [r7, #4]
cmp r3, #11
ble .L5
movw r0, #:lower16:.LC2
movt r0, #:upper16:.LC2
bl printf
movs r3, #0
mov r0, r3
adds r7, r7, #168
mov sp, r7
pop {r7, pc}
=====================
Finding th minimum element:
====================
.LC0:
.ascii "searching...."
.LC1:
.ascii "
Minimum element is %d "
main:
push {r7, lr}
sub sp, sp, #88
add r7, sp, #0
movs r3, #0
str r3, [r7]
add r2, r7, #8
movs r3, #80
mov r0, r2
movs r1, #0
mov r2, r3
bl memset
movs r3, #45
str r3, [r7, #8]
movs r3, #56
str r3, [r7, #12]
movs r3, #23
str r3, [r7, #16]
movs r3, #11
str r3, [r7, #20]
movs r3, #1
str r3, [r7, #24]
movs r3, #67
str r3, [r7, #28]
movs r3, #42
str r3, [r7, #32]
movs r3, #9
str r3, [r7, #36]
movs r3, #34
str r3, [r7, #40]
movs r3, #12
str r3, [r7, #44]
movs r3, #11
str r3, [r7, #48]
movs r3, #45
str r3, [r7, #52]
movs r3, #99
str r3, [r7, #4]
movw r0, #:lower16:.LC0
movt r0, #:upper16:.LC0
bl printf
movs r3, #0
str r3, [r7]
b .L2
.L4:
ldr r3, [r7]
lsls r3, r3, #2
add r2, r7, #88
add r3, r3, r2
ldr r2, [r3, #-80]
ldr r3, [r7, #4]
cmp r2, r3
bge .L3
ldr r3, [r7]
lsls r3, r3, #2
add r2, r7, #88
add r3, r3, r2
ldr r3, [r3, #-80]
str r3, [r7, #4]
.L3:
ldr r3, [r7]
adds r3, r3, #1
str r3, [r7]
.L2:
ldr r3, [r7]
cmp r3, #11
ble .L4
movw r0, #:lower16:.LC1
movt r0, #:upper16:.LC1
ldr r1, [r7, #4]
bl printf
movs r3, #0
mov r0, r3
adds r7, r7, #88
mov sp, r7
pop {r7, pc}
Adding element :
===========printf@plt-0x10:
pushq 0x20063a(%rip) # 600ae0 <_GLOBAL_OFFSET_TABLE_+0x8>
jmpq *0x20063c(%rip) # 600ae8 <_GLOBAL_OFFSET_TABLE_+0x10>
nopl 0x0(%rax)
printf@plt:
jmpq *0x20063a(%rip) # 600af0 <_GLOBAL_OFFSET_TABLE_+0x18>
pushq $0x0
jmpq 4004a0 <_init+0x28>
main:
push %rbp
mov %rsp,%rbp
sub $0x60,%rsp
movl $0x0,-0x4(%rbp)
movl $0x2d,-0x30(%rbp)
movl $0x38,-0x2c(%rbp)
movl $0x17,-0x28(%rbp)
movl $0xb,-0x24(%rbp)
movl $0x1,-0x20(%rbp)
movl $0x43,-0x1c(%rbp)
movl $0x2a,-0x18(%rbp)
movl $0x9,-0x14(%rbp)
movl $0x22,-0x10(%rbp)
movl $0xc,-0xc(%rbp)
movl $0x0,-0x60(%rbp)
movl $0x1,-0x5c(%rbp)
movl $0x2,-0x58(%rbp)
movl $0x3,-0x54(%rbp)
movl $0x4,-0x50(%rbp)
movl $0x5,-0x4c(%rbp)
movl $0x6,-0x48(%rbp)
movl $0x7,-0x44(%rbp)
movl $0x8,-0x40(%rbp)
movl $0x9,-0x3c(%rbp)
mov $0x400758,%edi
mov $0x0,%eax
callq 4004b0 <printf@plt>
movl $0x0,-0x4(%rbp)
cmpl $0x9,-0x4(%rbp)
jg 4006b0 <main+0xda>
mov -0x4(%rbp),%eax
cltq
mov -0x30(%rbp,%rax,4),%edx
mov -0x4(%rbp),%eax
cltq
mov -0x60(%rbp,%rax,4),%eax
add %eax,%edx
mov -0x4(%rbp),%eax
cltq
mov %edx,-0x30(%rbp,%rax,4)
addl $0x1,-0x4(%rbp)
jmp 400687 <main+0xb1>
mov $0x400781,%edi
mov $0x0,%eax
callq 4004b0 <printf@plt>
mov $0x0,%eax
leaveq
retq
nopw %cs:0x0(%rax,%rax,1)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.