News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Access violation with parameter.. .

Started by indiocolifa, September 21, 2005, 08:00:39 AM

Previous topic - Next topic

indiocolifa

I finally have done the 6502 memory dissasembler (works great)....
But the problem is that it's working except you use as starting address anything > $3060  :dazzled:

Let's show the code.

First, the definition of memory (64K RAM):


CONST RAM_SIZE := 64*1024;
TYPE    sysmem : BYTE[RAM_SIZE];


Now the procedure to dissasemble memory is (until stops with access violation):


/**** Dissasembler ****/
procedure       disasm ( var mem    : sysmem;
                         startaddr  : WORD ;
                         endaddr    : WORD );@nodisplay;
static
    opcodestr : string;
    op1       : byte;
    op2       : byte;
begin           disasm;

    push            (eax);
    push            (ebx);
    push            (ecx);
    push            (edx);
    xor             (ecx,ecx);
    xor             (edx,edx);
    mov             (startaddr, cx);
lp: movzx           (MEM_PTR, eax);                     // fetch byte from memory


In that MOVZX instruction the program crashes (if you use the parameter startaddr<$3060 works perfect...   :eek)

Remeber that MEM_PTR is a text constant defined as:


MEM_PTR      : text := "(type sysmem mem[ecx])";


Why I'm getting fault at this address??!

Thank you in advance.. and I repeat that HIDE/HLA combination is the best approach to easy and fun assembly. :clap:




indiocolifa

After playing a bit and adding dynamic memory allocation, fixed IT!
:8) :8)

Sevag.K

Cool, but you shouldn't have to change your memory structure to make things work :)

Just so you know what was going on before:

MEM_PTR      : text := "(type sysmem mem[ecx])";

This scheme is not good to use on reference arguments.

HLA translates this:

movzx           (MEM_PTR, eax);


to this:

movzx   ax, byte ptr [ebp+ecx*1+16]   ;/* (type sysmem mem) */

As you can see, what the code is doing is retreiving bytes off the *stack*

What you needed to do was dereference the pointer and use it through registers:

eg:

xor ( ecx, ecx );
mov ( mem, ebx ); // load ebx with the address of memory (static or dynamic)
mov ( startaddr, cx );
mov ( [ ebx + ecx ], al);  // grab the byte at location cx


This method can be used with both static and dynamic memory.

btw: thanks for the complimens on HIDE.

indiocolifa

Yes, my friend, I've not fixed just with dynamic alloc  :green but using:


xor             (ecx,ecx);
    xor             (edx,edx);
    mov             (memptr, eax);      // eax -> base memory address
   
    FOR (mov(startaddr,cx); cx <= endaddr; inc(cx)) do
       
        stdout.put      (cx,":");
       
        // write memory values
        FOR (xor(ebx,ebx); (ebx < 16); inc(ebx)) do
            mov             ([eax+ecx], dl);    // fetch byte from 6502 memory


See that  [eax+ecx] that fixed all, just as you pointed it.

Thank you very much for your invaluable help.
I'll soon send you my 6502 Monitor (DOS Debug-like) to show you my progress.