.model small
.stack 100h
.data
msg1 db "Enter your symbol line: ","$"
msg2 db "Numbers found at: ","$"
eilute db 255,0,255 dup (0) ;symbol line
nauja db 13,10,'$' ;new line
.code
start:
mov ax, @data
mov ds, ax
mov ah, 09h ;1 message
lea dx, msg1
int 21h
mov ah, 0Ah ;reads line
lea dx, eilute ;saves buff adress
mov si, dx
add si, 2
int 21h
mov ah, 09h ;new line
lea dx, nauja
int 21h
mov ah, 09h ;prints out 2nd message
lea dx, msg2
int 21h
mov bx, -1 ; starting place -1
loopas:
lodsb ;gets the symbol
inc bx ;++
cmp al, 13 ;checks if it's the end
jz exit
cmp al, 48 ;checks if less than 0
jb loopas
cmp al, 57 ;checks if more than 9
ja loopas
mov ax, bx ;if the string ends
mov cx, 10
call printina
mov ah, 2 ;prints out new line
mov dl, 32
int 21h
jmp loopas
printina proc near ;prints the place
skloop:
xor dx, dx
div cx
push dx
cmp ax, 0
je undo
call skloop
undo:
pop dx
pdig:
add dl, 30h
cmp dl, 39h
jle pch
add al, 7
pch:
mov ah, 2
int 21h
ret ; gets back to loop
printina endp
exit:
mov ax, 4c00h ;exit
int 21h
end start
那麼如何獲得字符串「eilute」長度,然後使用cx來保存長度,而不是使用循環作爲每次添加+1直到到達結尾,它使用字符串的長度和函數Loop ?如何查找字符串的長度,然後使用該長度來運行使用cx的循環函數?
感謝您的回答。所以現在在這之後,我有cx中的字符串長度?我如何使用它來編寫循環?基本上,我如何將「loopas:」更改爲使用該字符串長度的東西,並執行相同的操作? – Johnie78
@ Johnie78,用CX編輯我的答案。 –
非常感謝!此外,評論是非常有幫助的:) – Johnie78