Question

In: Computer Science

Write an arm assembly program that will multiply two arrays (index by index) and store the...

Write an arm assembly program that will multiply two arrays (index by index) and store the result in a third array.

Declare an array:

.data

Arr1: .quad 10    #index 0

            .quad 4      #index 1

         …..

Arr2: .quad 2,5,6….

Arr3: .quad 0,0,0….

To load array pointer address:

     Movq $Arr1, %rdx   #stores address of Arr1 index 0 in rdx

To move to the next index of an array:

    Addq $8,%rdx

To retrieve data:

Movq (%rdx), %rcx         # will have data at address in rdx

We can also use LEA instruction.

Xorq %rbx,%rbx

LEAQ (%rdx, %rbx,8), %<reg>     #address if index 0 in reg

Movq(%<reg>) , %<reg>     #data at index 0

Inc %rbx

To store data:

Movq %<reg>, (%<reg that has address>)

.global main

.text

main:

movq $arr, %rcx            #load address of index 0

movq (%rcx), %rax          #retrieve data at index 0

addq $8, %rcx              #go to next index 8 bytes over

movq (%rcx), %rax          #get data at index 1

#or

xorq %rcx,%rcx

movq $arr, %rbx

leaq (%rbx,%rcx,8), %rax   #ADDRESS OF INDEX 0

movq (%rax),%rax           #content at index 0

incq %rcx

leaq (%rbx,%rcx,8), %rax   #address of index 1

# or

xorq %rcx, %rcx

movq arr(,%rcx,8), %rax    #move content at index 0 to rax

#or

xorq %rcx,%rcx

movq $arr,%rbx

movq (%rbx,%rcx,8), %rdx    #move content at index 0

# exiting

movq $60, %rax # sys_exit syscall number: 60

xorq %Rdi, %Rdi # set exit status to 0

syscall     

.data

arr: .quad 10,11,12

Solutions

Expert Solution

.data
    x: .word 4,5,2
    y: .word 1,8,3  
    z: .space 12
main:
    .text

     la $a0 x #loads contents into $a0
     la $a1 y
     la $a2 z
     jal addArray #function call
     li $v0, 4
     syscall


addArray:
    addi $sp, $sp, -4 # make room for 1 saved register
   [b] sw $s0, 0($sp) # save $s0 onto frame stack[/b]
    add $s0, $zero, $zero # initialize i=0
    add $s1, $zero, 12  #for the loop condition
L1:
    add $t1, $s0, $a0 # compute x[i] as $a0[$s0]
    add $t2, $s0, $a1
    lbu $t3, 0($t1)  # load byte at x[i] (x+i) into $t3
    lbu $t4, 0($t2)   # load byte at y[i] (y+i) into $t3
    add $t5, $t3, $t4 #adding elements x+y and putting it in $t5 
    add $t6, $s0, $a2 
    sb  $t5, 0($t6) #adds to the third array
    beq $s0, $s1, L2 # $s0 >=$s1                 
    addi $s0, $s0, 4 # increment array
    j L1 # jump unconditionally to L1 (beginning of loop)   

L2:
    lw $s0, 0($sp) # restore $sp
    addi $sp, $sp, 1 # pop 1 word off the stack
    jr $ra # return to sender

Related Solutions

Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest...
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest common divisor. *I am using Eclipse DS-5 Community Workspace with A64 Instruction Set) Use the following algorithm: // Given two integers m and n: if (m < n) gcd(n, m) if n is a divisor of m gcd(m, n) = n else gcd (m, n) = gcd (n, m % n) Your program must be recursive. You must create a function that calls itself,...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert temperatures from Celsius to Fahrenheit or from Fahrenheit to Celsius. Here are the two formulas for your reference. Use variable to read and store values. C= 5* (F - 32) / 9 F = (9 * C / 5 ) + 32 My code below: TempConvert.s LDR R8,=temperature LDR R1,[R8] LDR R8,=unit LDRB R2,[R8] LDR R8,=celsius LDRB R3,[R8] LDR R8,=fahrenheit LDRB R4,[R8] MOV R6,#9...
5. Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly...
5. Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly code to compare sum of the numbers sotred in the arrays. If sum of Array1 is greater, save a “1” in R10, otherwise, save “0’ in R10.    
Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly code...
Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly code to compare sum of the numbers sotred in the arrays. If sum of Array1 is greater, save a “1” in R10, otherwise, save “0’ in R10.
You have to write an ARM Assembly M4 program for SLTB004A Thunderboard Sense 2. Write an...
You have to write an ARM Assembly M4 program for SLTB004A Thunderboard Sense 2. Write an assembly program that blinks the red LED to send out a SOS Morse code (... --- ...). The dot duration must be 1/4 second and the dash one - 1/2 sec. Duration between dots and dashes is 1/4 second. After displaying SOS the program must delay for 2 seconds and then loop back to blink out SOS again. Use LETIMER for generating all time...
     program will enter data into two single dimension arrays (do not store duplicate values in arrays)...
     program will enter data into two single dimension arrays (do not store duplicate values in arrays)      program will find the union and intersection of the two arrays using one function      program will find the symmetric difference of two arrays      program will display the union, intersection, and symmetric difference   */     short* input_data(short size);   // function to dynamically allocate and array and enter data into the array void display_data(short *data, short size); // function to display data in an array void...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Write a Python program to add, multiply and divide any two numbers.
Write a Python program to add, multiply and divide any two numbers.
Write the below C program using ARM assembly language and compile for Cortex A53. #include<stdio.h> void...
Write the below C program using ARM assembly language and compile for Cortex A53. #include<stdio.h> void quicksort(int number[25],int first,int last){ int i, j, pivot, temp; if(first<last) { pivot=first; i=first; j=last; while(i<j) { while(number[i]<=number[pivot]&&i<last) i++; while(number[j]>number[pivot]) j--; if(i<j){ temp=number[i]; number[i]=number[j]; number[j]=temp; } } temp=number[pivot]; number[pivot]=number[j]; number[j]=temp; quicksort(number,first,j-1); quicksort(number,j+1,last); } } int main() { int i, count, number[25]; printf("Enter some elements (Maximum 25): "); scanf("%d",&count); printf("Enter %d elements: ", count); for(i=0;i<count;i++) scanf("%d",&number[i]); quicksort(number,0,count-1); printf("The Sorted Order is: "); for(i=0;i<count;i++) printf(" %d",number[i]); return...
Write a program that takes two integer arrays a and b of size n from the...
Write a program that takes two integer arrays a and b of size n from the user, the use a method product to find the product of a and b and return the results after storing them in an array c, then prints the returned results to the screen. (Note: c[i] = a[i] * b[i], for i = 0, ..., n-1) Sample Output: Enter the size of your arrays: 5 Enter the integer values of the first array a: 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT