Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please complete the implementation of the function given in the question section

ID: 642391 • Letter: P

Question

Please complete the implementation of the function given in the question section below.

Test your functions using the main program given. Please note main program may have missing lines or code. You are required to identify missing code and complete it.

QUESTION: Write a function to change variable from little endian to big endian notation in assembly.

The basic structure of the function is given in the attached assembly language file. You are expected to complete the function int toBigEndian(int variable) which converts an integer variable passed from little endian to big endian notation. The conversion function should simply accept the number variable and flip the order of the bytes and return the resulting value. For example

Variable passed to function 0xAABBCCDD?The value returned from the function 0xDDCCBBAA

Complete the function implementation which takes a little endian notation as input and returns the big endian notation of the given value from the function as given in the above example.

The function with the basic commands for the function entry and exit / return are already given. Use the given function and fill in your implementation where it is specified as below:

TO DO: Your implementation should be here

*/

Note: The function can be implemented using the following instructions:

ANDL?

ORL?

ADDL

SUBL

XORL

SHL

SHRL

THESE ARE THREE SEPERATE FILES THAT ARE INCLUDED IN THE PROGRAM!

/*

* Assembly.S This is file 1

*/

.global _toBigEndian

_toBigEndian:

/* Function entry code */

     pushl    %ebp

     movl     %esp, %ebp

     subl $16, %esp

    

    

    

     /* TO DO: Your implementation

         should be here

     */

    

    

    

/* Function exit code */

     movl     %ebp, %esp

     popl     %ebp

     ret

    

    

    

.global _isLittleEndian

_isLittleEndian:

/* Function entry code */

     pushl    %ebp

     movl     %esp, %ebp

     subl $16, %esp

    

    

    

     /* TO DO: Your implementation

         should be here

     */

    

    

    

/* Function exit code */

     movl     %ebp, %esp

     popl     %ebp

     ret

//function.h This is file 2

extern int toBigEndian(int);

extern int isLittleEndian(int);

// This is file 3

#include stdio.h>

#include "function.h"

int main() {

    

     int in1, in2;

     int out1, out2;

    

     // Sample input value (It may be tested with other input values)

     // Do not hard code these values inside the function

     in1 = 0xAABBCCDD;

     out1 = toBigEndian(in1);

     printf(" Output1: %d", out1);

    

     // Sample input value (It may be tested with other input values)

     // Do not hard code these values inside the function

    

     out2 = isLittleEndian();

     printf(" Output2: %d", out2);

     return 0;

}

*********************************

Explanation / Answer

#include #include #include #include enum endianness { little_endian, big_endian, network_endian = big_endian, #if defined(BOOST_LITTLE_ENDIAN) host_endian = little_endian #elif defined(BOOST_BIG_ENDIAN) host_endian = big_endian #else #error "unable to determine system endianness" #endif }; namespace detail { template struct swap_bytes { inline T operator()(T val) { throw std::out_of_range("data size"); } }; template struct swap_bytes { inline T operator()(T val) { return val; } }; template struct swap_bytes { inline T operator()(T val) { return ((((val) >> 8) & 0xff) | (((val) & 0xff) > 24) | (((val) & 0x00ff0000) >> 8) | (((val) & 0x0000ff00) 56) | (((val) & 0x00ff000000000000ull) >> 40) | (((val) & 0x0000ff0000000000ull) >> 24) | (((val) & 0x000000ff00000000ull) >> 8 ) | (((val) & 0x00000000ff000000ull)
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote