Vous êtes sur la page 1sur 16

Write a program to read string using the character reading function and display the string using character

displaying function title read and display string using character function .model small .stack 32 .data str db 25 dup(?) newline db 0dh,0ah,'$' .code main proc far mov ax,@data mov ds,ax mov cx,25 mov dx,00 mov bx,offset str mov ah,01h int 21h mov [bx],al inc dx inc bx cmp al,0dh loopne l1 mov cx,dx mov ah,09h mov dx,offset newline int 21h mov ah,02h mov bx,offset str mov dl,[bx] int 21h inc bx loop l2

l1:

l2:

mov ax,4c00h int 21h main endp end main

1|Page

Write a program to display all ASCII character from 0 to 255 (decimal value) TITLE PROGRAM TO DISPLAY ASCII CHARACTER FROM 0 TO 255 .MODEL SMALL .STACK 32 ;32 bytes stack segment defined .DATA .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX ;DATA SEGMENT REGISTER INITIALIZATION MOV DL,00 MOV AH,02H INT 21H INC DL CMP DL,255 JB BACK MOV AX,4C00H INT 21H MAIN ENDP END MAIN

;SINGLE CHARACTER DISPLAY

BACK:

;REQUEST FOR NORMAL EXIT ;END PROCEDURE

WAP to read string and display each word in separate lines TITLE READ STRING FROM USERS & DISPLAY EACH WORD IN SEPARATE LINES .MODEL SMALL .STACK 64 ;STACK WITH 64 BYTES SIZE .DATA STR DB 30 DUP(?) NEWLINE DB 13,10,'$' ;OR --> 0DH,0AH,'$' .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX ;DATA SEGMENT INITIALIZATION MOV CX,30 MOV DX,00 MOV BX,OFFSET STR MOV AH,01H ;KEYBOARD CHARACTER INPUT FUNCTION NUMBER INT 21H

L1:

2|Page

MOV [BX],AL INC BX INC DX CMP AL,0DH LOOPNE L1

;STORE ASCII VALUE OF KEY PRESSED INTO MEMORY ;WITH OFFSET GIVEN BY BX REGISTER ;COUNTS CHARACTER ENTERED ;COMPARE WITH ENTER KEY

MOV CX,DX ;COPY N0. OF CHARACTERS TO CX MOV AH,09H MOV DX,OFFSET NEWLINE INT 21H ;INSERT NEWLINE MOV BX,OFFSET STR MOV AH,02H MOV DL,[BX] CMP DL,' ' ;COMPARE CHARACTER TO BE DISPLAY WITH SPACE KEY VALUE JNE NOSPC ;JUMPS IF NOT EQUAL RESULT FOR ABOVE COMPARISION MOV AH,09H MOV DX,OFFSET NEWLINE INT 21H INC BX LOOP L2 MOV AX,4C00H INT 21H MAIN ENDP END MAIN ;END 'MAIN' PROCEDURE ;TERMINATE PROGRAM

L2:

NOSPC:

Write a program to count and display its total vowel characters from user entered string TITLE READ STRING AND COUNT THE VOWELS AND DISPLAY IT .MODEL SMALL .STACK 64H .DATA PARALST LABEL BYTE MAXCHAR DB 60 ACTCHAR DB ? STR DB 60 DUP(?) VOWEL DB 0 NEWLINE DB 13,10,'$'
3|Page

CHECKSTR DB 'a','e','i','o','u','A','E','I','O','U' .CODE MAIN PROC FAR MOV AX,@DATA ;for locating the data segment MOV DS,AX LEA DX,PARALST MOV AH,0AH INT 21H CALL NEXTLINE MOV CL,ACTCHAR MOV CH,0 MOV BX,0 L1: PUSH CX MOV DL,STR[BX] MOV SI,0 MOV CX,10 ;enter the string

;call procedure "nextline" for newline

;no. of vowels to be compared with each character

L3:

CMP DL,CHECKSTR[SI] JZ L2 INC SI LOOP L3 JMP L4 INC VOWEL MOV AH,02H INT 21H INC BX POP CX LOOP L1 CALL VOWELCOUNTDISP MOV AH,01H INT 21H MOV AX,4C00H INT 21H ;count vowel charater found ;for displaying each vowel character found

L2:

L4:

;get back no. of character for checking each

MAIN ENDP

4|Page

NEXTLINE PROC NEAR LEA DX,NEWLINE MOV AH,09H INT 21H RET NEXTLINE ENDP VOWELCOUNTDISP PROC NEAR MOV CX,10 MOV AL,VOWEL MOV AH,0 MOV BX,0 LABEL1: MOV DX,0 DIV CX ADD DX,30H PUSH DX INC BX CMP AX,0 JA LABEL1 MOV AH,02H MOV CX,BX

;convert vowel number into ASCII format for displaying

;load total number to be displayed into cx for loop

DISP:

POP DX INT 21H LOOP DISP RET VOWELCOUNTDISP ENDP END MAIN

;display number after converting it into ASCII format ;loop continue until number ends

WAP to read a string and display it on center of window 2,10 * 22,70 title display string on center of window defined .model small .stack 64h .data string label byte maxlen db 40 actlen db ? input db 40 dup("$") message db "Please enter a string: ","$"
5|Page

.code main proc far mov ax,@data mov ds,ax mov ah,09h ;ask for string input mov dx,offset message int 21h mov ah,0ah lea dx,string int 21h mov ah,06h mov al,00h mov bh,07h mov cx,0000h mov dx,184fh int 10h mov ah,06h mov al,14h mov bh,30h mov cx,020ah mov dx,1646h int 10h mov al,actlen shr al,1 mov dl,40 sub dl,al mov ah,02h mov bh,00h mov dh,12 int 10h ;enter string

;for complete window clear

;for clearing defined window area 2,10 * 22,70

;set the cursor at the center by ;by dividing the string into half

;center column (width) ;page number (0 for default) ;center of row

mov ah,09h mov dx,offset input int 21h

6|Page

mov ax,4c00h int 21h main endp end main WAP to take single digit from user and display sum upto that number starting from 0. title take a single number as input and display the sum upto that number from 0 .model small .stack 100 .data input db "Please enter a number: ","$" output db "The sum is: ","$" newline db 0dh,0ah,"$" sum dw 0 .code main proc far mov ax,@data mov ds,ax mov ah,09h lea dx,input int 21h mov ah,01h int 21h mov ah,00 sub al,30h mov cx,ax add sum,cx loop l1 mov ax,sum mov dx,0 mov bx,0 mov cx,10 div cx add dx,30h push dx inc bx mov dx,00 ;ask for input number

;request for keboard input character

;find actual number by converting ASCII ;find sum

l1:

l2:

7|Page

cmp ax,00 ja l2 mov ah,09h lea dx,newline int 21h mov ah,09h ea dx,output int 21h mov cx,bx mov ah,02h pop dx int 21h loop l3

l3:

mov ax,4c00h int 21h main endp end main

WAP to add all data between 50 and 150 from the table of data stored in memory title to add all the data of table between 50 and 150 .model small .stack 32h .data table db 55,12,34,156,234,90,140,200,99,6 ;table of data of each 1 byte message db "The sum is : ","$" sum dw 0000 newline db 13,10,"$" .code main proc far mov ax,@data ;initialization of data segment mov ds,ax mov si,offset table mov cx,10 ;counter for 10 data mov ah,00h mov al,[si]

l1:

8|Page

l2:

cmp al,50 jbe l2 add sum,ax inc si loop l1 mov ax,sum mov dx,00 mov bx,00 mov cx,10 div cx add dx,30h push dx inc bx mov dx,00 cmp ax,00 ja l3 mov ah,09h lea dx,newline int 21h mov ah,09h lea dx,message int 21h mov cx,bx mov ah,02h pop dx int 21h loop l4

;jump on below or equal

;stored sum is copied to ax register

l3:

;bx is used to count the number of ASCII character

;print one blank line

;print message

l4:

;display result in ASCII format

mov ax,4c00h int 21h main endp end main WAP to sort an array of 10 numbers stored in memory. Display the numbers in screen after sorting title sorting 10 numbers stored in memory and disply them afer sorting .model small
9|Page

.stack 100h .data data_arr db 3,5,8,2,5,93,9,10,10h,4 message db 'THE SORTED ORDER IS: ','$' tablike db ' ','$' .code main proc far mov ax,@data mov ds,ax l1: mov si,offset data_arr mov bl,00h mov cx,0009h l2: mov al,[si] inc si cmp al,[si] jbe ahead ;swapping mov dl,[si] mov [si],al dec si mov [si],dl inc si mov bl,01h ahead: loop l2 dec bl jz l1 lea dx,message mov ah,09h int 21h ;for display mov si,offset data_arr mov ch,00 mov cl,0ah no_of_times: mov ah,09h ;one space separation for each digit mov dx,offset tablike int 21h
10 | P a g e

