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

QUESTION: Write a function to check if a machine uses little endian or big endia

ID: 3848319 • 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"
.global isLittleEndian .data // declare any global variables here .text isLittleEndian: mov r12,r13 // save stack pointer into register r12 sub sp,#32 // reserve 32 bytes of space for local variables push {lr} // push link register onto stack -- make sure you pop it out before you return
  
// Your solution here



pop {lr} // pop link register from stack mov sp,r12 // restore the stack pointer -- Please note stack pointer should be equal to the // value it had when you entered the function . mov pc,lr // return from the function by copying link register into program counter
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"
.global isLittleEndian .data // declare any global variables here .text isLittleEndian: mov r12,r13 // save stack pointer into register r12 sub sp,#32 // reserve 32 bytes of space for local variables push {lr} // push link register onto stack -- make sure you pop it out before you return
  
// Your solution here



pop {lr} // pop link register from stack mov sp,r12 // restore the stack pointer -- Please note stack pointer should be equal to the // value it had when you entered the function . mov pc,lr // return from the function by copying link register into program counter
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"
.global isLittleEndian .data // declare any global variables here .text isLittleEndian: mov r12,r13 // save stack pointer into register r12 sub sp,#32 // reserve 32 bytes of space for local variables push {lr} // push link register onto stack -- make sure you pop it out before you return
  
// Your solution here



pop {lr} // pop link register from stack mov sp,r12 // restore the stack pointer -- Please note stack pointer should be equal to the // value it had when you entered the function . mov pc,lr // return from the function by copying link register into program counter .global isLittleEndian .data // declare any global variables here .text isLittleEndian: mov r12,r13 // save stack pointer into register r12 sub sp,#32 // reserve 32 bytes of space for local variables push {lr} // push link register onto stack -- make sure you pop it out before you return
  
// Your solution here



pop {lr} // pop link register from stack mov sp,r12 // restore the stack pointer -- Please note stack pointer should be equal to the // value it had when you entered the function . mov pc,lr // return from the function by copying link register into program counter

Explanation / Answer

Assembly code: The following assembly code checks whether the machine is little endian or big endian.

section .text

global _start
_start:

mov dword[b],0x12345678
mov cl,byte[b]

cmp cl,0x78
je littleend


cmp cl,0x12
jne extcode

mov ecx,big
mov edx,lbig
mov eax,4
mov ebx,1
int 0x80

jmp extcode



littleend:

mov ecx,lit
mov edx,llit
mov eax,4
mov ebx,1
int 0x80

extcode:


mov eax,1
mov ebx,0
int 0x80



section .data
b dd 30h
big db "BIG ENDIAN - ",10
lbig equ $-big
lit db "LITTLE ENDIAN - ",10
llit equ $-lit

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