Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembly program that prints the elements of the following int array in

ID: 3736954 • Letter: W

Question

Write an assembly program that prints the elements of the following int array in the standard output

5,6,7,8,9,2,1,0,2,4,8,6,3,9,7

Suggested output on screen:

All elements of the array: 567892102486397

Values at even indices: 57912837

Values at odd indices: 6820469

In your code section:

Write three blocks of code where each block prints the array as follows:

All elements of the array

Values at the odd indices

Values at the even indices

Remember to convert each integer to an ascii character and display it on screen.

You should use the writeString function that was covered in the class to make each of the write system calls

In your data section: Define the following array

array        dd         5,6,7,8,9,2,1,0,2,4,8,6,3,9,7

arrayLen equ        15

newline db 10 ; Define a newline character as

Also, In the data section remember to define the following three strings and their lengths

All elements of the array:

Values at even indices:

Values at odd indices:

Explanation / Answer

1.

.LC0:

.ascii "All elements of array:"

.LC1:

.ascii " Values at even indices:"

.LC2:

.ascii " Values at odd indices:"

main:

stmfd sp!, {fp, lr}

add fp, sp, #4

sub sp, sp, #408

ldr r0, .L12

ldr r1, .L12+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, #0

str r3, [fp, #-8]

b .L2

.L3:

sub r2, fp, #408

ldr r3, [fp, #-8]

mov r3, r3, asl #2

add r3, r2, r3

ldr r0, .L12+8

mov r1, r3

bl std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L2:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L3

mov r3, #0

str r3, [fp, #-8]

b .L4

.L5:

ldr r2, [fp, #-8]

ldr r3, .L12+12

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r3, [r3, #0]

ldr r0, .L12

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]

.L4:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L5

ldr r0, .L12

ldr r1, .L12+16

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, #0

str r3, [fp, #-8]

b .L6

.L8:

ldr r3, [fp, #-8]

and r3, r3, #1

cmp r3, #0

bne .L7

ldr r2, [fp, #-8]

ldr r3, .L12+12

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r3, [r3, #0]

ldr r0, .L12

mov r1, r3

bl std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

.L7:

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L6:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L8

ldr r0, .L12

ldr r1, .L12+20

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, #0

str r3, [fp, #-8]

b .L9

.L11:

ldr r3, [fp, #-8]

and r3, r3, #1

and r3, r3, #255

cmp r3, #0

beq .L10

ldr r2, [fp, #-8]

ldr r3, .L12+12

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r3, [r3, #0]

ldr r0, .L12

mov r1, r3

bl std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

.L10:

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L9:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L11

mov r3, #0

mov r0, r3

sub sp, fp, #4

ldmfd sp!, {fp, pc}

.L12:

.word std::cout

.word .LC0

.word std::cin

.word -404

.word .LC1

.word .LC2

__static_initialization_and_destruction_0(int, int):

stmfd sp!, {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 .L14

ldr r2, [fp, #-12]

ldr r3, .L16

cmp r2, r3

bne .L14

ldr r0, .L16+4

bl std::ios_base::Init::Init()

ldr r3, .L16+8

ldr r0, .L16+4

mov r1, r3

ldr r2, .L16+12

bl __aeabi_atexit

.L14:

sub sp, fp, #4

ldmfd sp!, {fp, pc}

.L16:

.word 65535

.word std::__ioinit

.word std::ios_base::Init::~Init()

.word __dso_handle

global constructors keyed to main:

stmfd sp!, {fp, lr}

add fp, sp, #4

mov r0, #1

ldr r1, .L19

bl __static_initialization_and_destruction_0(int, int)

ldmfd sp!, {fp, pc}

.L19:

.word 65535

Output:

All elements of array:1556789210248639

Values at even indices:156820469

Values at odd indices:5791283

2.

.LC0:

.ascii "All elements of array:"

.LC1:

.ascii " Values at even indices:"

.LC2:

.ascii " Values at odd indices:"

main:

stmfd sp!, {fp, lr}

add fp, sp, #4

sub sp, sp, #408

ldr r0, .L14

ldr r1, .L14+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, #0

str r3, [fp, #-8]

b .L2

.L3:

sub r2, fp, #408

ldr r3, [fp, #-8]

mov r3, r3, asl #2

add r3, r2, r3

ldr r0, .L14+8

mov r1, r3

bl std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L2:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L3

mov r3, #0

str r3, [fp, #-8]

b .L4

.L5:

ldr r2, [fp, #-8]

ldr r3, .L14+12

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r3, [r3, #0]

ldr r0, .L14

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]

.L4:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L5

mov r3, #0

str r3, [fp, #-8]

b .L6

.L7:

ldr r2, [fp, #-8]

ldr r3, .L14+12

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r3, [r3, #0]

and r3, r3, #255

ldr r0, .L14

mov r1, r3

bl std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L6:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L7

ldr r0, .L14

ldr r1, .L14+16

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, #0

str r3, [fp, #-8]

b .L8

.L10:

ldr r3, [fp, #-8]

and r3, r3, #1

cmp r3, #0

bne .L9

ldr r2, [fp, #-8]

ldr r3, .L14+12

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r3, [r3, #0]

ldr r0, .L14

mov r1, r3

bl std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

.L9:

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L8:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L10

ldr r0, .L14

ldr r1, .L14+20

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, #0

str r3, [fp, #-8]

b .L11

.L13:

ldr r3, [fp, #-8]

and r3, r3, #1

and r3, r3, #255

cmp r3, #0

beq .L12

ldr r2, [fp, #-8]

ldr r3, .L14+12

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r3, [r3, #0]

ldr r0, .L14

mov r1, r3

bl std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

.L12:

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L11:

ldr r3, [fp, #-8]

cmp r3, #14

movgt r3, #0

movle r3, #1

and r3, r3, #255

cmp r3, #0

bne .L13

mov r3, #0

mov r0, r3

sub sp, fp, #4

ldmfd sp!, {fp, pc}

.L14:

.word std::cout

.word .LC0

.word std::cin

.word -404

.word .LC1

.word .LC2

__static_initialization_and_destruction_0(int, int):

stmfd sp!, {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 .L16

ldr r2, [fp, #-12]

ldr r3, .L18

cmp r2, r3

bne .L16

ldr r0, .L18+4

bl std::ios_base::Init::Init()

ldr r3, .L18+8

ldr r0, .L18+4

mov r1, r3

ldr r2, .L18+12

bl __aeabi_atexit

.L16:

sub sp, fp, #4

ldmfd sp!, {fp, pc}

.L18:

.word 65535

.word std::__ioinit

.word std::ios_base::Init::~Init()

.word __dso_handle

global constructors keyed to main:

stmfd sp!, {fp, lr}

add fp, sp, #4

mov r0, #1

ldr r1, .L21

bl __static_initialization_and_destruction_0(int, int)

ldmfd sp!, {fp, pc}

.L21:

.word 65535

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote