The MASM Forum

General => The Campus => Topic started by: Lonewolff on April 24, 2018, 07:02:21 PM

Title: Odd issue
Post by: Lonewolff 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;


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?
Title: Re: Odd issue
Post by: jj2007 on April 24, 2018, 07:30:13 PM
Can't be. Post full code.
Title: Re: Odd issue
Post by: Lonewolff 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.


; 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:
Title: Re: Odd issue
Post by: Lonewolff on April 24, 2018, 07:44:36 PM
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.
Title: Re: Odd issue
Post by: Lonewolff 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.
Title: Re: Odd issue
Post by: 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 .
Title: Re: Odd issue
Post by: Lonewolff on April 24, 2018, 08:16:22 PM
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
Title: Re: Odd issue
Post by: hutch-- 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

Title: Re: Odd issue
Post by: Siekmanski 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 )
Title: Re: Odd issue
Post by: Lonewolff 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:
Title: Re: Odd issue
Post by: russellgreen 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.
Title: Re: Odd issue
Post by: hutch-- 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.
Title: Re: Odd issue
Post by: Lonewolff 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:
Title: Re: Odd issue
Post by: russellgreen on April 24, 2018, 09:16:39 PM
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?   ::)

Title: Re: Odd issue
Post by: Lonewolff 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.

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??
Title: Re: Odd issue
Post by: Siekmanski on April 24, 2018, 09:26:25 PM
This example doesn't work with eax, but it does with esi.

D3DMatrixTranspose proc pOut:DWORD,pM2:DWORD
mov esi,offset pM

movaps  xmm0,[esi+0]            ; [0 1 2 3]
movaps  xmm1,[esi+16]           ; [4 5 6 7]
movaps  xmm4,[esi+32]           ; [8 9 A B]
movaps  xmm3,[esi+48]           ; [C D E F]


This with parameters works well with eax.

D3DMatrixTranspose proc pOut:DWORD,pM:DWORD
; [0 1 2 3]    [0 4 8 C]
; [4 5 6 7]    [1 5 9 D]
; [8 9 A B]    [2 6 A E]
; [C D E F]    [3 7 B F]

mov     eax,pM

movaps  xmm0,[eax+0]            ; [0 1 2 3]
movaps  xmm1,[eax+16]           ; [4 5 6 7]
movaps  xmm4,[eax+32]           ; [8 9 A B]
movaps  xmm3,[eax+48]           ; [C D E F]


At least it behaves like that on my machine.


EDIT: Aaaargh, I was totally wrong.  :dazzled:

I used ESI only because I used windows functions as well.
Sorry for the misconception.
Think I need a break and clear my mind.  :icon_mrgreen:
Title: Re: Odd issue
Post by: jj2007 on April 24, 2018, 10:59:52 PM
Quote from: Lonewolff 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.

The usual approach is to insert an int 3 just in front of the code you want to study. Then you launch the exe with Olly, hit F9 (=run!), and voilà, it stops right there and you can watch, hitting F7, what happens.

In the upper right corner, there is the "Registers" window. Right-click on EAX and choose "Follow in dump". Now, hitting F7, you can watch what exactly happens to [eax+4] and [eax+16]. Note that Olly uses hex notation, so eax+10 means eax+10h.

Again: If eax is the correct pointer, those few lines will swap the memory content. There are no hidden CPU quirks, you can trust intel and AMD 8)

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

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


Btw, here is another method that does the swap with one single register:
  push [eax+4]
  push [eax+16]
  pop [eax+4]
  pop [eax+16]

It takes 7 cycles instead of 4, so it is slower, but if you need the registers for other uses and your number of iterations is below ten Millions, that is not a problem.
Title: Re: Odd issue
Post by: LordAdef on April 25, 2018, 03:42:22 AM
something Jj forgot to say about Olly: you may want to set Olly to start at you program starting point, otherwise it will not
Title: Re: Odd issue
Post by: Lonewolff on April 25, 2018, 08:25:40 PM
I tracked down where the fault is. Still doesn't make much sense to me though.

It is to do with the loop


myloop:
invoke MatrixTranspose, addr testMat

mov eax, ddCounter
inc eax
mov ddCounter, eax
cmp eax, ddCount
jl myloop


If I comment out the loop code the MatrixTranspose function works correctly.

I know that 'invoke' stores its result in EAX, but EAX is immediately overwritten on the next line.

So I am still a little confused as to why this should affect the MatrixTranspose prototype.

Even if I change EAX to ECX the fault remains.


[edit]
Arghhh.... Worked it out.

It is an absolute noob bug.

