Question

2. Given the following data declarations: .DATA Alpha WORD 1Ah, 2Bh, 3Ch, 4CH, 5C00, 6D03, 7F1A...

2. Given the following data declarations:

.DATA Alpha WORD 1Ah, 2Bh, 3Ch, 4CH, 5C00, 6D03, 7F1A SUM WORD ?

.CODE

;Write instructions that sum the odd elements of the array into AX and then save the resultant sum in the location SUM.


This needs to be done using Assembly.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Alpha:
        dw 1Ah, 2Bh, 3Ch, 4CH, 5C00h, 6D03h, 7F1Ah
SUM:
        dw   0
s(dw*):
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-24], rdi
        mov     WORD PTR [rbp-2], 0
.L3:
        cmp     WORD PTR [rbp-2], 6
        ja      .L2
        movzx   eax, WORD PTR [rbp-2]
        lea     rdx, [rax+rax]
        mov     rax, QWORD PTR [rbp-24]
        add     rax, rdx
        movzx   edx, WORD PTR [rax]
        movzx   eax, WORD PTR SUM[rip]
        add     eax, edx
        mov     WORD PTR SUM[rip], ax
        add     WORD PTR [rbp-2], 2
        jmp     .L3
.L2:
        movzx   eax, WORD PTR SUM[rip]
        pop     rbp
        ret
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     edi, OFFSET FLAT:Alpha
        call    s(unsigned short*)
        mov     WORD PTR [rbp-2], ax
        movzx   eax, WORD PTR [rbp-2]
        mov     WORD PTR SUM[rip], ax
        mov     eax, 0
        leave
        ret

Add a comment
Know the answer?
Add Answer to:
2. Given the following data declarations: .DATA Alpha WORD 1Ah, 2Bh, 3Ch, 4CH, 5C00, 6D03, 7F1A...
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
  • QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...

    QUESTION 1 Using the following declarations and a member of the Array class, int [ ] bArray = new int [10]; int location; Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell. __________________________ HINT: You must write the full statement...

  • using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last in...

    using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1. Determine the sum of all...

  • A data scientist needs a MIPS assembly-language program for data analysis. He has three arrays of...

    A data scientist needs a MIPS assembly-language program for data analysis. He has three arrays of floating-point numbers. Array 'a' is a source array, and 'b' and 'c' are result arrays. Array 'a' contains '2n' floating-point numbers. 'r1' is the address of 'a[0]'. 'r4' is the address of the byte immediately following 'a', i.e., the address of the imaginary element 'a[2n]'. Each of 'b' and 'c' can store 'n' floating-point numbers. 'r2' is the address of 'b[0]'. 'r3' is the...

  • 1. (i) [8] Suppose $s2 contains the value 6. What’s the value of $s1 after the...

    1. (i) [8] Suppose $s2 contains the value 6. What’s the value of $s1 after the instruction sll $s1, $s2, 5? (ii) [6] Convert jalr $s2, $t7 to machine code (binary). (iii) [6] Find the corresponding MIPS instruction to the following machine code. You are given that any immediate value is represented using 2’s complement. 0011010101010111 1111111111111111 2. [20] There is a value stored in $s0. Write a sequence of MIPS instructions that will place the absolute value of $s0...

  • Can someone solve number 5 using Matlab? In Class Exercises 8-Arrays For the following exercises, assume...

    Can someone solve number 5 using Matlab? In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1....

  • Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in);...

    Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in); Random r = new Random(); Write code to do the following: Use a while loop to prompt the user for how many numbers are to be entered. If the user does not enter a positive number (a number greater than 0), display a message saying the number must be positive and to try again. Store this value in the howmany variable. Declare an integer...

  • All solutions must have both code and data segments Write a sequence of assembly language instructions...

    All solutions must have both code and data segments Write a sequence of assembly language instructions to subtract each entry of an array B of five two’s complement 16-bit binary integers from the corresponding entry of an array A of five two’s complement 16-bit binary integers and construct a third array C of two’s complement 16-bit binary integers. i.e. C[i] = A[i] - B[i]. Use the following data for the arrays A and B.             A: 10, -15, 20, 4,...

  • csc 220 assembly 2. Use the following code below as a template and follow the instructions...

    csc 220 assembly 2. Use the following code below as a template and follow the instructions written in the comments Assume I have the following data segment written: data val1 BYTE 10h val2 WORD 8000h val3 DWORD OFFFFh val4 WORD 7FFFh :1. Write an instruction that increments val2. ;2. Write an instruction that subtracts val3 from EAX. ;3. Write instructions that subtract val4 from val2. .code ;Write your instructions here

  • Please help me! For Problem 1, 2 and 3: You are required to submit three .c...

    Please help me! For Problem 1, 2 and 3: You are required to submit three .c files that contain the instructions that you have written to solve the following problems. Place the C source code to solve the first problem in a file called lab5a.c. Place the C source code to solve the second problem in a file called lab5b.c. And place the C source code to solve the third problem in a file called lab5c.c. Remember to include your...

  • Problem 2: The following dictionary word and its meaning is given. Create a struct data structure...

    Problem 2: The following dictionary word and its meaning is given. Create a struct data structure such that when the client types the word, the meaning of that word is displayed. Word: foo; Meaning: A file Word: fooo; Meaning: A long file Word: foooo; Meaning: A long long file Word: fooooo; Meaning: A long long long file Word: foooooo; Meaning: A long long long long file Word: fooooooo; Meaning: A long long long long long file Write the algorithm in...

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