title Lab_Tutorial_1
.dosseg
.model small
.stack 100h

.data
input   db 99 dup(0) 
msg1    db 0ah, "Enter a string (max of 99 characters) : " ,0ah,0dh, '$' 
msg2    db "Filtered result : " ,0ah,0dh, '$'
msg3    db "Number of alphabets : $"
msg4    db "Press any key to end.....$"
blank   db 0ah, 0dh,'$'

.code
main proc

        mov ax, @data
        mov ds, ax

        mov si, offset input
        mov dx, offset msg1
        mov bh, 0 ;bh is used as a counter for alphabets
        mov ah, 9
        int 21h
        mov dx, 1 ;dl is used as a counter for max characters

again : mov cl, 41h ;sets cl to store upper case 'A' in ASCII 
        mov ch, 61h ;sets ch to store lower case 'a' in ASCII
        mov ah, 1
        int 21h
        cmp al, 0dh ;compares input with ASCII 'enter'   
        je finish   ;ends input loop if matches
        cmp al, 20h ;compares input with ASCII 'space'
        je space    ;skips remaining instructions if matches

upperC :cmp al, cl  ;upper case loop
        je save
        inc cl
        cmp cl, 5ah ;compares cl with 'Z'
        jle upperC

lowerC :cmp al, ch  ;lower case loop
        je save 
        inc ch
        cmp ch, 7ah
        jle lowerC  ;compares ch with 'z'
        jmp max     ;jumps to "max" to avoid saving

save  : inc bh      
space : mov [si], al
        inc si
max   : inc dl
        cmp dl, 99
        jle again

finish :mov dx, offset blank
        mov ah, 9
        int 21h 
        int 21h              ; prints blank space twice
        mov dx, offset msg2
        int 21h

        mov bl,'$'
        mov [si], bl
        mov dx, offset input
        int 21h
        mov dx, offset blank
        int 21h
        int 21h

        mov dx, offset msg3
        int 21h
        mov ax, 0
        mov al, bh
        aam           ; forms unpacked decimal values
        add ax, 3030h ; encodes the values in ax to ASCII format
        mov bx, ax
        mov dl, bh    
        mov ah, 2
        int 21h       ; prints most significant decimal value first
        mov dl, bl
        int 21h       ; prints least significant decimal value last

        mov ah, 9
        mov dx, offset blank
        int 21h
        int 21h
        mov dx, offset msg4
        int 21h

        mov ah, 1
        int 21h

        mov ax, 4c00h
        int 21h

main EndP
end main

I don't even really know Assembly but I think you should ask a question in your post, not just post random code.

don't even really know Assembly but I think you should ask a question in your post, not just post random code.

It's especially important with assembly because the function of a program tends to be non-obvious. I doubt most of us will know what Lab_Tutorial_1 is, after all. ;)

This article has been dead for over six months. Start a new discussion instead.