OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:23 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Why little endian!
PostPosted: Mon Dec 21, 2020 5:13 pm 
Offline
Member
Member

Joined: Tue Apr 03, 2018 2:44 am
Posts: 402
The one place endianness really makes a visual difference is in bitmap displays, and there, big endian matches what's on the screen.

These days, with 32-bpp displays, even that is not significant any more.

It's all just a pain in the arse. I'm putting together my USB stack, which is predominantly little-endian, but at some point I'll be using it to push across SCSI command blocks, which are big-endian.


Top
 Profile  
 
 Post subject: Re: Why little endian!
PostPosted: Sat Dec 26, 2020 6:23 pm 
Offline

Joined: Thu Sep 10, 2020 1:32 pm
Posts: 5
I dont know why the choice was made, but as someone who prefers little edian in cpu design, its mainly due to the fact that you can take the same address and load it at different byte witdths without having to think about adding 1 to 4 to the address due to the edianess.


Top
 Profile  
 
 Post subject: Re: Why little endian!
PostPosted: Sat Dec 26, 2020 6:37 pm 
Offline
Member
Member
User avatar

Joined: Tue Sep 15, 2020 8:07 am
Posts: 264
Location: London, UK
nexos wrote:
moonchild wrote:
bloodline wrote:
It just the bytes which are stored in reverse order of what you would expect when reading and writing binary numbers.


That's not entirely true.

The bits are probably also in little endian (though there is no guarantee of this).

But this is a CPU implementation detail. Since the byte is the smallest addressable unit, so there's no way for us programmers to tell the difference.

Actually, when doing bitwise operations, bits being ordered in little endian can be quite confusing. (i.e, when masking off the top four bits of a number, you must do "num & 0x0fff")


Only if you loaded the bytes into memory sequentially... if you read a little endian word from storage, then you can treat it as a normal binary.

_________________
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su


Top
 Profile  
 
 Post subject: Re: Why little endian!
PostPosted: Sat Dec 26, 2020 9:33 pm 
Offline
Member
Member
User avatar

Joined: Wed Aug 17, 2016 4:55 am
Posts: 251
Gotta love how the consensus these days seems to be "because it allows you to resize integers" (though on big endian you can achieve the same by apply an offset to the address as needed)…
eekee wrote:
There's another argument for little-endian, but it doesn't apply to many OSs: In arbitrary-precision calculations, adding or subtracting numbers needs to start with the low digits for the carry to propagate correctly. (Yes, even though you borrow in the other direction when doing subtraction longhand. 2s complement is awesome like that.) I don't know about multiplication and division.
…but I believe this is the correct answer, at least originally. Don't forget that the difference between little and big endian dates back to the earliest CPUs, and especially was critical with the 8-bit ones (e.g. on 6502 anything larger than 8-bit was in the realm of arbitrary precision), and even for CPUs that could work on larger data it gave the possibility to start performing the calculation before the whole number was fetched (though I'm not sure how common that actually was).

Not so important nowadays, but it stuck and x86 was originally designed back when this kind of stuff was still relevant too. There really isn't much of a difference other than big endian being seemingly easier to read (and only because of how we lay out bytes in writing, shouldn't they be really right to left and bottom to top? we do say that higher memory addresses are at the "top" of memory after all…)


Top
 Profile  
 
 Post subject: Re: Why little endian!
PostPosted: Wed Dec 30, 2020 5:28 pm 
Offline
Member
Member

Joined: Wed Mar 09, 2011 3:55 am
Posts: 509
I'll note that whether big or little endian seems more "natural" depends greatly on how it is presented visually. When reading left-to-right with arabic numerals with the LSB on the right, Big Endian seems most natural:

Code:
Increasing addresses ------------>
Big Endian: DE AD BE EF
Little Endian: EF BE AD DE


But sometimes a vertical presentation of addresses with high addresses being higher on the page and lower addresses being lower is helpful (because high addresses being located higher than lower addresses is a useful mnemonic device). In this case, Little Endian seems most natural:

Code:
^    Big Endian:            Little Endian
|     EF                         DE
|     BE                         AD
|     AD                        BE
|     DE                        EF
|
|
|
| Increasing addresses


But then again, sometimes a vertical presentation with higher addresses being lower on the page is used (because in the usual reading order for western languages, a lower position on the page is later than a higher position). In this case, Big Endian becomes more intuitive again.

But keep in mind that the document in which "Big Endian" and "Little Endian" were first applied to byte order was titled "On Holy Wars and a Plea for Peace", and that it was written in 1980. Enough people have held the opinion that either byte order is "superior" or "more natural" strongly enough for the debate to be labeled as a "holy war" for at least 40 years now. It will continue to be hotly debated for the foreseeable future.

Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group