;A to Z charcters are in between 65 to 90 asci
org 100h
mov ax,64d;taking 64 in decimal
mov cx,0;counter
loop:
add ax,1
add cx,1
mov dx ,ax
mov ah , 2h
int 21h ; interrupt for printing
cmp cx,26
jne loop
end:
MOV AH,4CH;terminating program
INT 21H
Two different interrupts for char input
Method 1
;this program gets a char from key board and displays it on screen
org 100h
; getting input from keyboard
MOV AH, 00h
INT 16h
;we have got our input in al register
;now showing it on screen
MOV AH, 0Eh
INT 10h
mov ax, 4ch; terminating
int 21h
Method 2
;this program gets a char from key board and display it on screen
org 100h
; getting input from keyboard
mov ah, 1; get a char and display it
int 21h
mov ax, 4ch; terminating
int 21h
Converting to upper case
;This program prints in upper case,
;if any character is present in lower case, it will be converted to upper case
org 100h
arr dw 'H','a','P','p','y',' ','&',' ','j','O','Y' ; this array has a sentence
length dw 11 ;length of array
for_upper dw 32
lower_limit_97 dw 97
upper_limit_122 dw 122
two dw 2
mov bx,0; starting index
jmp start
uppercase: ;converting to upper case
mov cx,[for_upper];moving 32 to cx register
sub [arr+bx],cx;this line converts char from lower to upper case
ret
print: ;printing
mov dx ,[arr+bx]
mov ah , 0x2
int 21h
ret
start:
;if char is not in between 97 and 122, it means its in upper case
;97 to 122 contains alphabets in lower case
mov cx,[lower_limit_97]
cmp [arr+bx],cx;checking if character is less than 97
jl ok
mov cx,[upper_limit_122]
cmp [arr+bx],cx;checking if character is greater than 122
jg ok
call uppercase
ok:
call print
add bx,[two];we are using word so we will add 2 for moving to next index
dec [length]
jnz start;if lenght is not zero jump to start
end:
MOV AH,4CH ;terminating
INT 21H
String Input
;This program shows how you can get a string input
;from keyboard, Input is stored in variable named string
;It also shows how you can distribute, your program in segments
data segment;this is data segment
size= 7
string db size dup (?);reserving space in memory equal to size=7
Enter_string db 'Enter a string:' ,13,10,'$'
ends
stack segment;this is stack segment
dw 32 dup(0)
ends
code segment;this is code segment
start:
;our code segment is seperate from data segment
;so, we have to tell ds & es about our data segment
;because we need data in code segment for use
mov ax,data
mov ds, ax
mov es, ax
mov cx, size;cx will contain size,we need it to
; check if we have got 10 inputs from key board
lea dx, Enter_string;it will display a text on screen to enter text
mov ah, 9
int 21h
call get_string;input string from keyboard
mov ax, 4ch;terminating
int 21h
get_string:
mov si, 0; si will be used as index
mov bx, offset string
get_char:
mov ah, 1; get a char from keyboard
int 21h
mov [bx][si], al; saving input in string
inc si
cmp si,cx;if si=7 than, no need to take more input
jne get_char
ret
ends;code segment ends here
Clearing Screen
;print all ascii characters and then clear the screen
org 100h
jmp start
start:
mov ax, 0xb800;for accessing video memory, as we want to print some thing on screen
mov es, ax
mov di,100 ;we want to start printing from location 100
xor al,al ;al contains ascii codes
;printing string
print:
mov byte es:[di],al ;printing value of al at location=di
mov byte es:[di+1],0x07;color attribute,you can change it
add al, 1;Moving si one index forward
add di, 2;Moving di two index forward
;because di has char and di+1 has color attribute so, next char should be at di+2
cmp di, 1000
jne print
;clearing screen
xor di,di ; same as mov di,0
nextchar:
mov word es:[di],0x0720; 0720 is for clearing screen
add di,2
cmp di,1000; you can change this value to clean more or less area of screen.
jne nextchar
MOV AH, 4CH ;terminate program
INT 21H
Clearing screen in progress
Clearing screen completed
No comments:
Post a Comment