Task: to find the maximum word in the line and display it. Here is my code, but it gives an error in this line.

MOV DI,buff+2 

Here is the code itself:

 .model tiny .stack 256 .data sin db 'Enter string: $' buff label byte ; буфер для приема строки с клавиатуры (по ф-и 0ah) poss DW 0 len DW 0 .386 Start: mov ax, @data mov ds, ax lea dx, sin mov ah, 9 int 21h ; приглашение ввести строку lea dx, buff mov ah, 0ah int 21h ; ввод стркои в буфер PUSH 20h 0 POP CX AX ; AL = 20H (пробел), СХ = 0 MOV CL,[buff+1] ; СХ = длина строки MOV DI,buff+2 ; ..её адрес compare: PUSH CX ; сохраняем текущую позицию символа REPNE SCASB ; ищем пробел в строке POP BX ; пробел нашёлся! берём нач.позицию символа SUB BX,CX ; и расчитываем разницу CMP BX,[len] ; тест с переменной JLE next ; переход, если длина слова меньше/равно MOV [len],BX ; иначе - сохраняем в переменных MOV [poss],DI ; ..адрес конца слова, и его длинну next: DB 8,0C9h ; последний символ в строке? (OR CL,CL) JNZ compare ; нет - продолжаем искать пробелы MOV CX,[len] ; длинна самого/длинного слова MOV SI,[poss] SUB SI,CX ; его позиция в оригинальной строке print: LODSB ; выводим это слово на экран! INT 29h LOOP print XOR AX,AX INT 16h INT 20h END Start 
  • Try replacing with MOV DI, offset buff+2 . Or on lea di, [buff+2] . - insolor
  • @insolor thanks, helped) - Digital Resistance

1 answer 1

For masm and tasm, you need to explicitly specify what you want to write to the register address (offset), for this the keyword offset :

 MOV DI, offset buff+2 

If you do not specify it, the translator may consider that you want to write the contents of the address into a variable. Because the size of the buffer elements is specified as a byte, you get an error from the question header.

Another option is to use the lea command (load effective address - load the "effective" address):

 lea di, [buff+2] 

Although square brackets are indicated in the right-hand operand, the address of the right-hand operand will be written to the left-hand operand.