LETS DISCUSS DEEP ABOUT ASSEMBLY LANGUAGE

in steemgigs •  7 years ago 

unnamed.jpg
Image

We are going to meet the real stuff about programming in assembly language. I will try as much as possible to be more elaborate even if you are new in programming you can follow up. So I urge you to grab a cup of chilled water as we ride on in this topic… wow, I think I heard some people exclaiming Ride on!. Sure I will.

Most serious programming efforts in assembly languages are done with the ASSEMBLER. What is the function of the assembler? When we write mnemonic, it translates them into machine code. There are many assembler programs available in the market but two are very poplar and common.

These are the MICROSOFT MACRO ASSEMBLER (MASM.EXE) and BORLAND TURBO ASSEMBLER (TASM.EXE). please note that I will be using these terms frequently so always refer back. Now your assembly language program will almost certainly on either of the two with little or no modifications. Most of the conventions I will use in this article will however follow the rules set by the MASM.

In creating an assembly language program, let’s take an instance, the Microsoft text editor program (EDIT.COM) is usually employed to create the assembly language source code. Normally, each source module is named as a file with an extension .ASM.
Each source program module is assembled to an object program code (.OBJ file) using the assembler (let’s say its MASM.EXE) and a linker program (LINK.EXE) is then used to combine or link together to produce an executable program module with abbreviation (.EXE).
Now the final product, that’s the executable program file can now be executed at the MS-DOS command line… hope I am making sense a bit, lets continue.
images.jpg
Image

There are things you should watch out during your program coding or editing. Debug assumes (will explain debugging in a separate topic) that all numbers are in hexadecimal number system and does in anyway accept any other number system. The assembler on its own assumes that all numbers are in decimal.
You can however place the suffix h (or H) after a hexadecimal number. Will explain more on this later.
Again the assembler can become confused by numbers such as Ach, which looks like a name or an instruction. In the other to avoid this, always type a zero before a hex number that begins with a letter. For example type 0ACh not ACh.

Spacing and comments are important in your source code. They help the program to be readable. You will appreciate this when you begin really to write programs for the assembler.

It is difficult to appreciate any assembler source code without adequate spacing and comments. Because operations at assembly level are quite far lower than the human level of communication, it will take a lot of efforts to read and understand poorly documented program source codes. So my dear, be wise and professional when you code!

PROGRAM ASSEMBLY
The assembler (MASM) assembles your source program codes and translates it into an object (machine, language) program. This resulting program is usually called object program. This files contains a lot of bookkeeping information that the Linker uses to translate it a standalone .exe file.

MASM will need the following information when it begins the translation process;

The name of the file containing the source program
The filename for the object program to be created
The destination of the program listing
The filename for the information that is later processed by the cross-reference utility (CREF.EXE)
Now you can invoke MASM in two ways; one is that you can just type MASM and press the Enter key. MASM will then prompt you the names of each input and output files. You will be offered default names. If you type a name, this will then override the suggested name.

If you press Enter without typing any name, you will notice that the suggested default name will be used. I think I will try to show you an example, a typical session with the assembler (MASM) entered without any argument.

C:> MASM

Microsoft ® Macro assembler 6.0
Copyright © Microsoft Corp. 1981 – 1983. All right reserved.
Source filename [.ASM] : PROG1
Object filename[PROG1.OBJ]:
Source listing [NLS.LST]:
Cross-reference [NUL.CRF]:

49006 Bytes symbol space free

0 warning errors
0 severe errors
C:>

In this example we assumed that all the name of your source code file is PROG1.ASM. now we can supply all parameters in the command line as;
MASM *[options] source, [object], [listing], [crossref]

These commands se the file PROG1 as the source, generates an object code file PROG1.OBJ and sends the listing and cross-reference files to the bit bracket. MASM also expects several optional switches in the command line to control generation and output files. You ought to contact the MASM manual or a good MD-DOS manal for these optional switches.

PROGRAM LINKING
The object program produced by the MASM from a source file is in a form that contain unresolved references to external locations or subroutines. This object file is written in a common format that is also produced by the various high-level compilers (sch as Fortran and C) that run under MS-DOS. The computer cannot execute object modules without further processing.

Now the Microsoft object linker (LINK.EXE) accepts one or more of these object modles, resolves external references, which includes any of the necessary routines from the designated libraries. It performs any necessary offset relocations, and writes a file that can be loaded and executed by the MS-DOS. NOTE that the output of the LINK is always in .exe load module format.
Figure2.1-CompLang.gif
Image

THE EXE2BIN UTILITY

The EXE2BIN utility normally EXE2BIN.EXE transforms a .EXE file created by LINK into an exectable .COM file. In programming, any .EXE file must meet the following prerequisites before it can be successfully converted into a .COM file by EXE2BIN utility;

It must contain more than one declared segment and cannot define a stack
It must be less than 64kb in length.
The first location in the file must be specified as the entry point in the source code’s END directive.
It must have its origin at 0100H
Although .COM files are somewhat more compact than .EXE files, you would not always want to see them. Programs that use separate segments for codes, data, and stack are much easier to port to other environments.

Unlike any other programming utilities, EXE2BIN does not have an interactive mode. It always takes its source and destination file names, separated by spaces, from the MS-DOS command lines.

So in summary, you would have noticed that it is possible to combine modules written in high-level languages (HLL) with those of the assembler. The compiler translates a HLL source code into an object module, which can be combined with other object modules from different sources by the LINKER to produce an .EXE file. So in this case, the linker may also search the HLL runtime libraries to resolve object references.

Oh yes!...so glad we made it to the end of this great study, sometimes its vital to know what always happen behind the scene. Thanks so much and once again i still remain your humble friend @angelfidel

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!