Question

Modify the ARMSIM program to do the following: 1) output the square sum of the data...

Modify the ARMSIM program to do the following:

1) output the square sum of the data
2) output the sum of all negatives and positives separately

   .text @ Direvtive
    .global _start @ declare global begining
   _start:
LDR R1,=idx @ content of idx is length of Vec and now R1 is a counter.
LDR R1,[R1] @ R1 is now the length of Vec. read inderectly
LDR R2,=Vec @ R2 is the address of first element of vector
MOV R0,#0 @ R0 is a Register to accumolate the summation of the element of the vector.
LOOP: LDR R3,[R2] @ R3 = Vec[i]
ADD R0,R0,R3 @ R0 = R0 + Vec[i]
ADD R2,R2,#4 @ R2 pointing to the next element of vector
SUB R1,R1,#1 @ contor elemente este decrementat
CMP R1,#0 @ if counter = 0, end of Vec
BNE LOOP @ loop until R1=0
MOV R0,R0, ASR #4 @ Divding R0=SUM by 16
LDR R1,=Avg @ R1 now is the address of the Avg
STR R0,[R1] @ Inderect writing for average results in Avg
MOV R1,R0 @ Making R1 ready for print out
MOV R0,#1 @ To print out using SWI 0x6b
SWI 0x6b @ Printing the contant of R1
SWI 0x11 @ Termination
.data @ Directive for begining of data part
.align @ Directive for alagnment of memory addresses
idx: .word 16 @ Total number of elements of vector
Vec: .word -7,3,5,1 @ vector initiation
.word -3,5,-18,-10
.word 2,-1,0,6
.word -10,-9,8,2
Avg: .skip 4 @ results
.end

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PART 1(SUM OF SQUARES )

.text                                         @ Direvtive
.global _start                          @ declare global begining
   _start:
LDR R1,=idx                           @ content of idx is the length of Vec and now R1 is a counter.
LDR R1,[R1]                           @ R1 is now the length of Vec. read inderectly
LDR R2,=Vec                          @ R2 is the address of first element of vector
MOV R0,#0                             @TO STORE SUM OF POSITIVE INTEGERS.[r0=0]

LOOP:

LDR R3,[R2]              @ R3 = Vec[i](r3= vec[0] initially)

MUL R3                       @R3= R3*R3

ADD R0,R0,R3                       @ R0 = R0 + (R3*R3)
ADD R2,R2,#4                        @ R2 pointing to the next element of vector
SUB R1,R1,#1                        @ contor elemente este decrementat
CMP R1,#0                             @ if counter = 0, end of Vec
BNE LOOP                             @ loop until R1=0

MOV R1 , R0

SWI 0x6b                                @ Printing the content of R1
SWI 0x11                                @ Termination

.data                                        @ Directive for begining of data part
.align                                       @ Directive for alagnment of memory addresses
idx: .word 16                           @ Total number of elements of vector
Vec: .word -7,3,5,1                 @ vector initiation
.word -3,5,-18,-10
.word 2,-1,0,6
.word -10,-9,8,2
.end

PART 2

.text                                         @ Direvtive
.global _start                          @ declare global begining
   _start:
LDR R1,=idx                           @ content of idx is length of Vec and now R1 is a counter.
LDR R1,[R1]                           @ R1 is now the length of Vec. read inderectly
LDR R2,=Vec                          @ R2 is the address of first element of vector
MOV R0,#0                             @TO STORE SUM OF POSITIVE INTEGERS.[r0=0]

MOV R4,#0                             @TO STORE SUM OF NEGATIVE INTEGERS[r4=0]


LOOP:

LDR R3,[R2]              @ R3 = Vec[i](r3= vec[0] initially)

ITE PL                         @LOOP FOR POSITIVE AND NEGAVTIVE NUMBERS

ADDPL R0, R0, R3                 @ R0 = R0 + (R3)
ADDMI R4, R4, R3                 @ R4= R0 + (R3)

ADD R2, R2, #4                      @ R2 pointing to the next element of vector
SUB R1, R1, #1                      @ counter element decrement
CMP R1, #0                            @ if counter = 0, end of Vec
BNE LOOP                             @ loop until R1=0

MOV R1, R0

SWI 0x6b                                @ Printing the content of R1(POSITIVE SUM)

MOV R1, R4

SWI 0x6b                                @ Printing the content of R1(NEGATIVE SUM)

SWI 0x11                                @ Termination

.data                                        @ Directive for begining of data part
.align                                       @ Directive for alagnment of memory addresses
idx: .word 16                           @ Total number of elements of vector
Vec: .word -7,3,5,1                 @ vector initiation
.word -3,5,-18,-10
.word 2,-1,0,6
.word -10,-9,8,2
.end

Add a comment
Know the answer?
Add Answer to:
Modify the ARMSIM program to do the following: 1) output the square sum of the data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT