+ All Categories
Home > Documents > AssemblyProgsCS2012 (17th April 2012)

AssemblyProgsCS2012 (17th April 2012)

Date post: 24-Oct-2014
Category:
Upload: asad-ahmed
View: 108 times
Download: 0 times
Share this document with a friend
Popular Tags:
16
- 1 - .model small .stack 100h .code first proc mov dl,65 mov ah,02 int 21h mov dl,'b' int 21h mov ax,4c00h int 21h first endp end first ============================================= .model small .stack 100h .code main proc mov cx,26 mov dl, 65 mov ah,2 abc: int 21h inc dl loop abc mov ax,4c00h int 21h main endp end main ============================================= .model small .stack 100h .data xyz db "KUDCS",0dh,0ah,"$" .code main proc mov ax, @data mov ds, ax mov ah, 9 mov dx, offset xyz int 21h mov ax, 4c00h int 21h main endp end main ============================================= ;; This program displays the following sequence: ;; AaBbCcDdEe........Zz ;; .model small .stack 100h .code main proc mov cx,26 ; or mov cx,1ah mov bl,41h ; Code for 'A' mov bh,61h ; Code for 'a' mov ah,2 lbl1: mov dl,bl int 21h mov dl,bh int 21h inc bl inc bh loop lbl1 mov ax,4c00h int 21h main endp end main ============================================= ;; This program shows number on screen but single digit number ;; This program is not for multiple digit numbers .model small .stack 100h .data arr1 dw 2h,3h,4h,5h,9h .code main proc mov ax,@data mov ds,ax mov cx,5 mov si,0 zcopy: mov bx,offset arr1 mov dh,0 mov dl,[bx+si] add dl,30h mov ah,02 int 21h inc si inc si loop zcopy mov ax,4c00h int 21h main endp end main ============================================= title program to show decimal no. on screen .model small .stack 100h .code main proc mov cx,635 mov ax,cx mov bx,10 mov dx,0 mov cx,0 loop1: div bx push dx mov dx,0 inc cx cmp ax,0 jnz loop1 loop2: pop dx add dx,30h mov ah,2 int 21h loop loop2 mov ax,4c00h int 21h main endp end main =============================================
Transcript
Page 1: AssemblyProgsCS2012 (17th April 2012)

- 1 -.model small.stack 100h.codefirst proc

mov dl,65mov ah,02int 21hmov dl,'b'int 21hmov ax,4c00hint 21h

first endpend first

=============================================

.model small

.stack 100h

.codemain proc

mov cx,26mov dl, 65mov ah,2

abc:int 21hinc dlloop abc

mov ax,4c00hint 21hmain endpend main

=============================================

.model small

.stack 100h

.dataxyz db "KUDCS",0dh,0ah,"$"

.codemain proc

mov ax, @datamov ds, axmov ah, 9mov dx, offset xyzint 21hmov ax, 4c00hint 21h

main endpend main

=============================================

;; This program displays the following sequence:;; AaBbCcDdEe........Zz;;.model small.stack 100h.codemain proc mov cx,26 ; or mov cx,1ah mov bl,41h ; Code for 'A' mov bh,61h ; Code for 'a' mov ah,2lbl1: mov dl,bl int 21h mov dl,bh int 21h inc bl inc bh loop lbl1 mov ax,4c00h int 21hmain endpend main

=============================================

;; This program shows number on screen but single digit number;; This program is not for multiple digit numbers .model small.stack 100h.data arr1 dw 2h,3h,4h,5h,9h

.code main proc mov ax,@data mov ds,ax mov cx,5 mov si,0zcopy: mov bx,offset arr1 mov dh,0 mov dl,[bx+si] add dl,30h mov ah,02 int 21h inc si inc si loop zcopy mov ax,4c00h int 21hmain endpend main

=============================================

title program to show decimal no. on screen.model small.stack 100h.codemain proc

mov cx,635mov ax,cxmov bx,10mov dx,0mov cx,0

loop1: div bxpush dxmov dx,0inc cxcmp ax,0jnz loop1

loop2: pop dxadd dx,30hmov ah,2int 21hloop loop2

mov ax,4c00hint 21h

main endpend main

=============================================

;; Display the contents of a register in binary no. format;; OR;; Display the bit patterns of the contents of a register.model small.stack 100h.codemain proc mov cx,16 ; cx contains how many bits in a register to process

mov bx,21 ; Suppose bx contains 21d or 15h or ; 00000000 00010101b mov ah,2 ; Service to display a characterlooplbl: mov dl,31h ; Move code of one in dl register shl bx,1 ; Shift left bx register, if carry jc disp ; flag is high it means the left most dec dl ; bit is one otherwise dl contains the ; ASCII code for zero which is 30hdisp: int 21h loop looplbl mov ax,4c00h int 21hmain endpend main

=============================================

Page 2: AssemblyProgsCS2012 (17th April 2012)

- 2 -Title macro and procedure.model small.stack 100h.data

msg db "KUDCS",'$'.codeshow macro string mov dx,offset string mov ah,9 int 21hendmnewline proc mov ah,2 mov dl,0ah int 21h mov dl,0dh int 21h retnewline endpmain proc mov ax,@data mov ds,ax mov cx,10abc: show msg call newline loop abc mov ax,4c00h int 21hmain endpend main

=============================================

.model small

.stack 100h

.data msg1 db 'Enter a number: $' msg2 db 0ah,0dh,'Its double is: $' wr db 0ah,0dh,'Invalid input$'.codemain proc mov ax,@data mov ds,ax mov ah,9 mov dx,offset msg1 int 21h

mov ax,0 mov bx,0

mov cx,0aha1:

mov ah,1int 21hcmp al,0dhje donecmp al,30hjl warn1cmp al,39hjg warn1sub al,30hcbwxchg ax,bxmul cxxchg ax,bxadd bx,axjmp a1

warn1: mov ah,9 mov dx,offset wr int 21h jmp exitdone: mov ah,9 mov dx,offset msg2 int 21h shl bx,1 mov ax,bx mov bx,10

mov dx,0 mov cx,0

cd: div bx push dx mov dx,0

inc cx cmp ax,0 jnz cd

wd: pop dx add dx,30h mov ah,2 int 21h loop wd

exit: mov ax,4c00h int 21hmain endp end main

=============================================

;; Use of include: just write code in a separate file and ;; write include to include it in another file

Title takes any integer and count it.model small.stack 100h.data

num1 db 0msg db "Enter any integer: ",'$'crlf db 0ah,0dh,'$'

.codeinclude numbers.hmain proc

mov ax,@datamov ds,axDispStr msgcall NumRead dispstr crlfmov dl,01h

mov dh,0 mov cx,bxlabel1:

DispNum dxdispstr crlfinc dlloop label1Exit

main endpend main

---------------------------------------------------------------------

;; Name of this file is numbers.h;; This file is used to be included in above program

DispStr macro string push dx push ax mov dx,offset string

mov ah,9int 21h

pop ax pop dxendm

Exit macromov ax,4c00hint 21h

endm

NumRead proc mov ax,0mov bx,0

a1:mov ah,1int 21hcmp al,0dhje donecmp al,30hjl warn1cmp al,39hjg warn1sub al,30hcbwxchg ax,bxmov cx,10dmul cx

Page 3: AssemblyProgsCS2012 (17th April 2012)

- 3 -xchg ax,bxadd bx,axjmp a1

warn1:mov ah,2

mov dl,0ah int 21h mov dl,0dh int 21h

Exitdone:

retNumRead endp

DispNum macro numvarpush axpush bxpush cxpush dxmov ax,numvarmov bx,10mov dx,0mov cx,0

cd:div bxpush dxmov dx,0inc cxcmp ax,0jnz cd

wd: pop dxadd dx,30hmov ah,2int 21hloop wdpop dxpop cxpop bxpop ax

endm

=============================================

;; This program totals all the odd nos. between 1 and 100;; and then display the sum.model small.stack 100h.codemain proc mov ax,0 mov bx,1 ; First odd no.lbl: add ax,bx ; Add odd no. in ax to get the sum inc bx ; Get next odd no. by adding two inc bx ; in the previous one cmp bx,100 ; repeat this process upto 100th term jl lbl

mov bx,10mov dx,0mov cx,0

cd:div bxpush dxmov dx,0inc cxcmp ax,0jnz cd

wd: pop dxadd dx,30hmov ah,2int 21hloop wd

exit: mov ax,4c00h int 21hmain endp end main

=============================================

.model small

.stack 100h

.data firstparam dw 8 secondparam dw 12 addresult dw 0.codemain proc mov ax,@data mov ds,ax lea bx,addresult push bx lea bx,secondparam push bx lea bx,firstparam push bx call c_conv lea bx,addresult push bx call dispresult mov ax,4c00h int 21hmain endpc_conv proc push bp mov bp,sp push ax push bx mov si,[bp+4] mov ax,[si] ;; mov ax,[[bp+4]] can be used but it will ;; collect data from stack segment not from ;; data segment because bp is a pointer ;; register in stack segment mov si,[bp+6] mov bx,[si] add ax,bx mov si,[bp+8] mov [si],ax pop bx pop ax pop bp ret 6c_conv endpdispresult proc push bp mov bp,sp push ax push bx push cx push dx push si mov si,[bp+4] mov ax,[si] ;; mov ax,[[bp+4]] can be used but it will ;; collect data from stack segment not from ;; data segment because bp is a pointer ;; register in stack segment mov cx,0 mov si,0ahlbl1: mov dx,0 div si push dx inc cx cmp ax,0 jg lbl1 mov ah,2lbl2: pop dx add dl,30h int 21h loop lbl2 pop si pop dx pop cx pop bx pop ax pop bp ret 2dispresult endpend main

