So I wrote a program where it shows a position of numbers in a line for example if I write abc123 it prints 4 5 6. My problem is the program I have written doesn't read more than 10 characters and doesn't show the position after 9. I'm very new to assembly so I'm not exactly sure what even the problem is.
.model small
.stack 100h
.data
buf db 255
howMany db ?
char db 255 dup (?)
msgIvesti db "Iveskite eilute:", 10, 13, "$"
msgRezult db "Rezultatai:",10,13,"$"
count db 0
.code
Start:
mov ax, @data
mov ds, ax
mov ah, 9
mov dx, OFFSET msgIvesti
int 21h
mov ah, 0Ah
mov dx,OFFSET buf
int 21h
mov ah, 9
mov dx,OFFSET msgRezult
int 21h
mov cl, howMany
mov ch, 0 ;
mov si, OFFSET char
cycle:
lodsb
inc count
cmp al,'0'
jb notDigit
cmp al, '9'
ja notDigit
mov dl,count
add dl, '0'
mov ah, 02h
int 21h
notDigit:
;inc bx
dec cl
cmp cl, 0
jne cycle
endi:
mov ax, 4C00h
int 21h
END Start
I need this program to be able to read more characters and print numbers positions further than it does now.
Your program will read many more than 10 characters. The trouble is in the way that you display the count. Merely adding "0" can only work for numbers smaller than 10, so occupying but a single decimal digit.
If more is needed then you'll have to convert the number into a string of characters and print that text. See Displaying numbers with DOS
mov dl,count add dl, '0' mov ah, 02h int 21h
is to be replaced by (copied from the linked Q/A and modified to operate in your loop):
mov al, count
mov ah, 0
mov bx, 10 ;CONST
xor bp, bp ;Reset counter
.a: xor dx, dx ;Setup for division DX:AX / BX
div bx ; -> AX is Quotient, Remainder DX=[0,9]
push dx ;(1) Save remainder for now
inc bp ;One more digit
test ax, ax ;Is quotient zero?
jnz .a ;No, use as next dividend
.b: pop dx ;(1)
add dl, "0" ;Turn into character [0,9] -> ["0","9"]
mov ah, 02h ;DOS.DisplayCharacter
int 21h ; -> AL
dec bp
jnz .b