assemblyprogscs2

Upload: adil-ahmad

Post on 05-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 AssemblyProgsCS2

    1/4

    - 1 -.model small.stack 100h.data

    var1 db '0999'var2 db '0999'result db 4 dup(0)

    .codemain proc

    mov ax,@datamov ds,axmov cx,4mov si,3

    mov ax,0nextdigit:

    mov al,var1[si]add al,ahmov ah,0add al,var2[si]aaaor al,30hmov result[si],aldec siloop nextdigitmov bx,offset resultmov cx,4mov ah,2

    disp:mov dl,[bx]

    int 21hinc bxloop dispmov ax,4c00hint 21h

    main endpend main

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

    .model small

    .stack 100h

    .datavar1 dw 0017hvar2 dw 0ff29hresult dw 0

    .codemain procmov ax,@datamov ds,axmov cx,2mov si,0clc

    lbl1:mov al,byte ptr var1[si]sbb al,byte ptr var2[si]mov byte ptr result[si],alinc siloop lbl1mov bx,resultmov ch,4mov ah,2jnc lbl2mov dl,'-'int 21hneg bx

    lbl2:mov cl,4rol bx,clmov al,bland al,0fhadd al,30hcmp al,3ahjl dispadd al,7

    disp:mov dl,alint 21hdec ch

    jnz lbl2mov ax,4c00hint 21h

    main 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 notint 21hcmp al,30hjl exitprogcmp al,39h

    jg exitprogsub al,30h ; Convert entered digit into no.mov bl,alint 21h ; Take input second no. and check is it digit or notcmp al,30hjl exitprogcmp al,39hjg exitprogsub al,30h ; Convert entered digit into no.mul bl ; Multiply first no. with the secondaam ; ASCII adjust after multiplicationmov bx,axmov dl,bh ; Now display adjusted BCD digits one by oneadd dl,30hmov ah,2int 21h

    mov dl,bladd dl,30hint 21h

    exitprog:mov ax,4c00hint 21h

    main endpend main

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

    title Generating sound.model small.stack 100h

    speaker equ 61htimer equ 42h

    delay equ 0dfffh.codemain proc

    in al,speakerpush axor al,00000011bout speaker,almov al,200

    l2:out timer,almov cx,delay

    l3:loop l3sub al,1jnz l2pop axand al,11111100bout speaker,almov ax,4c00hint 21h

    main endpend main

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

    title to generate sound on speaker.model small.stack 100h.codemain proc

    mov cx,0fffehmov dx,8b40hin al,61h

    and al,11111100bsound:

    push cxxor al,2out 61h,aladd dx,9248hmov cl,3

  • 7/31/2019 AssemblyProgsCS2

    2/4

    - 2 -ror dx,clmov cx,dxand cx,1ffhor cx,10

    wt:loop wtpop cxloop soundmov ax,4c00hint 21h

    main endpend main

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

    .model small

    .stack 100h

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

    .codemain proc

    mov ax,@datamov ds,axmov es,axmov di,offset arr2mov si,offset arr2dec si

    mov cx,6call revcopymov dx,offset arr2mov ah,9int 21hmov ax,4c00hint 21h

    main endprevcopy proccopyloop:

    mov al,byte ptr[si]mov byte ptr[di],aldec siinc diloop copyloop

    ret

    revcopy endpend main

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

    .model small

    .stack 100h

    .datamaxkey db 19charkey db 0str1 db 19 dup(?)msg1 db 'Type any string: ','$'msg2 db 'You have typed: ','$'crlf db 0ah,0dh,'$'

    .codemain proc

    mov ax,@datamov ds,axmov dx,offset msg1mov ah,09hint 21hmov dx,offset maxkeymov ah,0ahint 21hmov dx,offset crlfmov ah,09hint 21hxor bx,bxmov bl,charkeymov str1[bx],'$'mov dx,offset msg2mov ah,09hint 21h

    mov dx,offset str1mov ah,09hint 21hmov ax,4c00hint 21h

    main endpend main

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

    .model small

    .stack 100h

    .datastr1a db 20str1b 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,@datamov ds,axmov es,axmov dx,offset msg1mov ah,9int 21hmov dx,offset str1amov ah,0ahint 21hmov ch,0mov cl,str1bpush cxmov si,offset str1c

    mov di,offset str2cldrep movsbpop cxmov bx,cxmov str2+[bx],'$'mov ah,9mov dx,offset newlineint 21h

    mov dx,offset msg2int 21hmov dx,offset str2int 21hmov ax,4c00hint 21h

    main endpend main

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

    .model small

    .stack 100h

    .datamssg1 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 20str1b db ?str1c db 20 dup(?)newline db 0dh,0ah,'$'

    .codemain proc

    mov ax,@datamov ds,axmov dx,offset mssg1mov ah,9int 21hmov dx,offset str1amov ah,0ahint 21hmov dx,offset newlinemov ah,9int 21hmov dx,offset mssg2int 21hmov ch,0mov cl,str1b

    mov ah,1int 21hmov ah,0push axmov dx,offset newlinemov ah,9int 21h

  • 7/31/2019 AssemblyProgsCS2

    3/4

    - 3 -mov bx,offset str1cpop dxmov dh,0

    lbl1:mov ah,[bx]inc dhinc bxcmp dl,ahjne lbl2mov cx,0mov si,0ahmov ah,0

    mov al,dhpush axmov dx,offset mssg3mov ah,9int 21hpop ax

    lbl3:mov dx,0div sipush dxinc cxcmp ax,0jg lbl3mov ah,2

    lbl4:pop dx

    add dl,30hint 21hloop lbl4jmp exit

    lbl2:loop lbl1mov dx,offset mssg4mov ah,9int 21h

    exit:mov ax,4c00hint 21h

    main 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 stringstr1b db ?str1c db 20 dup(?)str2a db 20 ; Data structure for second stringstr2b db ?str2c db 20 dup(?)str3 db 40 dup(?) ; Third stringnewline db 0dh,0ah,'$' ; New line string

    .codemain proc

    mov ax,@data ; Make data and extra segment pointmov ds,ax ; to same segmentmov es,axmov dx,offset mssg1mov ah,9int 21hmov dx,offset str1a ; Takes input first stringmov ah,0ahint 21hmov dx,offset newlinemov ah,9int 21hmov dx,offset mssg2

    int 21hmov dx,offset str2a ; Takes input the second stringmov ah,0ahint 21hmov dx,offset newlinemov ah,9int 21h

    mov ch,0 ; cx contains length of first stringmov cl,str1bmov si,offset str1c ; si points to the first string andmov di,offset str3 ; di points to the resulting third stringcldrep movsb ; Copy first string to the third onemov ch,0mov cl,str2b ; Now cx contains length of the secondmov si,offset str2c ; si points to the second stringrep movsb ; Copy second string to the end of third

    ; one because di point to the end of third stringmov str3+[di], '$' ; Append $ sign at the end of third string

    mov ah,9 ; to mark the end of string signmov dx,offset newlineint 21hmov dx,offset mssg3int 21hmov dx,offset str3int 21hmov ax,4c00hint 21h

    main endpend main

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

    ;; This program takes input a string and then display its length;;

    .model small.stack 100h

    .datamssg1 db 'Please enter a string: $'mssg2 db 'Number of characters entered in the string: $'str1a db 20 ; Data structure for the stringstr1b db ?str1c db 20 dup(?)newline db 0dh,0ah,'$' ; New line string

    .codemain proc

    mov ax,@datamov ds,axmov dx,offset mssg1mov ah,9int 21h

    mov dx,offset str1a ; Takes input the stringmov ah,0ahint 21hmov dx,offset newline ; Proceed to next linemov ah,9int 21hmov dx,offset mssg2 ; Display message for next characterint 21hmov ah,0 ; ax contains no. of characters enteredmov al,str1bmov bx,10mov dx,0mov cx,0

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

    wd:pop dxadd dx,30hmov ah,2int 21hloop wdmov ax,4c00hint 21h

    main 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: $'

  • 7/31/2019 AssemblyProgsCS2

    4/4

    - 4 -mssg2 db 'Number of vowels entered in the string: $'str1a db 20 ; Data structure for the stringstr1b db ?str1c db 20 dup(?)vowels db 'AEIOUaeiou' ; All possible vowels in a variablenewline db 0dh,0ah,'$' ; New line string

    .codemain proc

    mov ax,@data ; Initialize data and extra segmentmov ds,axmov es,axcld ; Clear Direction Flag

    mov dx,offset mssg1mov ah,9int 21hmov dx,offset str1a ; Takes input the stringmov ah,0ahint 21hmov dx,offset newline ; Proceed to next linemov ah,9int 21hmov dx,offset mssg2 ; Display message for no. of vowelsint 21hmov ch,0 ; cx contains no. of characters enteredmov 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 whichmov 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 vowelsmov al,[si+bx] ; and al contains the character to be searched

    repne scasb ; in vowels if the character is found in thejne novowel ; string pointed by di register (ie vowels) itinc ah ; means it is a vowel, so increment ah by 1

    novowel: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 theloop vowelcount ; next character in the entered string

    dispvalue:mov al,ah ; ax holds the total no. of vowels in stringmov ah,0mov bx,10mov dx,0mov cx,0

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

    wd:pop dxadd dx,30hmov ah,2int 21hloop wdmov ax,4c00hint 21h

    main 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

    .datastring1a db 70 ; Define data structure for strinstring1b db ? ; it can hold upto 70 charactersstring1c 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,@datamov ds,ax

    mov dx, offset string1a ; Now take input the stringmov ah,0ahint 21h

    mov ch,0 ; Get the length of stringmov cl,string1b ; in cx register

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

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

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

    cmp dl,20h ; If a character is space then storejne cptl ; 1 in si and display itmov si,1jmp dspl

    cptl: cmp si,1 ; If 1 is in si it means this characterjne dspl ; is the starting character or it ismov si,0 ; after space so then capitalize it ifcmp dl,61h ; it is in small casejl dsplcmp dl,7ahjg dsplsub dl,20h

    dspl: int 21h ; Display the character

    inc bx ; Increment bl to specify the next; characterloop trnsmov ax,4c00hint 21h

    main endpend main