News:

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

C++ to asm question

Started by ragdog, February 28, 2010, 05:11:06 PM

Previous topic - Next topic

jj2007

Yes, the disassembly is correct. Here is a variant:

start: mov edi, offset tocex
nop
SetField [edi.CDROM_READ_TOC_EX].Format, CDROM_READ_TOC_EX_FORMAT_TOC
nop
SetField tocex.CDROM_READ_TOC_EX.Msf, 1
nop
print str$(GetField(tocex.CDROM_READ_TOC_EX.Format, CDROM_READ_TOC_EX_FORMAT_TOC)), 9, "Format", 13, 10
print str$(GetField(tocex.CDROM_READ_TOC_EX.Msf, CDROM_READ_TOC_EX_FORMAT_TOC)), 9, "Msf", 13, 10
getkey
exit


If you have several fields to load, [edi.CD....] is slightly shorter. The code above disassembles as follows:
<ModuleEntryPo>/$  BF 00204000              mov edi, 00402000
00401005       |.  90                       nop
00401006       |.  B8 00000000              mov eax, 0
0040100B       |.  C1E0 04                  shl eax, 4
0040100E       |.  0907                     or [edi], eax
00401010       |.  90                       nop
00401011       |.  B8 01000000              mov eax, 1
00401016       |.  0905 00204000            or [402000], eax
0040101C       |.  90                       nop


The forceAnd parameter is needed if the field has already a value different from zero, and you want to overwrite it.

ragdog

#16
Ahh ok this  is fine i have add this dissasembled code

I have this c++ code dissasembled and now have i the next problem
  pTrack = (PTRACK_DATA)(&toc.TrackData[0]);

00405473  |>   LEA EAX,DWORD PTR SS:[EBP-338]     
00405479  |.    ADD EAX,4                         
0040547C  |.    MOV DWORD PTR SS:[EBP-340],EAX   

xyz proc
LOCAL pTrack:PTRACK_DATA       ;    PTRACK_DATA  pTrack;

;pTrack = (PTRACK_DATA)(&toc.TrackData[0]);
lea     eax,pTrack
add     eax,4 ;toc.TrackData
mov     pTrack, eax


Is This Correct?



ragdog

Hi

I need help Once again

memset(&Xptr, 0, sizeof(Xptr));   << fill this the struct with zeros same as zeromemory?

And can any translate this please

  const int i_header_size = __MAX( 4, MINIMUM_SIZE );
   uint8_t header[i_header_size];

  const int i_text = 2 + (header[0] << 8) + header[1];

    /*-------------- */
    uint8_t *p_text = calloc( 1, i_text );

Thanks

qWord

Quote from: ragdog on March 04, 2010, 08:30:21 PMmemset(&Xptr, 0, sizeof(Xptr)); << fill this the struct with zeros same as zeromemory?
yes.

_MAX macro a,b
IF a GE b
EXITM <&a>
ELSE
EXITM <&b>
ENDIF
endm

MINIMUM_SIZE EQU ???
.const
; may not needed/used ?
;const int i_header_size = __MAX( 4, MINIMUM_SIZE );
i_header_size SDWORD _MAX(4,MINIMUM_SIZE)

;const int i_text = 2 + (header[0] << 8) + header[1];
; fill at runtime
i_text SDWORD ?
.data?
;uint8_t header[i_header_size];
header db _MAX(4,MINIMUM_SIZE) dup (?)
align 4
p_text dd ?
.code
...
; header[0,1] must be filled
...

;const int i_text = 2 + (header[0] << 8) + header[1];
movzx eax,header[0]
movzx ecx,header[1]
shl eax,8
lea eax,[eax+ecx+2]
mov i_text ,eax

;uint8_t *p_text = calloc( 1, i_text );
mov p_text,alloc(eax)
FPU in a trice: SmplMath
It's that simple!

ragdog

Hi thanks

If i add this to my code crash this

movzx eax,header[0]
movzx ecx,header[1]
shl eax,8
lea eax,[eax+ecx+2]
mov i_text ,eax

qWord

ups... :red, you must declare i_text in .data section, not in .const
FPU in a trice: SmplMath
It's that simple!