# endian.s -- Determine if this machine is big or little endian. # "Big endian" means that the first byte of a number contains its # largest powers of 2, which we call the "big end" of the number. # So the big end comes first. # The definition of little endian is analogous -- the first byte # of the number contains the smallest powers of 2. In other words # the little end comes first. # # We'll put the number 0x12345678 into a word of memory so that it # takes up 32 bits = 4 bytes. The byte order will either be # 12 34 56 78 for big endian or 78 56 34 12 for little endian. .data array: .space 40 big_str: .asciiz "This machine is big endian.\n" little_str: .asciiz "This machine is little endian.\n" .text main: li $s0, 0x12345678 la $s1, array sw $s0, 0($s1) lb $s2, 0($s1) beq $s2, 0x12, equal li $v0, 4 la $a0, little_str syscall j end equal: li $v0, 4 la $a0, big_str syscall end: li $v0, 10 syscall