=============================================

Page 4: AssemblyProgsCS2012 (17th April 2012)

- 4 -;; Program to display the factorial of a number stored in ax.model small.stack 100h.codemain proc mov ax,3 push ax call factorial

mov bx,10mov dx,0mov cx,0

cd:div bxpush dxmov dx,0inc cxcmp ax,0jnz cd

wd: pop dxadd dx,30hmov ah,2int 21hloop wd

exit: mov ax,4c00h int 21hmain endp

factorial proc push bp mov bp,sp mov ax,[bp+4] cmp ax,1 ja l1 mov ax,1 jmp l2l1: dec ax push ax call factorial mov bx,[bp+4] mul bxl2: pop bp ret 2factorial endpend main

=============================================

;;;; This program takes input two numbers and then multiply;; them without using the MUL instruction;;

.model small

.stack 100h

.data mssg1 db 0ah,0dh,'Enter first number : $' mssg2 db 0ah,0dh,'Enter Second number: $' mssg3 db 0ah,0dh,'Their product is : $'.codemain proc mov ax,@data mov ds,ax mov ah,9 mov dx,offset mssg1 int 21h call NumRead ; Procdure to take input a number in bx push bx mov ah,9 mov dx,offset mssg2 int 21h call NumRead ; Procdure to take input a number in bx push bx mov ah,9 mov dx,offset mssg3 int 21h pop bx pop ax mov dx,0 ; dx is used to hold the productaddloop: test bx,1 ; Test that last bit of bx is 0 or not

jz shifting add dx,ax ; Add ax in the productshifting: shl ax,1 ; Shift ax by one bit to be added in ; dx to resemble multiplication shr bx,1 ; Shift bx to collect the last bit jnz addloop ; Check that all bits are processed or not mov ax,dx ; Now display the product

mov bx,10mov dx,0mov cx,0

cd:div bxpush dxmov dx,0inc cxcmp ax,0jnz cd

wd: pop dxadd dx,30hmov ah,2int 21hloop wd

exitprog: mov ax,4c00h int 21hmain endpNumRead proc

mov ax,0mov bx,0

a1:mov ah,1int 21hcmp al,0dhje donecmp al,30hjl warn1cmp al,39hjg warn1sub al,30hcbwxchg ax,bxmov cx,10dmul cxxchg ax,bxadd bx,axjmp a1

warn1:mov ah,2

mov dl,0ah int 21h mov dl,0dh int 21hdone:

retNumRead endpend main

=============================================

.model small

.stack 100h

.data var1 dd 08ac392beh var2 dd 0fa3b9ec6h result dw 3 dup(0) dummy db 0.codemain proc mov ax,@data mov ds,ax mov si,offset var1 mov di,offset var2 mov bx,offset result mov cx,2 clc ; Clears carry flag ; CMC complements carry flaglbl1: mov ax,[si] adc ax,[di] pushf mov [bx],ax add si,2

Page 5: AssemblyProgsCS2012 (17th April 2012)

- 5 - add di,2 add bx,2 popf loop lbl1 adc word ptr [bx],0 mov cx,6 mov bx,offset dummy dec bx mov ah,2lbl2: mov dl,[bx] mov dh,dl and dl,0f0h push cx mov cl,4 shr dl,cl pop cx add dl,30h cmp dl,3ah jl disp1 add dl,7disp1: int 21h mov dl,dh and dl,0fh add dl,30h cmp dl,3ah jl disp2 add dl,7disp2: int 21h dec bx loop lbl2 mov ax,4c00h int 21hmain endpend main

=============================================

;; This program input a number and then test ;; is it prime or not

.model small

.stack 100h

.data mssg db 'Enter a number: $' prime db 0ah,0dh,'It is a prime number $' notprime db 0ah,0dh,'It is not a prime number $' crlf db 0ah,0dh,'$'.codemain proc mov ax,@data mov ds,ax mov ah,9 mov dx,offset mssg int 21h

mov ax,0mov bx,0

a1:mov ah,1int 21hcmp al,0dhje donecmp al,30hjl warn1cmp al,39hjg warn1sub al,30hcbwxchg ax,bxmov cx,10dmul cxxchg ax,bxadd bx,axjmp a1

