News:

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

problem testing program

Started by Neil, February 19, 2009, 06:50:36 PM

Previous topic - Next topic

Neil

Sinsi,
They are 2 macros I added into macros Asm :-

    ; ----------------------
    ; fast lodsw replacement
    ; ----------------------
      ldw MACRO
        mov ax, [esi]
        add esi,2
      ENDM


    ; ----------------------
    ; fast stosw replacement
    ; ----------------------
      stw MACRO
        mov [edi], ax
        add edi,2
      ENDM

Neil

I've fired up my old computer (out of the attic) & the program runs perfectly OK on it, so I am unable to reproduce at home the unstability manifesting itself elsewhere. What I've decided to do is finish writing the program then install masm32 & Olly on my son's PC (He lives quite near) & see if I can get to the bottom of this mystery unless of course anyone else can come up with a possible solution.

sinsi

One thing I noticed, using windbg near those crash addresses, was
- loading a value in ax
- and eax,65535
which left eax as FFF6 (signed maybe?), then that was added to ESI (a pointer to a buffer) - this put ESI pointing to memory 64K past the buffer, there's the access violation.

From a quick look at the code, you seem to be mixing 8-bit, 16-bit and 32-bit code (e.g. "mul ten", "mul tn") which seems ok but is a bit hard to follow...and can have consequences in later code. Is this a straight port from 16-bit (DOS) code?

edit: I tried the program in NT4, 98 and 2000 (via virtualpc) and all showed the same crashes.
Light travels faster than sound, that's why some people seem bright until you hear them.

Neil

Sinsi,
The mul tn, ten etc were ported directly from DOS purely as a time saver as I knew they worked, I shall probably be changing them when I refine the code later.
The and eax,65535 is used to clear the hi 16 bits of eax because it's not possible to add ax to esi, I also use it in other parts of the program so that I can use print ustr$(eax) & do away with converting the value to ascii.

Neil

I'm busy cutting a tree down at the moment so I haven't got much time for programming.
Sinsi that value left in eax does seem rather bigger than it should be, could you give me the line number where it is.

Neil

I've had time now to look at the code & I think I've found what you were looking at :-

    mul tn            ;get total numbers of balls drawn
    lea esi,Binary    ;point at database
    and eax,65535

When I check the value of eax it's 35A2h which is what it should be.
this is at line 4463

PBrennick

Neil,
To add AX and ESI all you need to do is a Sign Extend.

QuoteIn the x86 instruction set, used by the main microprocessors of all common PCs, there are two ways of doing sign extension:

    * using the instructions cbw, cwd, cwde, and cdq ("convert byte to word", "c. word to doubleword", "c. w. to extended dw.", and "c. dw. to quadword", respectively; in the x86 context, a byte has 8 bits, a word 16 bits, a doubleword and extended doubleword 32 bits, and a quadword 64 bits);
    * using one of the sign extended moves, accomplished by the movsx ("move with sign extension") family of instructions.

The sign is preserved. These methods are preferable as they are less prone to errors.

hth,
Paul
The GeneSys Project is available from:
The Repository or My crappy website

Neil

Hi Paul,
I'm using unsigned numbers, so correct me if I'm wrong, I don't think it would work in my case, thats why i'm blanking the Hi 16 bits of eax before using the add instruction.

Neil

Thinking about it a bit more, changing my data to dd instead of dw would do away with the problem altogether.

Neil

Paul I wasn't thinking straight (I've had a busy day), you're right I don't use negative numbers so bit 15 of ax would be zero & wouldn't change the value overall :red

Neil

I've tried replacing this :-

    mov ax,evens
    and eax,65535

with

    mov ax,evens
    cwd

Now the program crashes on my computer, ax never contains a value greater than 6.
I'm getting even more confused now :eek


sinsi

QuoteThe and eax,65535 is used to clear the hi 16 bits of eax because it's not possible to add ax to esi
The trouble is (as far as I've followed that one problem) is that your cursor position seems to be a negative (FFF6), so when you 'and eax,FFFF' you are adding FFF6 to ESI.
Using CWD only sign-extends AX into DX:AX, you need something like    movsx eax,evensThis will give you the correct value in EAX (FFFFFFF6) and not DX:AX
Light travels faster than sound, that's why some people seem bright until you hear them.

Neil

Thanks sinsi,
I'll look into that.
Still the big mystery is that it's been tested on 8 different PC's, 4 on which it runs perfectly & 4 on which it crashes.

Neil

sinsi,
movsx has cured that one, I was using edx it bit further on in the loop & of course cwd was corrupting it :U

jj2007

cwd doesn't work, but there are two other instructions which perform the job:

   xor eax, eax
   mov ax, 0fff6h  ; create a test case
   cwde
   print str$(eax), 9

   xor eax, eax
   mov ax, 0fff6h  ; create a test case
   movsx eax, ax
   print str$(eax)

From Intel Hex Opcodes And Mnemonics (opcodes.hlp):

CWDE - Convert Word to Extended Doubleword (386+)
        Usage:  CWDE
        Modifies flags: None
        Converts a signed word in AX to a signed doubleword in EAX by
        extending the sign bit of AX throughout EAX.

MOVSX - Move with Sign Extend (386+)
        Usage:  MOVSX   dest,src
        Modifies flags: None
        Copies the value of the source operand to the destination register
        with the sign extended.

cwde is one byte short, movsx needs three bytes.