Home
Username:
Password:
Assembly Language Programming Tutorials

Performing Bit Operations / Endians




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

I have made references to the fact that Intel reverses the order of the bytes when copying data from registers into memory and from memory into registers. For the most part, this process is automatic and can be ignored. But there are exceptions. You need to understand it because it can cause confusion in certain circumstance. First you need to know that the two terms Big Endian and Little Endian refer to the left end of the value. If this left end is the least significant byte, it's a Little Endian value. If the left end is the most significant byte, it's the Big Endian value. The Intel family of chips are Little Endian machines. That is, the values stored in memory are in reverse order of the bytes stored in a register. Now, it is the bytes that are reversed, not the bit. The bytes are simply stored in reverse order. The top diagram here is of a 32-bit number with the bytes in memory stored zero, one, two, three order. The opposite of that of a register. The second diagram is of a 16-bit value with a byte stored in the least significant first order again. Reverse from any register value. This has some odd consequences that you need to be aware of. The least significant bit, the one that determines whether a number is odd or even, is the right-most bit of the byte on the left and the sign bit is the left-most bit of the byte on the right. So you have to know how long a value is before you can determine whether it's positive or negative. The Little Endian thing has effects on your life in some special ways. First, you must know the length of a data item before you load it from memory into a register. If you load only part of a value, you need to know which bytes you'll be getting, which part. In debugging your program, you may want to look into memory and see what's there. If the program that dumps memory for you doesn't know the data types, that is if it's a simple raw dump, you will need to reverse the bytes as you read them to be able to make sense out of what you see. But the most difficult problems come about when you write data to a file. If you transmit the file to another computer, it may be one of a different Endian and the data gets scrambled. Most common file formats specify Big Endian or Little Endian so your program must be ready to reverse bytes if necessary. You can't assume one or the other; you need to know. This short list will give you an example. Some of them are as you would suspect, but some are not. You would expect BMP files to be Little Endian but MacPaint is also Little Endian and it originated on the Macintosh Big Endian machine. Postscript is neither because it's text, which is always in the right order, the order that you would expect, from left to right. The last two, TIF and XWD can be either way. They both contain flags that specify whether they are Big or Little Endian. The Big Endian order is sometimes called the Network Order because it's the order of data on the Internet. If you deal with Internet protocols and headers on a Little Endian Machine, you will need to be ready to convert the integers including the 32-bit binary form of an IP address to and from Big Endian or from Network Order. The term comes from the two warring countries in Gulliver's Travels. One county had a law that soft-boiled eggs should be open from the big end and the other country opened them from the little end so they were known as Big Endians and Little Endians. You will also see the term Middle Endian. It's the name applied to any other byte order such as 3412 or you'll find the Middle Endian used for pac decimal data formats in some mini computers. So you may come across it if you deal with special data.

Tutorial Information

Course: Assembly Language Programming
Author: Arthur Griffith
SKU: 33995
ISBN: 1-935320-44-0
Release Date: 2009-05-28
Duration: 5.5 hrs / 70 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available