warn1:mov ah,2

mov dl,0ah int 21h mov dl,0dh int 21hdone: mov di,1 ; 1 prime, 0 not prime

mov cx,2divlbl: ; Now continuously divide the given number mov dx,0 ; until range is reached or any remainder mov ax,bx ; becomes zero div cx cmp dx,0 je exitprog inc cx cmp cx,bx jl divlbl mov di,2exitprog: ; Now display the nature of input number mov ah,9 mov dx,offset prime cmp di,2 je dispmssg mov dx,offset notprimedispmssg: int 21h mov ax,4c00h int 21hmain endp end main

=============================================

;; This program sorts an array ;;.model small.stack 100h.data a db 5,4,9,2,6,3,8 ; Initialize array with 7 values min db 0 max db 0.codemain proc mov ax,@data ; Initialize .data as data and extra segment mov ds,ax mov es,ax mov dx,1lbl1: ; Upper loop stores the maximum value at the lea si,a ; end of array and then process the array mov di,si ; upto one preceding element inc di mov cx,7 sub cx,dxlbl2: ; Inner loop compares two consecutive nos. mov al,[si] ; upto given no. of range if first no. is cmp al,[di] ; greater than the second then exchange them jl nextval xchg al,[di] ; The value of this range is provided by the xchg al,[si] ; upper loop which stores the maximum at the nextval: ; end of array inc si inc di loop lbl2 inc dx ; Upper loop executes six times i.e. no. of cmp dx,7 ; elements minus one jl lbl1 lea si,a mov al,[si] ; First element contains the minimum value mov min,al add si,6 mov al,[si] ; Last element contains the maximum value mov max,al mov cx,7 mov si,0zcopy: mov bx,offset a mov dh,0 mov dl,[bx+si] add dl,30h mov ah,02 int 21h inc si loop zcopy mov ax,4c00h int 21hmain endpend main

=============================================

.model small

Page 6: AssemblyProgsCS2012 (17th April 2012)

- 6 -.stack 100h.data var1 db '0999' var2 db '0999' result db 4 dup(0).codemain proc mov ax,@data mov ds,ax mov cx,4 mov si,3 mov ax,0nextdigit: mov al,var1[si] add al,ah mov ah,0 add al,var2[si] aaa or al,30h mov result[si],al dec si loop nextdigit mov bx,offset result mov cx,4 mov ah,2disp: mov dl,[bx] int 21h inc bx loop disp mov ax,4c00h int 21hmain endpend main

=============================================

.model small

.stack 100h

.data var1 dw 0017h var2 dw 0ff29h result dw 0.codemain proc mov ax,@data mov ds,ax mov cx,2 mov si,0 clclbl1: mov al,byte ptr var1[si] sbb al,byte ptr var2[si] mov byte ptr result[si],al inc si loop lbl1 mov bx,result mov ch,4 mov ah,2 jnc lbl2 mov dl,'-' int 21h neg bxlbl2: mov cl,4 rol bx,cl mov al,bl and al,0fh add al,30h cmp al,3ah jl disp add al,7disp: mov dl,al int 21h dec ch jnz lbl2 mov ax,4c00h int 21hmain endpend main

=============================================;;

;; This program multiplies two BCD nos.;;.model small.stack 100h.codemain proc mov ah,1 ; Take input first no. and check is it digit or not int 21h cmp al,30h jl exitprog cmp al,39h jg exitprog sub al,30h ; Convert entered digit into no. mov bl,al int 21h ; Take input second no. and check is it digit or not cmp al,30h jl exitprog cmp al,39h jg exitprog sub al,30h ; Convert entered digit into no. mul bl ; Multiply first no. with the second aam ; ASCII adjust after multiplication mov bx,ax mov dl,bh ; Now display adjusted BCD digits one by one add dl,30h mov ah,2 int 21h mov dl,bl add dl,30h int 21hexitprog: mov ax,4c00h int 21hmain endpend main

=============================================

title Generating sound.model small.stack 100h

speaker equ 61htimer equ 42hdelay equ 0dfffh

.codemain proc in al,speaker push ax or al,00000011b out speaker,al mov al,200l2: out timer,al mov cx,delayl3: loop l3 sub al,1 jnz l2 pop ax and al,11111100b out speaker,al mov ax,4c00h int 21hmain endpend main

=============================================

title to generate sound on speaker.model small.stack 100h.codemain proc mov cx,0fffeh mov dx,8b40h in al,61h and al,11111100bsound: push cx xor al,2 out 61h,al add dx,9248h mov cl,3 ror dx,cl

Page 7: AssemblyProgsCS2012 (17th April 2012)

