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

Hi this is Assembly Language MASM x86 program. Please write it in the language and please...
Hi this is Assembly Language MASM x86 program. Please write it in the language and please explain it with comments thank you Please answer it I really need help this question was refunded before so please answer. Thank you so much also these are two separate programs thank you. 1) Write a procedure to read in decimal or hex number (byte-sized) Then write a procedure using shifts and ANDS to convert the string to a binary number (if is backward,...
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...
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
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.
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 =...
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 write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one...
Please write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one array of size 24 to another array of size 24 using string instructions. Write 3 versions of this code. One code must copy byte at a time. One code must copy word at a time and one code must copy double word at a time. Cut and paste the array in memory to show your code is working.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT