i'm new to asm. now learning the project that require me to correct the code of letters counting. so the problem is everytime the counted total from the program gives the actual number of characters entered with 2 more digits. that means, if key-in: will, it should shows 4 letters, but instead of it, it shows 6 digits. may i know the exact root of this problem. would it be the counting of another 2 hidden characters of ASCII of the "enter" function?
the code as follow:
.Model small
.386
.Stack 300h
.Data
Prompt db 13, 10, 'Total entered characters ','$'
filehold_1 dw ?
by_r dw ?
by_r1 dw ?
char db 400 dup(?)
chinput db 400 dup(?)
counter dw ?
counter1 dw ?
Prompt1 db 13, 10, 'Enter your words :', '$'
.Code
Start:
;code to input from keyboard
push ax ;preserve used
push dx ; register
mov ah, 9 ;request display
lea dx, Prompt1 ;of user prompt
int 21h
pop dx ;restore
pop ax ;register
;code to read from keyboard and store in string
mov ax, seg chinput
mov ds, ax
mov dx, offset chinput
mov ah, 3fh
mov cx, 400
mov bx, filehold_1
int 21h
mov by_r1, ax
jc RError
;code to count the number of characters from keyboard
mov cx, by_r1 ;set counter to number of bytes
mov ax, seg chinput ; initialize ds to string segment
mov ds, ax
mov bx, 0 ;set bx to zero
mov di, 0 ;set di to zero
char_begin1:
cmp chinput [di],' ' ;if character = space
je char_nextchar ;not read next character
inc bx ; increase number of char by 1
char_nextchar:
inc di
loop char_begin1 ;go back to char_begin1 function
mov counter1, bx
;code to print total number of characters from keyboard
mov ax, seg Prompt1
mov ds, ax
mov ah, 9
mov dx, offset Prompt1
int 21h ;print the result
mov ax, counter1
push ax ;save bx, cx and dx
push dx
push cx
push bx
xor cx, cx
mov bx, 10 ;load 10
papx1:
xor dx, dx
div bx
push dx
inc cx
or ax, ax ;test
jnz papx1 ;if not zero
papx2:
pop dx
mov ah, 6
add dl, 30h
int 21h
loop papx2 ;repeat
pop bx ; restore bx, cx, and dx
pop cx
pop dx
pop ax
BOpen:
RError:
CError:
.exit
end start
thanx your help!
wcks48,
The Enter key is actually a 2 key sequence because two things happen, a linefeed and a carriage return. The values, in decimal, are 13 and 10.
Paul
so that's the only way to fix the problem right?
i would avoid the carriage return and line feed. thanx.