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

ragdog

Hi

I have a little question to translate from c++ to asm

xxx_xxx buffer;

xxx_xxx is a structur

qWord

some struct
foo dd ?
some ends

.data
WhatEver some <>
.code
FPU in a trice: SmplMath
It's that simple!

ragdog


ragdog

Hi

I have now a question to this struct
what is Record? and can any tranlate this correct please

CDROM_READ_TOC_EX   struct
CDROM_READ_TOC_EX_R0   RECORD   Format:4,Reserved1:3,Msf:1
   CDROM_READ_TOC_EX_R0 <>
SessionTrack   UCHAR   ?
Reserved2   UCHAR   ?
Reserved3   UCHAR   ?
CDROM_READ_TOC_EX   ends

;typedef struct _CDROM_READ_TOC_EX {
;    UCHAR Format    : 4;
;    UCHAR Reserved1 : 3; // future expansion
;    UCHAR Msf       : 1;
;    UCHAR SessionTrack;
;    UCHAR Reserved2;     // future expansion
;    UCHAR Reserved3;     // future expansion
;} CDROM_READ_TOC_EX, *PCDROM_READ_TOC_EX;

c++ code

  tocex.Format = CDROM_READ_TOC_EX_FORMAT_TOC;
    tocex.Msf = 1;

If this correct?

mov tocex.Format,CDROM_READ_TOC_EX_FORMAT_TOC;
mov tocex.Msf,1

Thanks


redskull

Be aware, MSVC and ML have opposite endians styles for bitrecords.  Define it in MASM in the opposite order as C

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

ragdog

Hi Thanks for you answere

I have look it on this link

I cannot mov in this structur why?

Here is my result


.data

tocex CDROM_READ_TOC_EX <>

.code

       lea edi,tocex
        assume edi: ptr CDROM_READ_TOC_EX
       
          mov  [edi].CDROM_READ_TOC_EX_R0.Format,CDROM_READ_TOC_EX_FORMAT_TOC
          mov  [edi].CDROM_READ_TOC_EX_R0.Mfs,1
          ;tocex.Format = CDROM_READ_TOC_EX_FORMAT_TOC;
          ;tocex.Msf = 1;
        assume edi: NOTHING

redskull

MOV works on bytes only (and words and dwords), nothing smaller (it's helpful to think of the structure name resolving down to just a single address).  You either AND with a 0 to clear a bit, or OR with a 1 to set a bit.  MASM has keyworks to automatically create said bitmasks, using MASK.  Check the programmers guide

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

dedndave

you have already told it that EDI is a structure pointer
try this

        assume edi: ptr CDROM_READ_TOC_EX
       
          mov  [edi].Format,CDROM_READ_TOC_EX_FORMAT_TOC ;not sure - this must be an equate ?
          mov  [edi].Mfs,1

ragdog

@dedndave

I have already try it this give me the same result

error A2006: undefined symbol
error A2006: undefined symbol : Mfs

@RedSkull
How i can make this?
(it's helpful to think of the structure name resolving down to just a single address)

jj2007

#10
Full example attached.
.code
start:
SetField tocex.CDROM_READ_TOC_EX.Format, CDROM_READ_TOC_EX_FORMAT_TOC
SetField tocex.CDROM_READ_TOC_EX.Msf, 1


EDIT: More size-efficient version of SetField added (v2).

ragdog

Ahh this mean you  :wink

Thanks it works

Why if this in c++ a little line in masm a little mor code  :bg

ragdog

I have this Dissasembled

this macro make this

.text:004010DE                 lea     edi, dword_403000
.text:004010E4                 mov     eax, 0
.text:004010E9                 shl     eax, 4
.text:004010EC                 or      dword_403000, eax
.text:004010F2                 mov     eax, 1
.text:004010F7                 or      dword_403000, eax

This dword_403000 if CDROM_READ_TOC_EX?
0 =CDROM_READ_TOC_EX_FORMAT_TOC
1 = Msf
4 =Format


               lea     edi, tocex
                mov     eax, 0
                 shl     eax, 4
                 or      tocex, eax
                 mov     eax, 1
                 or    tocex, eax
if this crorrect?

dedndave

i see a possible typo
is it Mfs or Msf ?

Quoteerror A2006: undefined symbol : Mfs
Quote
          mov  [edi].Msf,1

ragdog

Is Msf!

Thanks i have i solved it with the bitfield macro

Now is my question to the dissasembled snipped in my last post