Thursday, 28 June 2012

Create Your First Assembly Program Step By Step

Step 1. First let us define what is an Assembly language.



A programming language that is once removed from a computer's machine language. Machine languages consist entirely of numbers and are almost impossible for humans to read and write. Assembly languages have the same structure and set of commands as machine languages, but they enable a programmer to use names instead of numbers.

Each type of CPU has its own machine language and assembly language, so an assembly language program written for one type of CPU won't run on another. In the early days of programming, all programs were written in assembly language. Now, most programs are written in a high-level language such as FORTRAN or C. Programmers still use assembly language when speed is essential or when they need to perform an operation that isn't possible in a high-level language.

- from: http://www.webopedia.com

In order to create program in this language we need an assembler. Assembler is a program that is use to translate assembly code into machine language.

Step 2. Download an assembler:
Go to: http://eji.com/a86/ and download the latest A86 assembler, also in this site you can download D86 disassembler.


List of files in a86.zip:


The A86.COM file is what we want, so please copy this file and paste in another folder (create this folder), ex. project.

Step 3. Open MS DOS program.


You can open this thru: Start -> Run -> Type: cmd and click the OK button (for older operating system usecommand).

Step 4. Create a folder in drive C: named project with a86.com inside.


Step 5. In DOS, go to your project folder. Type: cd c:\project and press enter.


Step 6. Open an editor in DOS.
In DOS, type edit to open an editor.
C:\project>edit



Step 7. Create simple assembly program.
Write this code in this editor (edit). You can use other tool also like notepad.
01start: jmp main
02 
03main proc
04        mov ah,02h
05 
06        mov dl,"H"
07        int 21h
08        mov dl,"e"
09        int 21h
10        mov dl,"l"
11        int 21h
12        mov dl,"l"
13        int 21h
14        mov dl,"o"
15        int 21h
16        mov dl,0a
17        int 21h
18        mov dl,0d
19        int 21h
20        mov dl,"G"
21        int 21h
22        mov dl,"a"
23        int 21h
24        mov dl,"r"
25        int 21h
26        mov dl,"c"
27        int 21h
28        mov dl,"i"
29        int 21h
30        int 20h
31 
32main endp
33end start

Save this file as hello.asm in project folder.


Step 8. Compiling and running the program.
To compile just type: a86 hello.asm and press enter.


If no error(s) found, otherwise you need to debug or edit it.
To run: just type: hello and press enter.



Good luck! have a nice coding...

0 comments:

Post a Comment

Internet-PublicLab. Powered by Blogger.