Assembly Language Programming is an indigenous programming method used for PCs. An assembly language programmer has to understand the internal architecture of the Processor and he has to program accordingly.
The program given here is a simple example for printing a message on the console.
Before going for assembly language programming make sure that you have installed TASM or MASM assembler in your system.
Then type your program using any editor and save it with an extension .asm.
(see program hello.asm.)
Source CodeThe program given here is a simple example for printing a message on the console.
Before going for assembly language programming make sure that you have installed TASM or MASM assembler in your system.
Then type your program using any editor and save it with an extension .asm.
(see program hello.asm.)
hello.asm
; This program prints the message "Hello world" on the console
;Defines data segment
data segment
; data is the name of the data segment
; msg is the variable used to store message
msg db "Hello world$"
data ends
code segment ; defines code segment where program code is available
;tells the assembler about active segments.
assume cs:code,ds:data
; logical beginning of the program
start:
;data segment register(ds) has to be initialized explicitly
mov ax,data
mov ds,ax
;use the DOS interrupt function (09h) to display a string.
mov dx,offset msg ; address of the string must be available in dx reg.
mov ah,09h
int 21h
; following lines are necessary to bring
; the program control back to the DOS prompt
mov ax,4c00h
int 21h
code ends
end start
Output
E:\TASM>hello
Hello world
E:\TASM>
How to test this program on your computer
Assembling/Compiling the program
To compile/assemble the program use command like TASM <program> or MASM <program>
as shown below.
E:\TASM>tasm hello.asm
Turbo Assembler Version 3.1 Copyright (c) 1988, 1992 Borland International
Assembling file: hello.asm
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 459k
E:\TASM>
Then link the program using TLINK command as explained below.
E:\TASM>tlink hello
Turbo Link Version 2.0 Copyright (c) 1987, 1988 Borland International
Warning: no stack
E:\TASM>
Finally to see the output simply type the program name on the command prompt.
E:\TASM>hello
Hello world
E:\TASM>
No comments:
Post a Comment