Write a procedure is_little_endian that will return 1 when compiled and run on a
ID: 3624063 • Letter: W
Question
Write a procedure is_little_endian that will return 1 when compiled and run on a little---endian machine, and will return 0 when compiled and run on a big---endian machine. This program should run on any machine, regardless of its word size. You may write the procedure in C or in assembly language.This is the answer in assembly language
.globl is_little_endian
_is_little_endian:
pushl %ebp
movl %esp,%ebp
movl $1,-4(%ebp)
movb -4(%ebp),%bl
movl $0,%eax
andl %bl,%bl
jz out
movl $1,%eax
out:
popl $1,%ebp
ret
I know that little endian machine puts the least significant byte first but I need some help understanding how this assembly language program works and how it reveals that the machine is a little endian or big endian.
Thanks your a life saver!!!
Explanation / Answer
Dear, Here is the code #include int main(){
long i = 1;
char * blah = & i;
if(blah[0])
printf("%d ", 1);
else
printf("%d ", 0);
return 1;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.