source code
TITLE Count Character Template (charCount.asm)
INCLUDE Irvine32.inc
.data
buffer BYTE 100 DUP(0)
message BYTE "Please enter a string:",0
sortBYTE "Sort :",0
.code
main PROC
call countLetter
exit
main ENDP
;----------------------------------------------------------------------------------------------------------
countLetter PROC
; bubble sort with ASCII
;----------------------------------------------------------------------------------------------------------
mov edx,OFFSET message
call writeString
mov edx,OFFSET buffer
mov ecx,SIZEOF buffer
call ReadString
mov ecx,SIZEOF buffer
dec ecx
L1:
push ecx
mov edx,OFFSET buffer
mov ecx,SIZEOF buffer
dec ecx
L2:
mov al,[edx]
mov bl,[edx+1]
.IF al==0h || bl==0h
JMP J1
.ENDIF
.IF al>bl && bl!=20h;shift sapce==20h
mov [edx],bl
mov [edx+1],al
.ELSEIF al<=bl && al==20h;shift space==20h
mov [edx],bl
mov [edx+1],al
.ENDIF
add edx,1
loop L2
J1:
pop ecx
loop L1
mov edx,OFFSET buffer
mov esi,OFFSET buffer
add esi,1
mov al,[edx]
add al,32
mov ecx,-1
F1:
mov bl,[esi]
.IF al>bl
mov [esi-1],bl
add esi,1
.ELSEIF al<=bl
sub al,32
mov [esi-1],al
JMP E1
.ENDIF
JMP F1
E1:
mov edx,OFFSET sort
call writeString
mov edx,OFFSET buffer
call writeString
call crlf
call countLetter
ret
countLetter ENDP
END main