•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 423,386 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,727 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 698 | Replies: 0
![]() |
•
•
Join Date: Aug 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
assembly Syntax (Toggle Plain Text)
TITLE charwordcount DOSSEG .MODEL SMALL .STACK 100h .DATA msg1 db "Enter a sentence please: $" msg2 db " Do you want to try again (Y/N)? $" msg3 db "Character count = $" msg4 db "Word count = $" sentence db 84 dup("$") try db 5 dup("$") crlf db 13, 10, "$" error1 db "*** Error: Null Input ***$" error2 db "*** Error: No period or invalid terminating character at the end of the sentence ***$" error3 db "*** Error: Two or more spaces between words ***$" count db 00 .CODE BEGIN: mov ax, @data mov ds, ax mov es, ax ; clear screen mov al, 03h mov ah, 00h int 10h ; print msg1 ulit: lea dx, msg1 mov ah, 09h int 21h ; get sentence mov byte ptr sentence, 81 lea dx, sentence mov ah, 0Ah int 21h ; next line lea dx, crlf mov ah, 09h int 21h ; check for null value and output error msg mov si, 0002 mov al, sentence[si] cmp al, 0dh je err1 cmp al, ' ' je err1 ; compare for two or more spaces ;mov si, 0002 mov si, 0000 c10: inc si mov al, sentence[si] cmp al, '$' je next cmp al, ' ' je L11 jmp c10 L11: inc si mov al, sentence[si] cmp al, ' ' je err3 dec si jmp c10 ; compare for terminaton ;mov si, 0001 next: mov si, 0000 L1: inc si mov al, sentence[si] cmp al, '.' je cchar cmp al, '$' je err2 jmp L1 ; error message for null input err1: lea dx, error1 mov ah, 09h int 21h jmp tanong err3: lea dx, error3 mov ah, 09h int 21h jmp tanong ; print character message cchar: lea dx, msg3 mov ah, 09h int 21h ; count for characters mov si, 0001 mov al, sentence[si] sub al, 01 aam add ax, 3030h push ax ; print number of char mov dl, ah mov ah, 02h int 21h pop ax mov dl, al mov ah, 02h int 21h ; next line lea dx, crlf mov ah, 09h int 21h ; print msg4 lea dx, msg4 mov ah, 09h int 21h ; count number of words words: mov byte ptr count, 00 ;mov si, 0002 mov si, 0000 c1: inc si mov al, sentence[si] cmp al, '$' je pcount cmp al, ' ' je L10 jmp c1 ; start counting words L10: inc byte ptr count jmp c1 ; print number of words pcount: mov al, count add al, 01 aam add ax, 3030h push ax ; print number of words mov dl, ah mov ah, 02h int 21h pop ax mov dl, al mov ah, 02h int 21h jmp tanong ; error message for invalid terminator err2: lea dx, error2 mov ah, 09h int 21h jmp tanong ; next line tanong: lea dx, crlf mov ah, 09h int 21h ; try again lea dx, msg2 mov ah, 09h int 21h ; get try answer mov byte ptr try, 2 lea dx, try mov ah, 0Ah int 21h ; next line lea dx, crlf mov ah, 09h int 21h ; check for answer mov si, 0002 mov al, try[si] cmp al, 'Y' Jne tapos jmp ulit ; next line lea dx, crlf mov ah, 09h int 21h tapos: mov ah, 4ch int 21h end BEGIN
;;; Hi guys, I'm really new in Assembly programming.. This code is running pretty good.. but i have a problem when it loops.. i think the counter is not resetting.. it gave me wrong values for the word count.. please help.. thanks
Last edited by stymiee : Aug 10th, 2007 at 1:38 pm. Reason: added code tags
![]() |
•
•
•
•
•
•
•
•
DaniWeb Assembly Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- A small problem in the output (C++)
- Array Problem (C++)
- Script needed to check OID values (Shell Scripting)
- Problem in getting values of a text area by row and column wise (ASP)
- a problem wilth C program (C)
- transfer input.txt to output.txt help prz (C++)
- file extraction and insertion (C++)
Other Threads in the Assembly Forum
- Previous Thread: c++ to tasm
- Next Thread: x86 Assembly in Mac OS X


Linear Mode