Assembly Language Basics Presentation
Assembly Language Basics Presentation
Language
Basics
Presented by:
Rajat Chamaria
Saurabh Sharma
Agenda
• Layout of an Assembly Program
• Data Segment
• Intereupts
• Input From Keyboard
– Character, String, and Integer
• Print on Screen
• Working with Turbo Debugger
• Recursion
• Passing Parameters
– By reference
– By value
Layout of an Assembly Program
– Defining an array:
Arr dw 15 dup(0)
Arr dw 1,3,6,8,9
– Defining a string:
str db “This is a string”,’$’
new db 0dh,0ah,’$’
Interrupts
• int 21h
– Dos interrupt
– Uses function code from ah to specify its action
• int 00h
– BIOS interrupt
– Invoked by an attempt to Divide by zero
• int 10h
– Used for video input/output
– Clears the screen when ax contains 03h
Inputing data from keyboard
• Input a Character
– Uses subroutine 01h of int 21h
– Value will be stored in AL
mov ah,01h
int 21h
• Input a String
• Input an Integer
Input A String
• Steps to follow
1. Declare a string variable str(say)
2. Load DI with the address of ‘str’ variable
3. Input a character and check for ‘Enter’ key
• If ‘Enter’ is pressed jump to step 6
4. Move this character in memory at [DI]
5. Increment DI and jump to step 3
6. Move ‘$’ sign at [DI] to indicate the end of
string
7. Return to main
Input A String
get_string proc near
get_string endp
Input an Integer
• Steps to follow
1. Clear BX for saving intermediate values
2. Input a character which goes in AL
3. Check for ‘Enter’ key
• Jump to step 7
4. Check for ‘Minus’(-) sign
• Set DI = 1 if Minus key is pressed
5. Subtract 48 to change in numerical value
6. BX=BX*10 + AX and jump to step 2
7. Save in AX from BX
8. Negate the value in AX if Di=1 and return
Input an Integer
• Steps to follow:
1. Check Whether the number is negative
i. Print Minus sign ‘-’ first
ii. Negate the number
• C:\TASM\BIN> td filename.exe
Program’s Reigon
Register’s Reigon
Flag’s Reigon
Stack’s Reigon
Data Segment
mov ax,5108
mov ds,ax
mov es,ax
mov ax,000A
mov bx,0014
mov cx,001E
mov dx,0028
mov ah,[0001]
mov si,0001
mov ah,4C
mov al,[0000]
int 21h
Recursion
GCD: proceed:
integer GCD(m,n )
pop si mov cx,ax {
pop bx mov dx,0 if n==0
pop ax div bx return m;
Else
push si
{
cmp bx,0 push cx
r=m % n;
push bx return GCD(n,r);
jne proceed
}
ret push bx }
push dx
call function
Contd…
STACK
BP
RET MAIN
Offset of Z
-
Thank You