DCPU16 24
[COAL] Printing total number of characters Guest on 21st January 2021 07:57:41 PM
  1. ;Write a program that take input as string and counts
  2. ;number of characters and display. When user press
  3. ;'ENTER' key it must show the result not including the
  4. ;'ENTER' key .
  5. print macro p1
  6.     mov dx,offset p1
  7.     mov ah,9
  8.     int 21h
  9. endm
  10. .model small
  11. .stack 100h
  12. .data
  13. str1 db 10,13,'Please enter your statement:$'
  14. str2 db 10,13,'Total number of character=','$'
  15. str3 db 10,13,'press Y to run again or Press ESC to terminate program$'
  16. .code
  17. main proc
  18.     mov ax,@data
  19.     mov ds,ax
  20. start:
  21.     print str1
  22.     mov bl,0
  23. L1:  
  24.     mov ah,1
  25.     int 21h
  26.     cmp al,13
  27.     je end1
  28.     inc bl
  29.     cmp al,32
  30.     je decr
  31.  
  32.     jmp L1
  33. decr:
  34.     dec bl
  35.     jmp L1
  36. end1:
  37.     print str2
  38.     mov al,bl
  39.     mov ah,0 ; ax=bl
  40.     aam      ;ax=Dh->13d-> ah=1 ; al=3
  41.     mov bl,al
  42.     mov dl,ah
  43.     add dl,48
  44.     mov ah,2
  45.     int 21h ; al=dl
  46.     mov dl,bl
  47.     add dl,48
  48.     mov ah,2
  49.     int 21h
  50. L2:
  51.     print str3
  52.     mov ah,1
  53.     int 21h
  54.     cmp al,'Y'
  55.     je start
  56.     cmp al,'y'
  57.     je start
  58.     cmp al,27
  59.     je end2
  60.     jmp L2
  61. end2:
  62.     mov ah,4ch
  63.     int 21h
  64.     main endp            
  65. end main

Coding Base is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.