ARC Assembly Language: Create an assembly language program that will have two ar
ID: 3601582 • Letter: A
Question
ARC Assembly Language:
Create an assembly language program that will have two arrays, of five elements each.
Sum the corresponding elements in the two arrays together and store the result in one of the arrays. Do
this for each element. In other words:
a[0] = a[0] + b[0]
a[1] = a[1] + b[1]
etc.
When this is complete, add all of the values in the array that contains the sums together, and store that
value in memory.
The values in each array should be: 1, 2, 3, 4, 5.
The code that adds the two arrays together and then sums the elements together is to be in a separate sub-routine.
Assymble:
.begin
.org 2048
Explanation / Answer
.LC1:
.ascii "The elements after sum are "
.LC2:
.ascii " "
sumarr::sum(int*, int*):
@ Function supports interworking.
@ args = 0, pretend = 0, frame = 24
@ frame_needed = 1, uses_anonymous_args = 0
push {fp, lr}
add fp, sp, #4
sub sp, sp, #24
str r0, [fp, #-16]
str r1, [fp, #-20]
str r2, [fp, #-24]
mov r3, #0
str r3, [fp, #-8]
.L3:
ldr r3, [fp, #-8]
cmp r3, #4
bgt .L2
ldr r3, [fp, #-8]
lsl r3, r3, #2
ldr r2, [fp, #-20]
add r3, r2, r3
ldr r2, [fp, #-8]
lsl r2, r2, #2
ldr r1, [fp, #-20]
add r2, r1, r2
ldr r1, [r2]
ldr r2, [fp, #-8]
lsl r2, r2, #2
ldr r0, [fp, #-24]
add r2, r0, r2
ldr r2, [r2]
add r2, r1, r2
str r2, [r3]
ldr r3, [fp, #-8]
add r3, r3, #1
str r3, [fp, #-8]
b .L3
.L2:
ldr r1, .L7
ldr r0, .L7+4
bl std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov r3, r0
ldr r1, .L7+8
mov r0, r3
bl std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
mov r3, #0
str r3, [fp, #-8]
.L5:
ldr r3, [fp, #-8]
cmp r3, #4
bgt .L6
ldr r1, .L7+12
ldr r0, .L7+4
bl std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
ldr r3, [fp, #-8]
lsl r3, r3, #2
ldr r2, [fp, #-20]
add r3, r2, r3
ldr r3, [r3]
mov r1, r3
bl std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
ldr r3, [fp, #-8]
add r3, r3, #1
str r3, [fp, #-8]
b .L5
.L6:
nop
sub sp, fp, #4
@ sp needed
pop {fp, lr}
bx lr
.L7:
.word .LC1
.word std::cout
.word std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
.word .LC2
.LC0:
.word 1
.word 2
.word 3
.word 4
.word 5
main:
@ Function supports interworking.
@ args = 0, pretend = 0, frame = 48
@ frame_needed = 1, uses_anonymous_args = 0
push {fp, lr}
add fp, sp, #4
sub sp, sp, #48
ldr r3, .L11
sub ip, fp, #28
mov lr, r3
ldmia lr!, {r0, r1, r2, r3}
stmia ip!, {r0, r1, r2, r3}
ldr r3, [lr]
str r3, [ip]
ldr r3, .L11
sub ip, fp, #48
mov lr, r3
ldmia lr!, {r0, r1, r2, r3}
stmia ip!, {r0, r1, r2, r3}
ldr r3, [lr]
str r3, [ip]
sub r2, fp, #48
sub r1, fp, #28
sub r3, fp, #8
mov r0, r3
bl sumarr::sum(int*, int*)
mov r3, #0
mov r0, r3
sub sp, fp, #4
@ sp needed
pop {fp, lr}
bx lr
.L11:
.word .LC0
__static_initialization_and_destruction_0(int, int):
@ Function supports interworking.
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
push {fp, lr}
add fp, sp, #4
sub sp, sp, #8
str r0, [fp, #-8]
str r1, [fp, #-12]
ldr r3, [fp, #-8]
cmp r3, #1
bne .L15
ldr r3, [fp, #-12]
ldr r2, .L16
cmp r3, r2
bne .L15
ldr r0, .L16+4
bl std::ios_base::Init::Init()
ldr r2, .L16+8
ldr r1, .L16+12
ldr r0, .L16+4
bl __aeabi_atexit
.L15:
nop
sub sp, fp, #4
@ sp needed
pop {fp, lr}
bx lr
.L16:
.word 65535
.word std::__ioinit
.word __dso_handle
.word std::ios_base::Init::~Init()
_GLOBAL__sub_I_main:
@ Function supports interworking.
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 1, uses_anonymous_args = 0
push {fp, lr}
add fp, sp, #4
ldr r1, .L19
mov r0, #1
bl __static_initialization_and_destruction_0(int, int)
sub sp, fp, #4
@ sp needed
pop {fp, lr}
bx lr
.L19:
.word 65535