Question

How do you write x86 assembly code for the above main procedure and Addarrays function? Main()...

How do you write x86 assembly code for the above main procedure and Addarrays function?


Main()

{

     int A[100];

     int   B[100];

     // initialization etc.

     length = 100;

     Call Addarrays(A, B, length)

}

Addarrays(int[] X, int[] Y, count)

{

   i = 0;

   while (i < count) {

       X[i] = X[i] + Y[i];

        I++

   }

}

Homework Answers

Answer #1

X86-64 9.2 code:

main:
push rbp
mov rbp, rsp
sub rsp, 816
mov DWORD PTR [rbp-4], 100
mov edx, DWORD PTR [rbp-4]
lea rcx, [rbp-816]
lea rax, [rbp-416]
mov rsi, rcx
mov rdi, rax
mov eax, 0
call Addarrays
mov eax, 0
leave
ret
Addarrays:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-24], rdi
mov QWORD PTR [rbp-32], rsi
mov DWORD PTR [rbp-36], edx
mov DWORD PTR [rbp-4], 0
jmp .L4
.L5:
mov eax, DWORD PTR [rbp-4]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-24]
add rax, rdx
mov ecx, DWORD PTR [rax]
mov eax, DWORD PTR [rbp-4]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-32]
add rax, rdx
mov edx, DWORD PTR [rax]
mov eax, DWORD PTR [rbp-4]
cdqe
lea rsi, [0+rax*4]
mov rax, QWORD PTR [rbp-24]
add rax, rsi
add edx, ecx
mov DWORD PTR [rax], edx
add DWORD PTR [rbp-4], 1
.L4:
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-36]
jl .L5
nop
pop rbp
ret

if you like the answer please provide a thumbs up

Know the answer?
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
Similar Questions
Convert this C++ program exactly as you see it into x86 assembly language: // Use the...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the Irvine library for the print function #include <iostream> // The string that needs to be printed char word[] = "Golf\0"; // Pointer to a specific character in the string char * character = word; //NOTE: This main() function is not portable outside of Visual Studio void main() { // Set up a LOOP - See the while loop's conditional expression below int ecx =...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your variables here .code main PROC    ; write your assembly code here    INVOKE ExitProcess,0 main...
Write ARMv8 Assembly code and C++ code for a function called int grade(int n) that returns...
Write ARMv8 Assembly code and C++ code for a function called int grade(int n) that returns the character 'A' if n >= 90, 'B' if 90 > n >= 80, etc. (Use the ASCII code.)
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere...
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere else. int f2(int x, int y) { int i, z = 0; for (i = x; i <= y; i++) z = z + f1(i, 5); return z; }
How do I make this code not include negative numbers in the total or average if...
How do I make this code not include negative numbers in the total or average if they are entered? (C++) For example, if you enter 4, 2, and -2, the average should not factor in the -2 and would be equal to 3. I want the code to factor in positive numbers only. ----- #include using namespace std; int main() {    int x, total = 0, count = 0;       cout << "Type in first value ";   ...
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed...
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed starting at location 8000. Create labels for branch and jump instructions and indicate the 0001 0001 0010 1000 0000 0000 0000 0011 1000 1110 0001 0001 0000 0000 0000 1000 0010 0010 0010 1000 0000 0000 0000 0110 0000 1000 0000 0000 0000 0001 0000 0010 b. Translate the following C function into MIPS assembly code. int f1(int ar1[], int ar2[], int n) {...
In MIPS assembly, write an assembly language version of the following C code segment: int A[100],...
In MIPS assembly, write an assembly language version of the following C code segment: int A[100], B[100]; for (i=1; i < 100; i++) { A[i] = A[i-1] + B[i]; }
Write the C55x assembly code for each of the following C snippet code shown below. Assume...
Write the C55x assembly code for each of the following C snippet code shown below. Assume the 8-bit values a, b, c, and d are stored in locations 0x600, 0x601, 0x602, and 0x603 respectively in the memory. Store the result x in location 0x604 and y in location 0x60C. Do not use software to generate the assembly code and comment your code. x = (a - b)3 - (c*d); for (j=0;j<=200;j++)   y = y + (a * b);
Machine Language - 1. Which of the following assembly code represents the high-level Java code below?...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below? int x; int i = 5; if (i < 0) x = -1; else x = 1; @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JGE @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END...
Fill in the code for the function below called containsAvgValue. It takes as input a float...
Fill in the code for the function below called containsAvgValue. It takes as input a float array of any length and returns 1 if the array happens to contain a value that equals the average of all the values in the array or 0 otherwise. For example, when give the array [2.0, 2.0] it should return 1 since the average value is 2.0 and the array contains that value. To help you, I’ve included a function that computes the average...