There is a code on Tasm. It writes that there are 3 words in a line. Tell me how to display the length of a line and why counted only 3 words?

data segment para public "data" mas db 'podschitat kolichestvo slov v zadannom tekste''$' text1 db 'Slov v stroke: $ ' text2 db 'Dlina stroki: $' data ends code segment para public "code" start: assume ds:data,cs:code mov ax,data mov ds,ax lea di,mas mov si,0 l1 : cmp byte ptr [di],0 je l2 inc di inc si jmp l1 l2 : lea di,mas mov cx,si mov al,' ' mov bx,0 cld m1: repne scasb jcxz m2 inc bx jmp m1 m2: inc bx mov ah,9 mov dx,offset text1 int 21h add bx,30h mov ax,0200h mov dx,bx int 21h mov ax,4c00h int 21h code ends end start 
  • 1) where is es initialization? 2) Why are you looking for a byte with a value of 0? (it is not in the line) - PinkTux
  • @PinkTux 1) why initialize it? 2) the remark is logical, but then I don’t understand how to calculate the length, what would the words be afterwards? - user254109
  • Not "her", but the es register. But you don’t have tiny (if I understood correctly), therefore, the es:di pair doesn’t point at all to where you want :) And to calculate the length (in this case it doesn’t make sense, it’s already known at the assembly stage) criterion. For example, look for the $ character instead of the zero byte. - PinkTux

1 answer 1

For example:

 P8086 MODEL TINY DATASEG test_string db '11 222 3333 ', 0 CODESEG STARTUPCODE mov di, offset test_string push di mov cx, -1 xor ax, ax cld repne scasb not cx dec cx ; здесь в CX получаем длину строки pop si xor bx, bx skip_spaces: lodsb or al, al jz finish cmp al, ' ' jle skip_spaces inc bx skip_word: or al, al jz finish cmp al, ' ' jle skip_spaces lodsb jmp short skip_word finish: ; а здесь в BX - количество строк ret END