- 7 - mov cx,dx and cx,1ffh or cx,10wt: loop wt pop cx loop sound mov ax,4c00h int 21hmain endpend main

=============================================

.model small

.stack 100h

.dataarr1 db '$','S','C','D','U','K'arr2 db 6 dup(0)

.codemain proc

mov ax,@datamov ds,ax

mov es,axmov di,offset arr2 mov si,offset arr2

dec si mov cx,6 call revcopy mov dx,offset arr2 mov ah,9 int 21h

mov ax,4c00hint 21h

main endprevcopy proccopyloop:

mov al,byte ptr[si]mov byte ptr[di],al

dec si inc di

loop copyloopretrevcopy endpend main

=============================================

.model small

.stack 100h

.data maxkey db 19 charkey db 0 str1 db 19 dup(?) msg1 db 'Type any string: ','$' msg2 db 'You have typed: ','$' crlf db 0ah,0dh,'$'.code main proc mov ax,@data mov ds,ax

mov dx,offset msg1mov ah,09hint 21hmov dx,offset maxkey

mov ah,0ahint 21hmov dx,offset crlfmov ah,09hint 21hxor bx,bxmov bl,charkeymov str1[bx],'$'mov dx,offset msg2mov ah,09hint 21hmov dx,offset str1mov ah,09hint 21hmov ax,4c00hint 21h

main endpend main

=============================================

.model small

.stack 100h

.data str1a db 20 str1b db ? str1c db 20 dup(?) str2 db 20 dup(?) newline db 0dh,0ah,'$' msg1 db 'Type any string: ','$' msg2 db 'You have typed: ','$'.codemain proc mov ax,@data mov ds,ax mov es,ax mov dx,offset msg1 mov ah,9 int 21h mov dx,offset str1a mov ah,0ah int 21h mov ch,0 mov cl,str1b push cx mov si,offset str1c mov di,offset str2 cld rep movsb pop cx mov bx,cx mov str2+[bx],'$' mov ah,9 mov dx,offset newline int 21h

mov dx,offset msg2 int 21h mov dx,offset str2 int 21h mov ax,4c00h int 21hmain endpend main

=============================================

;; This program takes input a string and then display its length ;;;; It is not necessary that data segment always mentioned in ;; the beginning of a program. Data segment can be defined;; at the end too.

.model small

.stack 100h

.codemain proc mov ax,@data mov ds,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a ; Takes input the string mov ah,0ah int 21h mov dx,offset newline ; Proceed to next line mov ah,9 int 21h mov dx,offset mssg2 ; Display message for next character int 21h mov ah,0 ; ax contains no. of characters entered mov al,str1b mov bx,10 mov dx,0 mov cx,0cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cdwd:

Page 8: AssemblyProgsCS2012 (17th April 2012)

- 8 - pop dx add dx,30h mov ah,2 int 21h loop wd mov ax,4c00h int 21hmain endp .data mssg1 db 'Please enter a string: $' mssg2 db 'Number of characters entered in the string: $' str1a db 20 ; Data structure for the string str1b db ? str1c db 20 dup(?) newline db 0dh,0ah,'$' ; New line stringend main

=============================================

.model small

.stack 100h

.data mssg1 db 'Enter a string: $' mssg2 db 'Now enter a character to search: $' mssg3 db 'Entered character is located at location: $' mssg4 db 'Entered Character is not found$' str1a db 20 str1b db ? str1c db 20 dup(?) newline db 0dh,0ah,'$'.codemain proc mov ax,@data mov ds,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg2 int 21h mov ch,0 mov cl,str1b mov ah,1 int 21h mov ah,0 push ax mov dx,offset newline mov ah,9 int 21h mov bx,offset str1c pop ax mov dx,0lbl1: mov ah,[bx] inc dx inc bx cmp al,ah je lbl2 loop lbl1 mov dx,offset mssg4 mov ah,9 int 21h jmp exitlbl2: mov di,dx mov dx,offset mssg3 mov ah,9 int 21h mov ax,di mov cx,0 mov si,0ahlbl3: mov dx,0 div si push dx inc cx cmp ax,0 jg lbl3 mov ah,2

lbl4: pop dx add dl,30h int 21h loop lbl4exit: mov ax,4c00h int 21hmain endpend main

=============================================

.model small

.stack 100h

.data mssg1 db 'Enter a string: $' mssg2 db 'Now enter a character to search: $' mssg3 db 'Entered character is located at location: $' mssg4 db 'Entered Character is not found$' str1a db 20 str1b db ? str1c db 20 dup(?) newline db 0dh,0ah,'$'.codemain proc mov ax,@data mov ds,ax mov es,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a mov ah,0ah int 21h mov ch,0 mov cl,str1b mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg2 int 21h mov ah,1 int 21h mov dx,offset mssg4 lea si,str1c lea di,str1c cldrepne scasb jnz exit mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg3 int 21h sub di,si mov ax,di mov bx,10 mov dx,0 mov cx,0cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cdwd: pop dx add dx,30h mov ah,2 int 21h loop wd mov dx,offset newlineexit: mov ah,9 int 21h mov ax,4c00h int 21hmain endpend main

=============================================

Page 9: AssemblyProgsCS2012 (17th April 2012)

- 9 -

.model small

.stack 100h

.data var1a db 20 var1b db ? var1c db 20 dup(?) var2a db 10 var2b db ? var2c db 10 dup(?) newline db 0dh,0ah,'$' mssg1 db 'Enter a string: $' mssg2 db 'Enter another string to be searched in first one: $' isfound db 'String is found $' isnotfound db 'String is not found $'.codemain proc mov ax,@data mov ds,ax mov es,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset var1a mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg2 mov ah,9 int 21h mov dx,offset var2a mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h cld lea si,var2c mov al,[si] mov cl,var1b mov ch,0 lea di,var1clbl1: repne scasb mov dx,offset isnotfound cmp cx,0 je exit mov ax,cx mov bx,di mov cl,var2b mov ch,0 inc cx dec di mov si,di lea di,var2c repe cmpsb mov dx,offset isfound cmp cx,0 je exit mov di,bx mov cx,ax lea si,var2c mov al,[si] jmp lbl1exit: mov ah,9 int 21h mov ax,4c00h int 21hmain endpend main

=============================================

;; This program takes input two strings and then make another ;; string by concatenating them;;.model small.stack 100h.data

mssg1 db 'Enter first string: $' mssg2 db 'Enter second string: $' mssg3 db 'Both string together are: $' str1a db 20 ; Data structure for first string str1b db ? str1c db 20 dup(?) str2a db 20 ; Data structure for second string str2b db ? str2c db 20 dup(?) str3 db 40 dup(?) ; Third string newline db 0dh,0ah,'$' ; New line string.codemain proc mov ax,@data ; Make data and extra segment point mov ds,ax ; to same segment mov es,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a ; Takes input first string mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg2 int 21h mov dx,offset str2a ; Takes input the second string mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h mov ch,0 ; cx contains length of first string mov cl,str1b mov si,offset str1c ; si points to the first string and mov di,offset str3 ; di points to the resulting third string cld rep movsb ; Copy first string to the third one mov ch,0 mov cl,str2b ; Now cx contains length of the second mov si,offset str2c ; si points to the second string rep movsb ; Copy second string to the end of third ; one because di point to the end of third string mov str3+[di],'$' ; Append $ sign at the end of third string mov ah,9 ; to mark the end of string sign mov dx,offset newline int 21h mov dx,offset mssg3 int 21h mov dx,offset str3 int 21h mov ax,4c00h int 21hmain endpend main

=============================================

;; This program takes input a string and then ;; display no. of vowels appear in the string;;.model small.stack 100h.data mssg1 db 'Please enter a string: $' mssg2 db 'Number of vowels entered in the string: $' str1a db 20 ; Data structure for the string str1b db ? str1c db 20 dup(?) vowels db 'AEIOUaeiou' ; All possible vowels in a variable newline db 0dh,0ah,'$' ; New line string.codemain proc mov ax,@data ; Initialize data and extra segment mov ds,ax mov es,ax cld ; Clear Direction Flag mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a ; Takes input the string mov ah,0ah int 21h

Page 10: AssemblyProgsCS2012 (17th April 2012)

- 10 - mov dx,offset newline ; Proceed to next line mov ah,9 int 21h mov dx,offset mssg2 ; Display message for no. of vowels int 21h mov ch,0 ; cx contains no. of characters entered mov cl,str1b ; in the string which will be processed ; one by one

mov ah,0 ; ah register will be used to hold ; no. of vowels in the entered string

mov bx,0 ; bx will be used as base register to point ; to next available character in a string

mov si,offset str1c ; si points to the start of string

vowelcount: push cx ; Preserve old value of cx register which mov cx,10 ; initially holds the total no. of characters ; entered in the string and then store 10 in ; it which represent total no. of characters ; in the variable named vowels

mov di,offset vowels ; di points to the start of variable vowels mov al,[si+bx] ; and al contains the character to be searched repne scasb ; in vowels if the character is found in the jne novowel ; string pointed by di register (ie vowels) it inc ah ; means it is a vowel, so increment ah by 1novowel: pop cx ; Now extract old value of cx to represent ; remaining no. of characters to be processed

inc bx ; bx register is incremented to point to the loop vowelcount ; next character in the entered stringdispvalue: mov al,ah ; ax holds the total no. of vowels in string mov ah,0 mov bx,10 mov dx,0 mov cx,0cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cdwd: pop dx add dx,30h mov ah,2 int 21h loop wd mov ax,4c00h int 21hmain endpend main

=============================================

;; Input a string and then display it in Title case i.e. first letter of;; each word or sentence becomes capital;;.model small.stack 100h.data string1a db 70 ; Define data structure for strin string1b db ? ; it can hold upto 70 characters string1c db 70 dup(?)

newline db 0dh,0ah,'$' ; Carriage return and line feed ; with a dollar sign to proceed ; to the next line.codemain proc mov ax,@data mov ds,ax

mov dx, offset string1a ; Now take input the string mov ah,0ah int 21h

mov ch,0 ; Get the length of string

mov cl,string1b ; in cx register

mov ah,9 mov dx,offset newline ; now proceed to the next line int 21h

mov ah,2 mov bx,0 ; Starting position of string mov si,1

trns: mov dl,string1c+[bx] ; To transfer a character in dl

cmp dl,20h ; If a character is space then store jne cptl ; 1 in si and display it mov si,1 jmp dsplcptl: cmp si,1 ; If 1 is in si it means this character jne dspl ; is the starting character or it is mov si,0 ; after space so then capitalize it if cmp dl,61h ; it is in small case jl dspl cmp dl,7ah jg dspl sub dl,20hdspl: int 21h ; Display the character

inc bx ; Increment bl to specify the next ; character loop trns mov ax,4c00h int 21h

main endpend main==================================.model small extrn convert: proc .stack 100h .data msg db 'enter lower case letter:$' .code main proc mov ax,@data mov ds,ax mov ah,9 lea dx,msg int 21h mov ah,1 int 21h call convert mov ah,4ch int 21h main endp end main-------------------------------; This is the second program public convert .model small .data msg db 0dh,0ah,'in upper case' char db -20h,'$' .code convert proc near

push bx push dx add char,al mov ah,9 lea dx,msg int 21h pop dx pop bx

ret convert endpend===================extrn get_time:near.model small.stack 100h.datatime_buf db '00:00:00$' .codemain proc

mov ax,@data

Page 11: AssemblyProgsCS2012 (17th April 2012)

- 11 -mov ds,axlea bx,time_bufcall get_timelea dx,time_bufmov ah,09h ;display timeint 21hmov ah,4chint 21h

main endpend main-----------------------------------------public get_time.model small.codeget_timeproc

mov ah,2chint 21hmov al,chcall convertmov [bx],axmov al,clcall convertmov [bx+3],axmov al,dhcall convertmov [bx+6],axret

get_timeendpconvert proc

mov ah,0mov dl,10div dlor ax,3030hret

convert endpend==================================.model small.stack 100h.data doscall equ 21h var1 label word var2 db 41h var3 db 44h var4 label byte var5 dw 464Ah.codemain proc mov ax,@data mov ds,ax mov dx,var1 mov ah,2 int doscall mov dl,var4 int doscall mov dx,var5 int doscall mov dx,word ptr var4 int doscall mov dl,dh int doscall mov dx,word ptr var2 int doscall mov dl,byte ptr var5 int doscall mov dl,byte ptr var1 int doscall mov bx,offset var1 mov dl,[bx] int doscall mov dx,word ptr[bx] int doscall mov bx,offset var4 mov dx,word ptr[bx] int doscall mov bx,offset var5 mov dx,word ptr[bx] int doscall mov bx,offset var3 mov dx,word ptr[bx] int doscall mov dl,dh int doscall push var5

mov bp,sp mov dl,[bp] int doscall mov dx,word ptr[bp] int doscall mov dl,[bp+1] int doscall pop dx mov ax,4c00h int doscallmain endp==================================.model small.stack 100h.datavar1 db 0var2 db 0msg1 db '1st is 5 $'msg2 db '2nd is -5 $'msg3 db '1st is -5 $'msg4 db '2nd is 5 $'msg5 db '1st is greater $'msg6 db '2nd is greater $'.codemain proc mov ax,@data mov ds,ax mov ah,9 lea dx,msg1 int 21h lea dx,msg2 int 21h mov var1,5 mov var2,-5 call jproc lea dx,msg3 int 21h lea dx,msg4 int 21h mov var1,-5 mov var2,5 call jproc mov ax,4c00h int 21hmain endpjproc proc mov al,var1 mov cl,var2 cmp al,cl ja lablbl1: mov al,var1 mov cl,var2 cmp al,cl jb lbllbl2: mov al,var1 mov cl,var2 cmp al,cl jg lgrlbl3: mov al,var1 mov cl,var2 cmp al,cl jl lls jmp exitlab: lea dx,msg5 int 21h jmp lbl1lbl: lea dx,msg6 int 21h jmp lbl2lgr: lea dx,msg5 int 21h jmp lbl3lls: lea dx,msg6 int 21hexit: retjproc endp

Page 12: AssemblyProgsCS2012 (17th April 2012)

- 12 -end main==================================.model small.stack 100h.codedis_str macro string mov dx,offset string mov ah,9h int 21hendmcur_pos macro vpg,row,colum ;; For cursor position mov bx,vpg mov ah,2 mov dh,row mov dl,colum int 10hendmclrscr1 proc mov ax,0600h mov cx,0 mov dh,24 mov dl,79 mov bh,7 int 10h retclrscr1 endpmain proc mov ax,@data mov ds,ax call clrscr1 cur_pos 0,2,5 dis_str msg1 cur_pos 0,5,15 dis_str msg2 cur_pos 0,7,5 dis_str msg2 mov ax,4c00h int 21hmain endp.data msg1 db 'Hello',0dh,0ah,'$' msg2 db 'Thank you',0dh,0ah,'$'end main==================================.model small.stack 200.codemain proc mov ax , @data mov ds , ax mov ah , 00h mov al,03H int 10h mov ah , 09h mov al,0c4h mov bl,00001001b mov bh,00 mov cx,40 int 10h mov ah , 4ch int 21hmain endpend main==================================;draws horizontal line in high res ;in row 100 from col 301 to col 600.model small.stack 100h.codemain proc;set graphics mode

movax,6 ;select mode 6, hi resint 10h ;draw linemovah,0ch;write pixelmoval,1 ;whitemovcx,301;beginning colmovdx,100 ;row

l1: int 10hinc cx ;next colcmpcx,600;more columns?jle l1 ;yes, repeat

;read keyboardmovah,0int 16h

;set to text modemovax,3 ;select mode 3, text modeint 10h

;return to dosmovah,4ch;returnint 21h ;to dos

main endpend main

==================================.model small.stack 100h.data buffer db 4000 dup (?).codemain proc mov ax,@data mov ds,ax mov es,ax mov si,0 cld push ds mov ax,0b800h mov ds,ax mov di,offset buffer mov cx,4000rep movsb mov ah,1 int 21h mov cx,2000 mov dl,'A' mov ah,2ag1: int 21h loop ag1 mov ah,1 int 21h pop ds mov si,offset buffer mov ax,0b800h mov es,ax mov di,0 mov cx,4000rep movsb mov ax,4c00h int 21hmain endpend main==================================.model small.stack 100h.codemain proc ;set ds to active display page mov ah,0 mov al,3 int 10h mov ax,0b800h ;color active display page mov ds,ax mov cx,2000 ;80*25 = 2000 words mov di,0 ;initialize di ;fill active display pagefill_buf: mov word ptr[di],1441h ;red a on blue add di,2 ;go to next word loop fill_buf ;loop until done mov ah,4ch int 21h main endp end main==================================.model small.stack 100h.data mssg1 db 'Empty Command Tail$' mssg2 db 'Command tail is: $' buffer db 30 dup(?).codemain proc ;mov bx,es mov ax,@data mov ds,ax lea si,buffer ;mov es,bx ;mov si,dx

Page 13: AssemblyProgsCS2012 (17th April 2012)

- 13 - mov di,81h mov cx,0 mov cl,es:[di-1] cmp cx,0 je lb2 mov al,20hrepz scasb jz lb2 dec di inc cxlb1: mov al,es:[di] mov [si],al inc si inc di loop lb1 mov al,'$' mov [si],al lea dx,mssg2 mov ah,9 int 21h lea dx,buffer int 21h jmp exitlb2: lea dx,mssg1 mov ah,9 int 21h

exit: mov ax,4c00h int 21hmain endpend main==========================.model small.stack 100h.codemain proc mov ax,0 int 33h mov ax,1 int 33h mov bh,00010111bdisp: mov ah,6 mov al,0 mov ch,8 mov cl,30 mov dh,16 mov dl,50 int 10h mov bl,0 push bxpress: mov ax,3 int 33h cmp bx,2 je exit cmp bx,1 jne presschk: mov ax,5 mov bx,0 int 33h and ax,1 cmp ax,1 je chk pop bx cmp bh,00010111b je red mov bh,00010111b jmp dispred: mov bh,01000111b jmp dispexit: pop bx mov ax,4c00h int 21hmain endpend mainend


Recommended