The Assembler / Hello world
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
This is the first lesson in the course with source code. This lesson includes some very simple, but complete Assembly Language Programs. Each one is a Hello world program. All they do is say Hello World and then quit. Let's start with DOS. Anyway, this is the shortest Hello world program that I know of. Let me explain it one line at a time. The first line is an org instruction. Org is short for origin. This is an instruction to the Assembler about where to put the program in memory. I'll have more about all that later. This next instruction puts the address of the character string in the dx register. Remember, this is DOS so we only deal with 16-bit addresses. Next, the number 9 is copied into the ah register. Remember ah, that's an 8-bit register. Then there is an interrupt instruction. Instead of an external stimulus the int instruction issues an internal stimulus for the interrupt routine identified with a hex number 21. In effect, the program interrupts itself. This happens to be an interrupt for the DOS service routines. It expects the values to be passed by being stored in registers, which we did; 9 in the ah tell it what to do and the address in dx tells it what to do it with. Here at the bottom is the string that is to be displayed. The hex value d is the carriage return character; a is the line feed; and, the dollar sign is the DOS character which terminates a character string. Once the display has finished, the interrupt routine is called again. This time the hex value for c is in the ah register. This ends the program. You have to tell it specifically to stop, or whatever garbage is in memory following the program will be executed and then anything can happen. To assemble it and get it ready to run this is all you need. It is not necessary to specify the output file format because the simple unadorned binary format is the default for the Assembler. To run it, just enter its name. It displays one line of text then quits. Alright, here's another one. This is pretty much the same program except for a Linux system. Let me start by describing the string. The string is declared using a db, as in the previous example, but there are differences. For one thing, the string ends with a single carriage return character and it's necessary to specify the length of the string as a constant value because the string has no terminator. The equ directive does not declare any memory, it just makes it constant. More about that later. This program is in sections. The data has its own section. And the executable code has its own section. You can actually put them in any order you want in the program because the Linker reorganizes them anyway, and the execution of the program begins at the global label named start. The system call for writing to a file is number 4. The number of the file we want to write to is number 1, already open, that's standard out. The address of the string and its length are copied into Registers, then the interrupt is triggered and the writing takes place. The registers are then set for the exit routine and a system call with an exit code value of zero is made and the interrupt is triggered again. You assemble it this way. The format for the program is elf, which is the Linux linkable object format, and the output file is Hello Linux dot o. It takes only seconds to assemble. Using the Linker named ld, you can link the object file into an executable file, then when you want to run it, all you have to do is enter its name on the Command Line. Now, to make sure that Linux looks in the current directory you can enter the name preceded by a and a/, otherwise you would need to have the current directory in your path. There are other Hello world programs, but these two are about as simple as it gets. If you feel like some things were skipped in my description, you're probably right. The next lesson starts to fill in some details.
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
United States 