mov ah,00 mov bx,00 mov al,[si] push cx mov cx,10 no_of_digits: mov dx,0 div cx add dx,30h push dx inc bx cmp ax,0 ja no_of_digits mov ah,02h mov cx,bx popping: pop dx int 21h loop popping inc si pop cx loop no_of_times mov ax,4c00h int 21h main endp end main WAP to find largest number among 10 numbers stored in memory & display it TITLE TO DISPLAY THE LARGEST AMONG 10 NUMBERS .MODEL SMALL .STACK 64 .DATA ARR_NUM DB 34,67,150,55,23,98,35,43,88,23 .CODE
11 | P a g e

;(dx:ax/cx= ax dx/cx)

MAIN PROC FAR MOV AX,@DATA MOV DS,AX MOV BX,00 MOV CX,09 MOV AL,ARR_NUM[BX] L1: INC BX CMP AL,ARR_NUM[BX] JAE L2 MOV AL,ARR_NUM[BX] L2: LOOP L1 MOV AH,00 MOV BX,00 MOV CX,10 MOV DX,00 A1: DIV CX ADD DX,30H PUSH DX INC BX MOV DX,00 CMP AX,00 JA A1 MOV AH,02H MOV CX,BX A2: POP DX INT 21H LOOP A2 MOV AX,4C00H INT 21H MAIN ENDP END MAIN WAP to generate multiplication table for user given single digit, and display them. TITLE GENERATE MULTIPLICATION TABLE OF USER GIVEN SINGLE DIGIT .MODEL SMALL .STACK 64H .DATA
12 | P a g e

;COMPARISION DONE FOR 9 TIMES

.CODE MAIN PROC FAR MOV AX,@DATA MOV DX,AX MOV AH,07H INT 21H SUB AL,30H MOV BL,01 MOV BH,AL MOV CX,10 BACK: PUSH CX PUSH BX MUL BL MOV CX,10 MOV BX,00 L1: MOV DX,00 DIV CX ADD DX,30H PUSH DX INC BX CMP AX,00 JA L1 MOV CX,BX MOV AH,02H POP DX INT 21H LOOP L2 MOV AH,02H MOV DL," " INT 21H POP BX MOV AL,BH INC BL POP CX LOOP BACK ;A BLANK CHARACTER IN PRINTED TO ;SEPARATE TWO NUMBERS ;CONSOLE INPUT WITHOUT ECHO

L2:

13 | P a g e

MOV AX,4C00H INT 21H MAIN ENDP END MAIN WAP to display string stored in memory in reverse order title program to display the stored string in reverse order .model small .stack 100h .data str1 db "Programming is fun.","$" str2 db 50 dup ("$") .code main proc far mov ax,@data mov ds,ax ;data segment initialization mov si,offset str1 mov di,offset str2 mov cx,00 l1: mov dl,[si] cmp dl,"$" je l2 inc cx inc si jmp l1 l2: dec si mov bl,[si] mov [di],bl inc di loop l2 mov ah,09h mov dx,offset str2 int 21h mov ax,4c00h int 21h main endp end main
14 | P a g e

;cx register initialized to 0 to count charaters

;increment counter ;increment offset address of source string

;decrement si offset before copying character

;display reverse ordered string

WAP to add sequence 1+2+3+ up to 100 and display result in HEX format. title program to add sequence 1+3+5+... up to 100 terms and display result in hex format .model small .stack 64 .data sum dw 00 .code main proc far mov ax,@data mov ds,ax mov cx,100 mov ax,01 l1: add sum,ax add ax,02 loop l1 mov ax,sum mov cx,16 mov bx,00 l3: mov dx,00 div cx cmp dx,09 jbe l2 add dx,07h l2: add dx,30h push dx inc bx cmp ax,00 ja l3 mov cx,bx mov ah,02h popping: pop dx int 21h loop popping mov ax,4c00h int 21h main endp end main
15 | P a g e

;add sequence

;copy sum to ax register ;copy base value of hex format for dividing data ;bx is used to count number of hex data

;compare each single data with 9 digit

16 | P a g e

Vous aimerez peut-être aussi