QUESTION: Write a function to check if a machine uses little endian or big endia
ID: 3679270 • Letter: Q
Question
QUESTION: Write a function to check if a machine uses little endian or big endian notation. The basic structure of the program is given in the attached assembly language file. You are expected to write the function int isLittleEndian(). Complete the function implementation to return the following values from the function. The function int isLittleEndian () should return the following values 1 if the architecture is "Little Endian" ·0 if the architecture is "Big Endian" Note: You may use the Homework2 as reference for the C program logic and implement the same in assembly. Also, pay attention to the return values and make appropriate changes.Explanation / Answer
Big endian and little endian are two formats to store multibyte data types into computer's memory. These two formats are also called network byte order and host byte order respectively. In a multibyte data type such as int or longor any other multibyte data type the right most byte is called least significant byte and the left most byte is called most significant byte. In big endian format the most significant byte is stored first, thus gets stored at the smallest address byte, while in little endian format the least significant byte is stored first.
C program to check
#include <stdio.h>
int main ()
{
unsigned int x = 0x76543210;
char *c = (char*) &x;
Printf("*c is: 0x%x ", *c);
Void Islittileindian()
{
if (*c == 0x10)
{
Printf ("Underlying architecture is little endian. ");
}
else
{
Printf ("Underlying architecture is big endian. ");
}
return 0;
}}
Assembly language
.global _isLittleEndian
_isLittleEndian:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
mov eax, nLongNumber
xchg ah, al
ror eax, 16
xchg ah, al
mov nRetNumber, eax
return nRetNumber;
movl %ebp, %esp
popl %ebp
ret