Because I am testing performance in a loop I am continuously transposing the same matrix. Just so happens because I am working with an even number of iterations, I am transposing the matrix back to what it was to begin with. ROFL.

Man, what a stupid mistake :P

Title: Re: Odd issue
Post by: hutch-- on April 25, 2018, 08:48:54 PM
 :biggrin:

Something we all have is a list of stupid mistakes, the more you make, the faster you get at fixing them. Its called "programming".  :P
Title: Re: Odd issue
Post by: Lonewolff on April 25, 2018, 08:55:50 PM
Haha true!

I'm usually fast with debugging in C++ and the likes.

Bit slower debugging my ASM because, I guess, the confidence isn't quite there yet.

Ripping through things though. In the past two weeks I have written over 2000 lines of code in ASM. So in reality the code produced vs questions asked ratio is pretty good.  :bgrin:
Title: Re: Odd issue
Post by: RuiLoureiro on April 26, 2018, 10:23:51 PM
Quote from: Lonewolff 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 (for what ?) 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  <<<<<< remove this
;-----------------------------------
Define szFloat HERE in this way
;-----------------------------------
              dd 0             ; <<<< here is the string length
szFloat       db 16 dup(?)



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

Maybe the source of the problem in my other project??  <<<< YES, it seems
The problem seems to be this: you dont show what/how you are doing, only some things.
Other important things you dont show (we try to guess).

This shows what you want. It needs  the file InputPrint.mac (.zip below)
and we need to include InputPrintProc.inc (.zip below) to use some macros in InputPrint.mac.
You may use it to input/print matrixes...

; File:       TestMatrix1.asm
; Written by: RuiLoureiro

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
include \masm32\include\masm32rt.inc
.686p
     ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            ; »»»»»»»»»»»»»»»»                          »»»»»»»»»»»»»»»»
            ; »»»»»»»»»»»»»»»» CONSOLE ASSEMLBLE & LINK »»»»»»»»»»»»»»»»
            ; »»»»»»»»»»»»»»»»                          »»»»»»»»»»»»»»»»
            ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                ;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
                        include     InputPrint.mac            ; macros to input/print

                        ConvertFloat4DF     proto   :DWORD,:DWORD
                ;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
$MsgLin         = 3         ; menu line
$MsgCol         = 15        ; menu column
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;»«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;----------------------------------------------------------------------
.data
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;       HERE we have a macro that define some frequently used variables
;
FREQUENTLYUSEDVARIABLE

testMat      real4   11.0,12.0,13.0,14.0    ;     line 1
                  real4 21.0,22.0,23.0,24.0    ; +16 line 2
                  real4 31.0,32.0,33.0,34.0    ; +32 line 3
                  real4 41.0,42.0,43.0,44.0    ; +48 line 4
; ,0.0

                 dd 0          ; <<<<<--- for string length
szFloat          db 16 dup(?)

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;                   general variables
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
.data?
_hInstance      dd ?
            ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
            ;                       Start HERE
  ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
.code
start:
                invoke      GetModuleHandle, 0
                mov         _hInstance, eax

                invoke      ConvertFloat4DF, addr testMat+60, addr szFloat

                printstring $MsgLin, $MsgCol, addr szFloat
                ;printLF
               
                invoke      MessageBeep, 0FFFFFFFFh
                inkeyLC    $MsgLin+2, $MsgCol, "The last value is printed correctly"       
            ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     itisdone:      cls
                    inkey   "Bye bye ... Good luck!"
                    exit    ;*****************************************************************************

;################################################################
        ;               Internal procedures are below
        ; ################################################################                   
                        include     InputPrintProc.inc
                        include     ConverterDD.inc
                ;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
end start
Title: Re: Odd issue
Post by: RuiLoureiro on April 27, 2018, 05:07:15 AM
Here we have a test program to show the matrix

; File:       TestMatrix3.asm
; Written by: RuiLoureiro

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
include \masm32\include\masm32rt.inc
.686p
           ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            ; »»»»»»»»»»»»»»»»                          »»»»»»»»»»»»»»»»
            ; »»»»»»»»»»»»»»»» CONSOLE ASSEMLBLE & LINK »»»»»»»»»»»»»»»»
            ; »»»»»»»»»»»»»»»»                          »»»»»»»»»»»»»»»»
            ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                ;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
                        include     InputPrint.mac            ; macros to input/print

                        ConvertFloat4DF     proto   :DWORD,:DWORD
                ;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

;»«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;----------------------------------------------------------------------
.data
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
;       HERE we have a macro that define some frequently used variables
;
FREQUENTLYUSEDVARIABLE

MAXLINES        equ 4     ; number of lines
MAXCOLUMNS      equ 4     ; number of columns

testMat      real4   11.0,12.0,13.0,14.0    ;     line 1
                  real4 21.0,22.0,23.0,24.0    ; +16 line 2
                  real4 31.0,32.0,33.0,34.0    ; +32 line 3
                  real4 41.0,42.0,43.0,44.0    ; +48 line 4

; buffer to get the converted values
;-----------------------------------
                 dd 0          ; <<<<<--- for string length
szFloat          db 16 dup(?)

_printLin        dd 10      ; first line   to print
_printCol        dd 10      ; first column to print
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
;                   general variables
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
.data?
_hInstance      dd ?
            ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
            ;                       Start HERE
            ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
.code
start:
                invoke      GetModuleHandle, 0
                mov         _hInstance, eax

                mov         esi, offset testMat
                mov         ebx, 1                ; line
                mov         edi, 1                ; column

                printit     8, 10, "***** Show Matrix *****"
               
     _loop0:    invoke      ConvertFloat4DF, esi, addr szFloat
                jc          itisdone
                add         esi, 4
               
                printstring _printLin, _printCol, addr szFloat
               
                ;---------------------------------------------
                ;             next column
                ;---------------------------------------------
                add         edi, 1
                add         _printCol, 20

                cmp         edi, MAXCOLUMNS
                jbe         short _loop0
               
                mov         edi, 1
                mov         _printCol, 10
               
                ;---------------------------------------------
                ;             next line
                ;---------------------------------------------
                add         ebx, 1
                add         _printLin, 1
                               
                cmp         ebx, MAXLINES
                jbe         short _loop0

                ;---------------------------------------------
                invoke      MessageBeep, 0FFFFFFFFh
                add         _printLin, 1
     
                inkeyLC     _printLin, 10, "It is done. Press any key to continue ..."       
          ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                    cls
     itisdone:      inkey   "Bye bye ... Good luck!"
                    exit
        ;-----------------------------------------------------------------------------        ;*****************************************************************************
        ;-----------------------------------------------------------------------------
                   
        ; ################################################################
        ;               Internal procedures are below
        ; ################################################################                   
                        include     InputPrintProc.inc
               
                        include     ConverterDD.inc
                ;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
end start

Quote

          ***** Show Matrix *****

          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

          It is done. Press any key to continue ...
Title: Re: Odd issue
Post by: RuiLoureiro on April 27, 2018, 06:46:06 AM
Hi LoneWolff,

This is what is written in ConverterDD.inc (and you didnt see i guess)
Quote
; Input:
;           pReal4 = pointer
;                                                           dd 0    <------- for lenght
;           pRcl   --------------> buffer shoud be  _buffer db x dup (?), 0
;
ConvertFloat4DF     proc     pReal4:DWORD, pRcl:DWORD
                    LOCAL    expscale     :DWORD   
                    LOCAL    exponent     :DWORD
                    LOCAL    integer      :DWORD
                    LOCAL    oldcw        :WORD
                    LOCAL    truncw       :WORD
                    LOCAL    string[22]   :BYTE
If you dont want/need the string length do this
and use only


.data?
szFloat   16 dup(?)


Quote
                    ...
                   
        _finish:    mov      eax, edi
                    mov      edi, pRcl
                    sub      eax, edi

        _exit0:     ; mov      dword ptr [edi-4], eax       <<<<< remove this
                    mov      byte ptr [edi+eax], 0
                                             
                    xor      eax, eax   ; EAX = 0
                    clc
        _exit:      pop      edi
                    pop      esi
                    pop      ebx
                    ret
                   
                    ; --------------------
                    ; is indefinite or NAN
                    ; --------------------
        _erro1:     mov    eax, 1
                    ;
        _error:     mov    dword ptr [edi+0], "ORRE"
                    mov    byte ptr [edi+4], "R"
                    ;
                    ; mov      dword ptr [edi-4], 5       <<<< remove this
                    mov      byte ptr [edi+5], 0
                    stc
                    jmp    _exit
                                       
                    ; -----------------
                    ; invalid operation
                    ; -----------------
        _erro2:     fclex
                    mov      eax, 2
                    stc
                    jmp      _error
ConvertFloat4DF     endp

Good luck  :t
Title: Re: Odd issue
Post by: Lonewolff on April 27, 2018, 08:31:04 AM
Quote from: RuiLoureiro on April 26, 2018, 10:23:51 PM
Maybe the source of the problem in my other project??  <<<< YES, it seems

No. It wasn't. (As explained above)
Title: Re: Odd issue
Post by: RuiLoureiro on April 28, 2018, 08:36:00 AM
Quote from: Lonewolff on April 27, 2018, 08:31:04 AM
Quote from: RuiLoureiro on April 26, 2018, 10:23:51 PM
Maybe the source of the problem in my other project??  <<<< YES, it seems

No. It wasn't. (As explained above)
Hi LoneWolff,
              The problem you post in the reply #14 was solved in my reply #21.
              You said that you added one dword (0.0) to the last value in TestMat
              and in this way ConvertFloat4DF shows the last value 44.0 correctly.
              Note that if we define szFloat after TestMat without one dword behind
              we need to add one dword (dd or real4) in the TestMat.
This:
Quote
TestMat   real4 a,b,.......,z, 0.0
szFloat   db 16 dup (?)
is the same as this:
Quote
TestMat   real4 a,b,.......,z
            dd 0
szFloat   db 16 dup (?)
             Wherever we define szFloat we need to put a dword behind.
             ConvertFloat4DF only works correctly in this way.
             This is why i gave the answer "YES it seems".

             The first post of ConverterDD was in 19 April 2013 and
             i never used it. Now i am reading it again and i found out
             that the algorithm to examine any real4 when we call
             ConvertFloat4DF doesnt test the exponent part (in DL).
            It tests only for DL=FFh.
             
             If DL=0 and fraction part (in EAX) is 0, the result may be
             0 if the bit sign is 0 or -0 (replaced by 0) if the bit sign is 1.
             If DL=0 but EAX is not, the procedure will exit with an error
             (is a denormalized value). Now, if you know, you may correct it.
             
             So, as soon as possible, i will correct this bug and i will post it
             and i will show it here to you.
             
             Thanks  :t
Title: Re: Odd issue
Post by: RuiLoureiro on May 02, 2018, 01:27:12 AM
I Ascended,

                  You may see the new Converter8 here:

                               http://masm32.com/board/index.php?topic=1859.0 (http://masm32.com/board/index.php?topic=1859.0)
Title: Re: Odd issue
Post by: RuiLoureiro on May 02, 2018, 02:41:02 AM
Hi
     Here we have ConverterDF to replace ConverterDD.

     You may see:
                       http://masm32.com/board/index.php?topic=1819.new#new (http://masm32.com/board/index.php?topic=1819.new#new)

     Now we may use ConvertFloat4DF or ConvertReal4DF.
Quote
3.141593
00000001 =ERROR
007FFFFF =ERROR
7F800000 =+INFINITY
FF800000 =-INFINITY
7F7FFFFF =3.40282E+38
00800000 =1.175494E-38
0
0                                <<<<<<<<<<----  is -0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
*** STOP - ConvertFloat4DF  end test digits ***
-1.1
-11.1
-111.1
-1111.1
-11111.1
-111111.1
-1.111111E+06
-1.111111E+07
-2.2
-22.2
-222.2
-2222.2
-22222.2
-222222.2
-2.222222E+06
-2.222222E+07
-3.3
-33.3
-333.3
-3333.3
-33333.3
-333333
-3.33333E+06
-3.33333E+07
*** STOP - ConvertFloat4DF ***
-4.4
-44.4
-444.4
-4444.4
-44444.4
-444444
-4.44444E+06
-4.44444E+07
-5.5
-55.5
-555.5
-5555.5
-55555.5
-555556
-5.55556E+06
-5.55556E+07
-6.6
-66.6
-666.6
-6666.6
-66666.6
-666667
-6.66667E+06
-6.66667E+07
-7.7
-77.7
-777.7
-7777.7
-77777.7
-777778
-7.77778E+06
-7.77778E+07
*** STOP - ConvertFloat4DF ***
-8.8
-88.8
-888.8
-8888.8
-88888.8
-888889
-8.88889E+06
-8.88889E+07
-9.9
-99.9
-999.9
-9999.9
-99999.9
-1.0E+06
-1.0E+07
-1.0E+08
*** STOP - ConvertFloat4DF ***
0.1
0.01
0.001
0.0001
0.00001
0.000001
1.0E-07
1.0E-08
1.0E-09
*** STOP - ConvertFloat4DF ***
0.2
0.02
0.002
0.0002
0.00002
0.000002
2.0E-07
2.0E-08
2.0E-09
*** STOP - ConvertFloat4DF ***
0.3
0.03
0.003
0.0003
0.00003
0.000003
3.0E-07
3.0E-08
3.0E-09
*** STOP - ConvertFloat4DF ***
0.4
0.04
0.004
0.0004
0.00004
0.000004
4.0E-07
4.0E-08
4.0E-09
*** STOP - ConvertFloat4DF ***
0.5
0.05
0.005
0.0005
0.00005
0.000005
5.0E-07
5.0E-08
5.0E-09
*** STOP - ConvertFloat4DF ***
0.6
0.06
0.006
0.0006
0.00006
0.000006
6.0E-07
6.0E-08
6.0E-09
*** STOP - ConvertFloat4DF ***
0.7
0.07
0.007
0.0007
0.00007
0.000007
7.0E-07
7.0E-08
7.0E-09
*** STOP - ConvertFloat4DF ***
0.8
0.08
0.008
0.0008
0.00008
0.000008
8.0E-07
8.0E-08
8.0E-09
*** STOP - ConvertFloat4DF ***
0.9
0.09
0.009
0.0009
0.00009
0.000009
9.0E-07
9.0E-08
9.0E-09
*** STOP - ConvertFloat4DF ***
-1.234568
-12.34568
-123.4568
-1234.568
-12345.68
-123456.8
-1.234568E+06
-1.234568E+07
*** STOP - ConvertFloat4DF ***
-1.1
-11.1
-111.1
-1111.1
-11111.1
-111111.1
-1.111111E+06
-1.111111E+07
*** STOP - ConvertFloat4DF --- E N D ---***

3.141593
00000001 =ERROR
007FFFFF =ERROR
7F800000 =+INFINITY
FF800000 =-INFINITY
7F7FFFFF =3.40282E+38
00800000 =1.175494E-38
0
0                                    <<<<<<<<<---  is -0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
*** STOP - ConvertReal4DF  end test digits ***
-1.1
-11.1
-111.1
-1111.1
-11111.1
-111111.1
-1.111111E+06
-1.111111E+07
-2.2
-22.2
-222.2
-2222.2
-22222.2
-222222.2
-2.222222E+06
-2.222222E+07
-3.3
-33.3
-333.3
-3333.3
-33333.3
-333333
-3.33333E+06
-3.33333E+07
*** STOP - ConvertReal4DF ***
-4.4
-44.4
-444.4
-4444.4
-44444.4
-444444
-4.44444E+06
-4.44444E+07
-5.5
-55.5
-555.5
-5555.5
-55555.5
-555556
-5.55556E+06
-5.55556E+07
-6.6
-66.6
-666.6
-6666.6
-66666.6
-666667
-6.66667E+06
-6.66667E+07
-7.7
-77.7
-777.7
-7777.7
-77777.7
-777778
-7.77778E+06
-7.77778E+07
*** STOP - ConvertReal4DF ***
-8.8
-88.8
-888.8
-8888.8
-88888.8
-888889
-8.88889E+06
-8.88889E+07
-9.9
-99.9
-999.9
-9999.9
-99999.9
-1.0E+06
-1.0E+07
-1.0E+08
*** STOP - ConvertReal4DF ***
0.1
0.01
0.001
0.0001
0.00001
0.000001
1.0E-07
1.0E-08
1.0E-09
*** STOP - ConvertReal4DF ***
0.2
0.02
0.002
0.0002
0.00002
0.000002
2.0E-07
2.0E-08
2.0E-09
*** STOP - ConvertReal4DF ***
0.3
0.03
0.003
0.0003
0.00003
0.000003
3.0E-07
3.0E-08
3.0E-09
*** STOP - ConvertReal4DF ***
0.4
0.04
0.004
0.0004
0.00004
0.000004
4.0E-07
4.0E-08
4.0E-09
*** STOP - ConvertReal4DF ***
0.5
0.05
0.005
0.0005
0.00005
0.000005
5.0E-07
5.0E-08
5.0E-09
*** STOP - ConvertReal4DF ***
0.6
0.06
0.006
0.0006
0.00006
0.000006
6.0E-07
6.0E-08
6.0E-09
*** STOP - ConvertReal4DF ***
0.7
0.07
0.007
0.0007
0.00007
0.000007
7.0E-07
7.0E-08
7.0E-09
*** STOP - ConvertReal4DF ***
0.8
0.08
0.008
0.0008
0.00008
0.000008
8.0E-07
8.0E-08
8.0E-09
*** STOP - ConvertReal4DF ***
0.9
0.09
0.009
0.0009
0.00009
0.000009
9.0E-07
9.0E-08
9.0E-09
*** STOP - ConvertReal4DF ***

-1.234568
-12.34568
-123.4568
-1234.568
-12345.68
-123456.8
-1.234568E+06
-1.234568E+07
*** STOP - ConvertReal4DF ***
-1.1
-11.1
-111.1
-1111.1
-11111.1
-111111.1
-1.111111E+06
-1.111111E+07
*** STOP - ConvertReal4DF --- E N D ---***
     Good Luck :t
      :icon14: