Home
Username:
Password:
Assembly Language Programming Tutorials

Assembly Language Basics / It is All Bits




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

The pneumonics of an Assembly Language are not that important. Actually, they're not even necessary. The whole purpose is to generate a pattern of bits Ð ones and zeros Ð but how you go about doing that is up to you. You can see the bit patterns of a program in an Assembly Language listing. This is a simple example. All it does is compare the values of a couple of integers and make certain the smallest one is first. This is a listing of the program as it came out of the Assembler. You can get such a listing by specifying the l option and naming the list file. You can see lots of things in such a listing. For example, if you use the reserve instruction to set aside some word space the amount of space assigned to that label is listed here. This one is 4 because 4 bytes are to be assigned for each of these symbols. If a symbol had been for two double words instead of one, this would have been an 8. This is, of course, the bss section, so these values are not what is stored in memory; they're values stored in the object code and used by the system at load time to allocate memory. This is an example of the value stored in memory: it's the hex representation of the enter opcode. The two bytes following it are 60 for push ad, and 9c for push fd. The first thing this program does is initialize the two values to be sorted. This is the hex value for the opcode for copying a 32-bit constant value into a memory location. Now look at this. Part of the instruction is inside square brackets. That means it's a relocatal value. In this example the value is a zero offset from the top of the block of data. The actual value will be calculated depending on where the program is loaded into memory. This part of the instruction is the value 500 shown in hex. Now remember, with the Intel chip, numbers are stored in memory backwards so, the bytes are shown here the way they appear in memory. This is the first part and the second part of the 32-bit number. You have to reverse them to read what they are when they're loaded into a register or used in an expression. This is the number 200, also shown in hex in reverse order, and this is 4 offset into the data area with the offset shown in reverse order. In this program, before the numbers are sorted they are displayed by being loaded into registers and having the registers dumped. And, look at this. The address of the external function is shown as zero inside parentheses. This is the Assembler's way of showing an external reference. This value will be filled in by the Linker when all the modules are hooked together and that value will be adjusted again by the loader when the program is run. These six instructions are the heart of the program. The two values are compared and if they're out of order they are reversed. You can see here all the opcodes and the data references embedded inside them. In particular you can see an example of a short jump instruction. It is not jumped to an address. It jumps a number of bytes away from the current location. That way instruction is short and there is no relocation of an address necessary when the code is moved to a different location. But this same program can be written without using pneumonics for opcodes. It can be written by using pseudo ops creating bit patterns. For example, here is a declared double pseudo op that creates a 32-bit enter instruction. Notice that the hex digits are written in reverse order that they appear in the actual object code. The Assembler does it that way because when the Intel chip loads a value from disk it reverses it. These two 8-bit instructions are the two push instructions at the top of the function. This is the opcode for copying a 32-bit immediate value, a constant, into a memory location, and this is the memory location. It has to be declared by name so that when the module is relocated the address referred to it is adjusted by the Linker. Such a relocatable address is always shown in square brackets in the listing. This is the constant value, which is written in base 10, but converted to binary to be stored inside the instruction. It's shown listed here as a hex number. Coding it this way caused a necessity of one slight change to the program. The external function is called a little differently. It's called by having its address loaded into a register and then the address is called. That was done because the Assembler handles address resolutions differently in the call up code. I'll have more about this later in the chapter on Global Offset Table. Here is the main body of the function. It compares the two values and swaps them if necessary. As you can see it is all coded as declaratives with hex values and symbol references. This is the way the first computers were programmed, by entering all the ones and zeros. When the first Assemblers were devised and you could just type in names for the instructions, it was said that programming was automated. There would be no more need for programmers. Anybody could do it. They said the same thing again with the higher-level languages Fortran and Cobol, and they're saying it again now with IDEs and Drag and Drop, but they're still wrong. The point to all this is so that you know there is nothing magic about the names, the pneumonics, they only exist to make it easy for you to remember what to type in to get the bit patterns that you want. You can make up your own pneumonics if you want. At the top of this example is a macro that produces the code to store a constant value. Don't worry about how macros work just yet. This macro is called sti and it produces the three lines of opcodes shown here. In this version of the program the macro is used twice. I called it sti because it stores an immediate 32-bit value into a memory location. Here the instruction is used to store the number 500 in the location called value1. Now it does that by generating these three lines of code so as you can see you can make up any Assembly Language you'd like to use. A lot of people have done this and they get very elaborate with the languages and they call them compilers. The next lesson goes into some details about macros.

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