Question

In: Computer Science

Please complete in MASM (x86 assembly language). Use the code below to get started. Use a...

Please complete in MASM (x86 assembly language). Use the code below to get started.

Use a loop with indirect or indexed addressing to reverse the elements of an integer array in

place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF

operators to make the program as flexible as possible if the array size and type should be

changed in the future.

.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 ENDP
END main

Solutions

Expert Solution

Below is the assembly language code for inplace reversing of array.

daddiu  $sp,$sp,-64

        sd      $fp,56($sp)

        move    $fp,$sp

        lui     $6,%hi(%neg(%gp_rel(main)))

        daddu   $6,$6,$25

        daddiu  $6,$6,%lo(%neg(%gp_rel(main)))

        ld      $2,%got_page(.LC0)($6)

        daddiu  $3,$2,%got_ofst(.LC0)

        ldl     $3,7($3)

        ldr     $3,%got_ofst(.LC0)($2)

        move    $4,$3

        daddiu  $3,$2,%got_ofst(.LC0)

        ldl     $5,15($3)

        ldr     $5,8($3)

        move    $3,$5

        daddiu  $2,$2,%got_ofst(.LC0)

        ldl     $5,23($2)

        ldr     $5,16($2)

        move    $2,$5

        sd      $4,16($fp)

        sd      $3,24($fp)

        sd      $2,32($fp)

        li      $2,6                        # 0x6

        sw      $2,0($fp)

        sw      $0,4($fp)

        lw      $2,0($fp)

        addiu   $2,$2,-1

        sw      $2,8($fp)

.L3:

        lw      $3,4($fp)

        lw      $2,8($fp)

        slt     $2,$3,$2

        beq     $2,$0,.L2

        nop

        lw      $2,4($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        lw      $2,16($2)

        sw      $2,12($fp)

        lw      $2,8($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        lw      $3,16($2)

        lw      $2,4($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        sw      $3,16($2)

        lw      $2,8($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        lw      $3,12($fp)

        sw      $3,16($2)

Thank You.


Related Solutions

X86 Assembly MASM Questions below ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the...
X86 Assembly MASM Questions below ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the APPROPRIATE places at the end ;;;;; of the file as indicated. ;;;;; Q2: Write the directive to bring in the IO library           ;;;;; Q3: Create a constant called DAYS_PER_WEEK and initialize it to 5 ;;;;;     Create a constant called WEEKS_PER_YEAR and initialize it to 49 ;;;;; Q4: Create a constant called DAYS_PER_YEAR by using DAYS_PER_WEEK and ;;;;;     WEEKS_PER_YEAR (of Q3) in an...
Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2,...
Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2, and num3 and display the value of the expression ( (num1 ^ 3) * num2 + 5 * ( num2 ^ 2) ) / num3. assume that the user enters only numbers that are greater than zero and the calculation never exceed 4 bytes size. Sample run: num1 = 1 num2 = 2 num3 = 3 ((num1 ^ 3) * num2 + 5 *...
Using x86 assembly language, create a flowchart and write an example of code that will sort...
Using x86 assembly language, create a flowchart and write an example of code that will sort 2 arrays of unsigned doubleword integers in ascending order and output the largest element in each array. Any sorting procedure can be used, but this procedure must be called twice for each array. The first time it is called, the first array should be sorted and the second time it is called, the second array must be sorted. As well as outputting which is...
Please use assembly language x86 Visual Studio Write a program to add the following word size...
Please use assembly language x86 Visual Studio Write a program to add the following word size numbers:15F2, 9E89, 8342, 99FF, 7130 using adc instruction and a loop. The result must be in DX, AX. Show the result in debug window.
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
Please complete both questions in MASM. Explain code clearly, thank you. Please screenshot memory outputs. Symbolic...
Please complete both questions in MASM. Explain code clearly, thank you. Please screenshot memory outputs. Symbolic Text Constants Write a program that defines symbolic names for several string literals (characters between quotes). Use each symbolic name in a variable definition. Use this code to get started: ; Symbolic Text Constants Comment ! Description: Write a program that defines symbolic names for several string literals (characters between quotes). Use each symbolic name in a variable definition. ! .386 .model flat,stdcall .stack...
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
Assembly Language for x86 processors You are to write a program which should first ask for...
Assembly Language for x86 processors You are to write a program which should first ask for 4 random numbers from 0-20 (user will inpute these numbers in no preset order). Input these 5 numbers in variables called num1, num2, num3, num4, and num5. When done, your program should sort these numbers (you will use lots of conditions to check order). num1 should contain smallest number while num5 should contain the biggest. display the contents of num1 through num5 on the...
Develop an x86 assembly language program that properly executes an "x to the y power" function:...
Develop an x86 assembly language program that properly executes an "x to the y power" function: int power(int x, int y) Compute the integer value that is x to the y power Do not concern yourself with the possibility of overflow You may only use only a loop structure to compute the value Remember that the return value must be placed in the EAX register Make sure that any registers (not EAX) used by this function are placed back to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT