Registers displaying reverse stored informaiton.

Started by Chip, October 15, 2006, 03:09:06 AM

Previous topic - Next topic

Chip

My program reads information into a buffer,
and then immediately copies it to a register
for processing.  (The buffer is treated as
one large array.)

In testing, I recently switched from arbitrary
"FFFFFFFF" input to input files with varying
data.  Suddenly, nothing made since in my
routines.

In debugging the problem, it became apparent
that the value read into the register was
reverse stored.  However, neither the buffer
nor a register copy to memory showed this
reverse storage condition.  (I tried using
every variation of register and memory moves
to no avail.)


My temporary work around appears to be:
     1. Read the buffer memory into a register
     2. Write the register to temporary memory
     3. Read the memory back into same register
     4. Continue with processing.

     
**** Update - values stay reverse stored ****
**** even if a second register is used!  ****
****              Now what?              ****



I have attached my relevant code, as well as
commented debug dumps for further evaluation.

It was my understanding from the documentation
that no data would be presented in a reverse
storage format.

Perhaps I misunderstood the documentation.
Is this the way GoAsm is supposed to work?


Chip




1. How the data is declared.

            DATA Section
               
                Align 16
                Read_Buffer_ERROR       DD  0                      ;Reversed in Register, but not memory! 
                Read_Buffer           DB  65536  Dup 0  ;Buffer Length
                End_Of_Read_Buffer      DD  12121212h       ;End Address of Read_Buffer 



               
2. How the data is read           
           
            Read_Input_File:
               
                INVOKE  ReadFile,                                              \                       
                                    [Input.FileHandle],                          \                      ;handle to file
                                    Addr Read_Buffer,                         \                       ;Where to put the input
                                    [Input.NumberOfBytesToRead],     \                      ;How much to read
                                    Addr Input.NumberOfBytesRead,   \                      ;Amount read (at eof?)
                                    NULL                                                                     ;Overlap not used.
               
                int3 ;DEBUG                                                                               ;Interrup Debugger
           
                Mov eax, addr Read_Buffer                                                         ;CHECK FOR REVERSE STORAGE
                mov ebx, [eax]                                                                           ;REVERSE STORAGE FOUND 
                mov D[Read_Buffer_ERROR], ebx                                              ;Move next to Read_Buffer
                                                                                                                   ;   for comparison
                 

           

3. Register Dump - EBX recieves reverse storage that is unsuitable for processig
       
                       GoBug - copyright Jeremy Gordon 1996-2005
                    Date: Saturday, October 14, 2006 Time: 18:17:45
                                 Dump of register pane
                              whilst debugging Control.exe
   
   
            EDI=75558000h            ESI=00000555h            EBX=01EFCDABh
            EDX=7C90EB94h            ECX=0012FFACh            EAX=00402264h
            EBP=0012FFF0h            EIP=00401273h            ESP=0012FFC4h
             GS=00000000h             FS=0000003Bh             ES=00000023h
             DS=00000023h             CS=0000001Bh             SS=00000023h
                    C=0   P=0   A=0   Z=0   S=0   O=0   D=0   
   
       
       

       
       
4. Data Dump - Register value above does not reflect memory values!
                The correct value in HEX is "ABCDEF01" - Created in a seperate HEX editor.
       
       
                       GoBug - copyright Jeremy Gordon 1996-2005
                    Date: Saturday, October 14, 2006 Time: 18:17:24
                                 Dump of data inspector
                              whilst debugging Control.exe
   
   
        402260: Read_Buffer_ERROR
        AB CD EF 01                                       «Íï.             
       
        402264: Read_Buffer
        402264:
        AB CD EF 01 FF FF FF FF FF FF FF FF FF FF FF FF   «Íï............. 
       
        402274:
        FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF   ................ 
       
I am on Skype under my email address!

sinsi

Intel processors are "little-endian" which means a 32-bit number in memory is stored from low to high, so your value EBX=01EFCDABh
is stored in memory as AB CD EF 01, which the memory dump shows.
Light travels faster than sound, that's why some people seem bright until you hear them.

Chip

Sinsi,

Thank you for the comment.

One of the great things about GoAsm is that Jeremy converts
all of the "indians" to  unscrambled text so that we do not have
too fool with the hardware stroage layouts.

I can only assume that this is some minor bug, or something
that I am doing unwittingly.

Chip
I am on Skype under my email address!

Shantanu Gadgil

Quote...converts all of the "indians" to  unscrambled...
Racial slur!!!  :naughty: :naughty: :naughty:
To ret is human, to jmp divine!

donkey

Hi Chip,

Although GoAsm does reverse the byte order for text declared in source code where necessary, it cannot and does not effect run-time data such as that read from a file. If you have written the bytes sequentially then are reading the bytes into a DWORD they will be reversed by the processor since the low order byte will be leftmost in the DWORD. In order to fix a DWORD that has been reversed you can use the BSWAP instruction, it is made to change the "endian" order.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Chip

Donkey,

Wow!  Your answer through me for a loop - or through a loop!

I had read Jeremy's preference for not reversing storage at
least 4 times after I began encountering a problem.  I seemed
to have missed the keywords "character immediate".  (I had
even looked at the BSWAP instruction, but erroneously
thought it unnecessary in GoASM.)

Still, it does seems problematic in the debugger to show the data
in memory one way, and another way if loaded into a register.

Thanks for clearing this up.  I had spent over six hours debugging
what I originally thought was an incorrect pointer in my program.
Well, at least the BSWAP instruction is fast.

Chip

I am on Skype under my email address!

Chip

Shantanu,

  ...converts all of the "indians" to  unscrambled...

       Racial slur!!!  naughty naughty naughty



"Endians"?  "Indians"?

You don't like my scrambled metaphors?

So! - Sioux Me!

(Hmmm... a bad pun that probably does not translate well.)


Smiling,

Chip
I am on Skype under my email address!