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

**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...
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...
**IN AT&T ASSEMBLY LANG** Write an assembly language program which either hardcodes or reads in two...
**IN AT&T ASSEMBLY LANG** Write an assembly language program which either hardcodes or reads in two integers, A and B, and uses them to compute the following expressions. You must use the same values for A and B throughout all three expressions. A * 5 (A + B) - (A / B) (A - B) + (A * B)
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT