Author Topic: Odd issue  (Read 1123 times)

Ascended

  • Member
  • ***
  • Posts: 331
Odd issue
« on: April 24, 2018, 07:02:21 PM »
Hi guys,

I have an odd one.

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

Code: [Select]
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

  • Member
  • *****
  • Posts: 8773
  • Assembler is fun ;-)
    • MasmBasic
Re: Odd issue
« Reply #1 on: April 24, 2018, 07:30:13 PM »
Can't be. Post full code.

Ascended

  • Member
  • ***
  • Posts: 331
Re: Odd issue
« Reply #2 on: April 24, 2018, 07:41:11 PM »
Russ, nope nothing in between that's the actual flow of the code. And this is the only call to this location.

Code: [Select]
; 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:

Ascended

  • Member
  • ***
  • Posts: 331
Re: Odd issue
« Reply #3 on: April 24, 2018, 07:44:36 PM »
Have you tried looking at it in ollydbg, or other???

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

Ascended

  • Member
  • ***
  • Posts: 331
Re: Odd issue
« Reply #4 on: April 24, 2018, 07:53:48 PM »
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.

AW

  • Member
  • *****
  • Posts: 1500
  • Let's Make ASM Great Again!
Re: Odd issue
« Reply #5 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 .

Ascended

  • Member
  • ***
  • Posts: 331
Re: Odd issue
« Reply #6 on: April 24, 2018, 08:16:22 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--

  • Administrator
  • Member
  • ******
  • Posts: 5831
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Odd issue
« Reply #7 on: April 24, 2018, 08:42:18 PM »
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

hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Siekmanski

  • Member
  • *****
  • Posts: 1671
Re: Odd issue
« Reply #8 on: April 24, 2018, 08:48:06 PM »
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.

Ascended

  • Member
  • ***
  • Posts: 331
Re: Odd issue
« Reply #9 on: April 24, 2018, 08:55:52 PM »
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:

-infinity

  • Regular Member
  • *
  • Posts: 19
Re: Odd issue
« Reply #10 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.
« Last Edit: April 24, 2018, 09:04:11 PM by hutch-- »

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5831
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Odd issue
« Reply #11 on: April 24, 2018, 09:05:17 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Ascended

  • Member
  • ***
  • Posts: 331
Re: Odd issue
« Reply #12 on: April 24, 2018, 09:11:17 PM »
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:

-infinity

  • Regular Member
  • *
  • Posts: 19
Re: Odd issue
« Reply #13 on: April 24, 2018, 09:16:39 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?   ::)


Ascended

  • Member
  • ***
  • Posts: 331
Re: Odd issue
« Reply #14 on: April 24, 2018, 09:26:04 PM »
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.

Code: [Select]
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??