0

my program is to count all vowels in user input characters my codes is long because of part when comparing the user input if vowel or not. is there a way to shorten my codes? i am new to assembly language so i use basic mnemonic

title sample.prog
cstack segment para stack 'stack'
dw 200h
cstack ends

cdata segment para 'data'
msg1 db 'ENTER 9 CHARACTER: $',10,13
msg2 db 10,13,'NUMBER OF VOWELS: $'
cdata ends

ccode segment para 'code'
assume cs:ccode,ds:cdata,ss:cstack
main:
 mov ax,cdata
 mov ds,ax

 mov ah,09h
 lea dx,msg1
 int 21h

 mov cl,0
 mov bl,30h

input:
 mov ah,01
 int 21h
 inc cl

 cmp al,61h
 je incre
 cmp al,65h
 je incre
 cmp al,69h
 je incre
 cmp al,6fh
 je incre
 cmp al,75h
 je incre
 cmp al,'A'
 je incre
 cmp al,'E'
 je incre
 cmp al,'I'
 je incre
 cmp al,'O'
 je incre
 cmp al,'U'
 je incre

 cmp cl,9
 je ed
 jmp input

incre:
 inc bl

 cmp cl,9
 je ed
 jmp input 

ed:
  mov ah, 09h
  lea dx,msg2
  int 21h


  mov ah,02h
  mov dl,bl
  int 21h

  mov ah, 4ch
  int 21h

ccode ends
end main
Jester
  • 56,577
  • 4
  • 81
  • 125
Volkswagen
  • 155
  • 2
  • 4
  • 11
  • 4
    I'm voting to close this question as off-topic because it should be on [codereview](http://codereview.stackexchange.com). – Jester Jan 29 '15 at 16:29
  • If you can use 386 features (32-bit registers), [Where can the code be more efficient for checking if an input character is a vowel?](https://stackoverflow.com/q/36121970) shows how to use a very compact bitmap to check for a vowel, after an efficient check for being alphabetic (which collapses upper and lower case to one). – Peter Cordes Jul 26 '22 at 02:55

1 Answers1

1

Shave off some code by first capitalizing

and al,1101_1111b
cmp al,'A'
jb skip
cmp al,'Z'
ja skip
cmp al,'A'
je incre
cmp al,'E'
je incre
cmp al,'I'
je incre
cmp al,'O'
je incre
cmp al,'U'
je incre
skip:

Or use a list (in de data section)

vowels db 'AEIOUaeiou'

...

mov cx,10
mov si,vowels
again:
cmp al,[si]
je incre
inc si
loop again
Sep Roland
  • 33,889
  • 7
  • 43
  • 76