"NTVDM CPU has encountered an illegal instruction" caused by RET instruction

1.3k Views Asked by At

Well, I've got a big problem here. This code is supposed to work; I did not write it, but my teacher give it to me. The code is a bit longer, as it a concat operation betwen two strings, and it has two more procs, but this is the only one which is not called from another proc, so, I've been debuggin this separately.

.MODEL LARGE
.386
.STACK 200h


.DATA
_MAX_CARACTERES_ EQU 30
__AUX_CADENA_ DB _MAX_CARACTERES_ dup(?), '$'  
cad1 DB "primer cadena", '$', 37 dup(?)
cad2 DB "segunda cadena", '$', 36 dup(?)
cad3 DB _MAX_CARACTERES_ dup(?), '$'


.CODE
BEGIN: .startup
mov AX, @DATA
mov DS, AX
FINIT

;;;;;;;;;;;;;;;STRLEN;;;;;;;;;;;;;;

STRLEN PROC

        ;mov bx, 0
        ;JMP STRL01
;STRL01:
        ;cmp BYTE PTR[SI+BX], '$'
        ;JS STREND
        ;inc BX
        ;jmp STRL01
;STREND:
        retn
STRLEN ENDP


;;;;;;;;;;;;MAIN;;;;;;;;;;;;;

    mov AX, @DATA

    mov es, ax
    mov si, OFFSET cad1
    mov di, OFFSET __AUX_CADENA_

    call STRLEN

    ;call COPIAR

    ;mov si, OFFSET cad2
    ;mov di, OFFSET __AUX_CADENA_
    ;call CONCAT

    ;mov si, OFFSET __AUX_CADENA_
    ;mov di, OFFSET cad3
    ;call COPIAR



mov AX, 4C00h
int 21h
END BEGIN

As you might see, I've been commenting the lines to find where the problem was. I came to the conclusion that the problem was the RET instruction. The program is well linked, but when I execute it I've got the following Windows dialog:

"The NTVDM CPU has encountered an illegal instruction. CS:0712 IP:0927 OP:ff 7f 00 00 00 Choose 'Close' to terminate the application."

The code works well in this part:

    mov AX, @DATA

    mov es, ax
    mov si, OFFSET cad1
    mov di, OFFSET __AUX_CADENA_

Until

    call STRLEN

Then, within STRLEN the only instruction it is non-commented is RET. That's why assume this is the problem.

I've been reading a lot, but I couldn't find the problem yet.

Somewhere in the web I've read that it is that the stack is corrupted, so when the proc "returns", it returns to an invalid memory address, which is something that the processor cannot understand.

Please, I wish someone could help me with this, I don't know what to do, I've tried a lot. Ask me whatever you need if the explanation was not clear or the information is not enough. Thank you very much.

Oh, by the way, I'm running Windows XP Mode 32bits

0

There are 0 best solutions below