if you want an in depth knowledge of assembly language click here
editing a program in assembly language
An assembly language program can be entered using a text editor available.
ex:notepad,edit,ne
The edited file should be saved with the extension .asm
ex:abc.asm,test.asm
assebling a .asm program
An assembler converts assembly language program to its object code.
masm assembler is masm.exe.usually it is located at c:\masm611\bin
Suppose that your program is in a directory c:\abc and the program name is abc.asm.
Before calling the assembler set the path using
c:\abc\path=%path%;c:\masm611\bin
After setting your path assemble your program using
c:\abc\masm abc.asm
or
c:\abc\masm abc;
If there are errors in the program abc.asm the assembler will display the errors with line numbers.The programmer has to correct the errors and save it.Try to assemble the program again.If the program is error free, it will be converted to an object file, abc.obj.
linking the program
The following commands can be used to link the object program to an executable file abc.exe
c:\abc\link abc.obj
or
c:\abc\link abc;
executing a program
If linking is successful, you can execute the program using the following command line.
c:\abc\abc.exe
or
c:\abc\abc
Your first program("hello.asm")
Program to display "Hello World".
data segment
msg db "Hello world$"
data ends
code segment
start:mov ax,data
mov ds,ax
lea dx,msg
mov ah,9
int 21h
mov ah,4ch
int 21h
code ends
end start
code snippet to read a character from the keyboard
mov ah,1
int 21h
After the execution of the interrupt AL register will hold the ASCII value of the keypressed.
Ex:if you have pressed 0, the content of AL will be 30H
code snippet to print a character on the screen if it is printable and execute a control function if it is control character.
Ex: if you want to print 0 on the screen
mov dl,'0' //moving the character 0 to dl register
or
mov dl,30h
mov ah,2
int 21h
Ex: if you want to execute the carriage return function
mov dl,0dh
mov ah,2
int 21h
code snippet to read a number(less than 255)
in the data segment there is a variable var1 to store the number
ie var1 db 0
in the code segment
l1:mov ah,1
int 21h
cmp al,0dh
jz l2
sub al,30h
mov bl,al
mov bh,var1
mov al,10
mul bh
add al,bl
mov var1,al
jmp l1
l2:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment