| | |
why there is ascii code infront?
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2009
Posts: 14
Reputation:
Solved Threads: 0
i am writing a assembly code to count the number of words in a sentence.
below is my coding:
when i run it, there is a ascii symbol infront of the number of word.
isit something wrong with my coding?
please help.
thank you
below is my coding:
Assembly Syntax (Toggle Plain Text)
.model small .stack 200h .386 .data message1 db 10,13, 'Word counter : Enter the sentence to be calculated$' result db 10,13, 'Number of words : $' counter db 5,6 dup(0) sentence db 10,13, 'hello world and me. $' .code Start: mov ax,seg message1 mov ds,ax mov dx,offset message1 mov ah,09h int 21h mov ax,seg sentence mov ds,ax mov bx,offset sentence mov ax,0 mov cx,0 mov di,2 check1: mov al,[bx+di] cmp al,'.' je check2 cmp al,',' je check2 cmp al,' ' je count cmp al,'$' je done jmp skip check2: inc cx inc di mov al,[bx+di] cmp al,' ' je skip jmp check1 skip: inc di jmp check1 count: inc cx inc di jmp check1 done: mov ax,cx aaa add ax,3030h cmp ah,30h je singleNumber jmp doubleNumber singleNumber: mov bx,offset counter mov [bx+2],al mov al,'$' mov [bx+3],al jmp print doubleNumber: mov bx,offset counter mov [bx+2],ah mov [bx+3],al mov al,'$' mov [bx+4],al print: mov dx,offset result mov ah,09h int 21h mov dx,offset counter mov ah,09h int 21h .exit end start
isit something wrong with my coding?
please help.
thank you
0
#2 Oct 18th, 2009
You loaded your counter variable starting at counter+2 which
causes the ASCII character 5 to be printed on the screen,
that is the initializer you used for the first byte of the
array at counter:
Make these changes:
That will eliminate the club symbol (ASCI '\5') from being
printed on the console.
causes the ASCII character 5 to be printed on the screen,
that is the initializer you used for the first byte of the
array at counter:
Make these changes:
Assembly Syntax (Toggle Plain Text)
singleNumber: mov bx,offset counter mov [bx+0],al ; changed +2 to +0 mov al,'$' mov [bx+1],al ; changed +3 to +1 jmp print doubleNumber: mov bx,offset counter mov [bx+0],ah ; changed +2 to +0 mov [bx+1],al ; changed +3 to +1 mov al,'$' mov [bx+2],al ; changed +4 to +2
That will eliminate the club symbol (ASCI '\5') from being
printed on the console.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
![]() |
Similar Threads
- Help Printing Ascii Code (Assembly)
- convert ascii code to string (C#)
- how to initialize a char valueble with ascii code? (C++)
- returning number of characters with ASCII code (C)
- Code Snippet: Strings: Looking at ASCII Code (C)
Other Threads in the Assembly Forum
- Previous Thread: Could anyone please tell me?
- Next Thread: Overflow with asr opcode
| Thread Tools | Search this Thread |
Tag cloud for Assembly





