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...

  • 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...

  • Step 1. Write a program in assembly language (using macros) to print out the following messages...

    Step 1. Write a program in assembly language (using macros) to print out the following messages on the screen [20 marks]: Hello, programmers! Welcome to the world of, Linux assembly programming! Step 2. Write a C function to passed two numbers to the function and calculate the sum of all the numbers between them (both inclusive). [50 marks] a. Make a version with for loop b. Make a version with while loop c. Make a version with do.. while loop...

  • The MIPS assembly program given here is expected to find the sum of elements in array...

    The MIPS assembly program given here is expected to find the sum of elements in array "myArr. Even though the code is syntactically correct, there are four bugs because of which the program is not glving the required output. With the help of the line numbers given identify the bug. Write the line number where you find the bug and give how the correct statement to eliminate the corresponding logical error (10 points partial points given for partial correct answers)...

  • Question 2 In this question, you will read two data files that include integers into two...

    Question 2 In this question, you will read two data files that include integers into two different arrays – the same way we did in class (but we are doing to arrays here). Duplicates are ok. 1- After you read the data into the array (use one function that takes an int array and a dsize by reference just like we did in class, and call that from main to fill both arrays). 2- Include a printArray function so that...

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
ADVERTISEMENT