Search code examples
assemblytasm

Assembly Programming Illegal indexing mode


I want to know why this program gives me an error.

Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International

Assembling file: sample.asm
Error sample.asm(16) Illegal indexing mode
Error messages: 1
Warning message: none
Passes: 1
Remaining memory: 470k

 title test.program
cstack segment para stack 'stack'
dw 200h
cstack ends

cdata segment para 'data'
msg1 db 'Sample progr! $'
cdata ends

ccode segment para 'code'
 assume cs: ccode, ds: cdata ,ss: cstack
main:
 mov cl,00
stri:
 mov ah,02h
 mov dl,[msg1 +cl] ;< this line give me an error of illegal indexing mode 
 int 21h

 add cl,02
 cmp dl,12
 jbe stri

 mov ah,4ch
 int 21h

ccode ends
end main

Solution

  • If you want to use a register to loop through the characters of msg1 then use an indexing register like SI, DI, or BX.

    When you add cl,2 you will not correctly display the string!

    Comparing with 12 will not include the exclamation mark character.

    main:
    mov si,00
    stri:
    mov ah,02h
    mov dl,[msg1 + si] ;< this line give me an error of illegal indexing mode 
    int 21h
    add si,1
    cmp si,13
    jbe stri