News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Frame not in module?

Started by arsenalftw067, October 23, 2015, 04:16:53 PM

Previous topic - Next topic

arsenalftw067

My program was working fine and executing, now all of a sudden I get a unhandled exception which forces me to break and then it says frame not in module?

"The current stack frame was not found in a loaded module. Source cannot bee shown for this location"


TITLE Sort array (Array.asm)

; This program sorts an array with random integers
; and outputs them in order

INCLUDE Irvine32.inc ; new
includelib C:\Irvine\Kernel32
includelib C:\Irvine\User32
includelib C:\Irvine\Irvine32

.data
array BYTE 20, 10, 60, 5, 120, 90, 100 ; array with 7 values
arraysize = ($ - array) -1 ; size of array


.code
main PROC
call SortArray ; call function to sort
call ShowArray ; call function to show

call DumpRegs ; display the registers
call WaitMsg        ; Pause until a key is pressed
exit
main ENDP


SortArray PROC
mov esi, OFFSET array
mov ecx, arraysize;
L1:
push ecx
mov edi, esi ; use seond pointer
mov eax,[esi]
L2:
inc edi
CMP eax, [edi]; compare second value with previous
JGE exchg ; perform exchange
JLE dntxchg ; dont perform exchange

inc esi
pop ecx
loop L1

dntxchg:
loop L2 ; start loop again

exchg:
mov eax, [edi]
xchg [esi],eax
mov [edi], eax
loop L2 ;

ret
SortArray ENDP


ShowArray PROC

;show contents of array
mov esi, OFFSET array
mov ecx, arraysize
inc ecx
L3:
mov ebx, TYPE array
call DumpMem
loop L3

ret
ShowArray EndP
END main

gelatine1

alright so the last 3 lines of the following code are never executed (Do you understand why ?) and thus you will only loop in L2. And in L2 you are popping and popping lots of values from the stack but since L1 isn't repeated no values or pushed onto the stack. This makes the program crash obviously.


CMP eax, [edi]; compare second value with previous
JGE exchg ; perform exchange
JLE dntxchg ; dont perform exchange

inc esi
pop ecx
loop L1

dedndave

I do see an imbalance in the stack, in the sort function

all is well until you branch
then, the stack becomes unbalanced due to a PUSH ECX without a corresponding POP
it may be that you PUSH PUSH PUSH until the stack barks   :shock:
or, it could be that it tries to RET to an address that isn't code inside your EXE

(I've never seen that specific error message - lol)

arsenalftw067

Ah yes I see, so how am I supposed to properly implement it?

Basically what I'm trying to do is:

Have esi point to the first element, whilst I use a second pointer which will keep pointing to the next element and comparing it to esi. Then, when edi reaches the last element, I want to increment esi so it points to the second element, and then I use edi again to compare it with every other element 

dedndave

unfortunately, i don't have time to really dig into the code

but, offhand, i would try to do it without push and pop
you have 7 registers, including EBP
there's a good chance it could be written without push and pop   :t

rrr314159

Quote from: arsenalftw067Have esi point to the first element, whilst I use a second pointer which will keep pointing to the next element and comparing it to esi.

The following code is not right. You want to move only the byte at esi into eax, not the next 4 bytes (dword).

;instead of

       mov eax,[esi]

;do this (there are alternatives)

       movzx eax,BYTE PTR [esi]


- That's assuming the byte values won't be negative; if they can be, use movsx.

instead of using edi you could compare to [esi+1]: 

;instead of

CMP eax, [edi]; compare second value with previous

;you could use

CMP al, BYTE PTR [esi+1]; compare second value with previous


- It requires changing the looping and exchg code appropriately

- I should check this by running it but, hopefully you get the idea. Anyway, you have to fix the first problem. But you can continue to use edi; it "wastes" a register but, it does work
I am NaN ;)