News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Odd issue

Started by Lonewolff, April 24, 2018, 07:02:21 PM

Previous topic - Next topic

Lonewolff

Hi guys,

I have an odd one.

I am trying to swap the data between two locations like so;


mov ecx,[eax+4]
mov edx,[eax+16]

mov [eax+16],ecx
mov [eax+4],edx


But the data remains the same.

If I comment one of the last lines, I can verify that the data is being copied from one location to the other.

Is this some weird CPU cache quirk or something?

jj2007

Can't be. Post full code.

Lonewolff

Russ, nope nothing in between that's the actual flow of the code. And this is the only call to this location.


; The WIP proc
MatrixTranspose PROC matrix:DWORD
mov eax, matrix ; Store the address of 'matrix' in eax

mov edx,[eax+16] ; _21
mov ecx,[eax+4] ; _12
mov [eax+16],ecx
mov [eax+4],edx

ret
MatrixTranspose ENDP


;Initialising a 4x4 matrix like this.

testMat real4 11.0,12.0,13.0,14.0,21.0,22.0,23.0,24.0,31.0,32.0,33.0,34.0,41.0,42.0,43.0,44.0


;Calling the proc like this

invoke MatrixTranspose, addr testMat


Got me bewildered.  :dazzled:

Lonewolff

Quote from: RussG on April 24, 2018, 07:43:54 PM
Have you tried looking at it in ollydbg, or other???

Not real familiar with it, but I will give it a go.

Lonewolff

Hmmm. Trying to make sense of OllyDebug, but the code I am looking at looks nothing like what I have typed in. Not even remotely similar.

[edit]
I wrapped the code with a bunch of NOP's so I could find the bit in question.

Just trying to figure out how to read these registers.

aw27

Since newbies, no offense of course, usually commit newbie mistakes it is advisable that they post the whole code .

Lonewolff

Quote from: aw27 on April 24, 2018, 08:09:31 PM
Since newbies, no offense of course, usually commit newbie mistakes it is advisable that they post the whole code .

None taken  :biggrin:

I'll take out the excess guff and see if I can post something minimal to replicate.  :t

FWIW - OllyDebug showed this

Quote
   mov edx,[eax+16]      ; EDX 41A80000
   mov ecx,[eax+4]      ; ECX 41400000
   mov [eax+16],ecx      
   mov [eax+4],edx

hutch--

Wolf,

What is in EAX to start with ?

LATER :

The code seems to work OK but I don't know what you are doing with it.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    LOCAL bvar[64] :BYTE

    push ebx
    push esi
    push edi

    lea eax, bvar
    mov DWORD PTR [eax], 0
    mov DWORD PTR [eax+4], 1
    mov DWORD PTR [eax+8], 2
    mov DWORD PTR [eax+12], 3
    mov DWORD PTR [eax+16], 4

  ; --------------------------------------

    mov edx,[eax+16]      ; EDX 41A80000
    mov ecx,[eax+4]       ; ECX 41400000
    mov [eax+16],ecx     
    mov [eax+4],edx

  ; --------------------------------------

    mov esi, eax

    mov ecx, [esi]
    print str$(ecx),13,10

    mov eax, [esi+4]
    print str$(eax),13,10

    mov eax, [esi+8]
    print str$(eax),13,10

    mov eax, [esi+12]
    print str$(eax),13,10

    mov eax, [esi+16]
    print str$(eax),13,10

    pop edi
    pop esi
    pop ebx

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start


Siekmanski

If eax is from a struct, try ESI instead of EAX ( don't forget to preserve ESI )
Creative coders use backward thinking techniques as a strategy.

Lonewolff

I just rewrote the program to be a console application and the proc works fine.

I think I'll back away slowly and chalk this up to a WTF.  :eusa_snooty:

russellgreen

#10
Russ,

Leave this stuff to the older guys. We keep the Campus for people learning assembler and the noise although well intended is a distraction.

hutch--

Wolf,

Don't give up on what you were trying, that type of data swap is common in the guts of a sort and its useful code to understand.

Lonewolff

Hey Hutch,

Nah, haven't given up. Just going to use a console 'test bed' instead of mucking around with a windows one. :t

All of this is in order to streamline my Matrix library I have created, just to give easy output to make sure the numbers are correct, so I am better with a small console program anyway.

I must have done something weird somewhere in my windows app, as it has been displaying the correct anticipated values all day long until this hiccup.

Certainly haven't given up. I have come so far in such a short time.  :biggrin:

russellgreen

Quote from: RussG on April 24, 2018, 09:01:12 PM
Russ,

Leave this stuff to the older guys. We keep the Campus for people learning assembler and the noise although well intended is a distraction.

wtf?   ::)


Lonewolff

I am a bit dubious that 'ConverterDD.inc' is doing the right thing.

I had to add an extra phantom value of 0.0 at the end of my real4 array to make the value of '44.0' display correctly.

testMat real4 11.0,12.0,13.0,14.0,21.0,22.0,23.0,24.0,31.0,32.0,33.0,34.0,41.0,42.0,43.0,44.0     ,0.0

Otherwise invoke ConvertFloat4DF, addr testMat+60, addr szFloat just displays a garbage value.

Maybe the source of the problem in my other project??