C++ to Asm 
Author Message
 C++ to Asm


>From an Asm point of view, what do the C++ keywords "new" and "delete" do??


Fri, 23 Mar 2001 03:00:00 GMT  
 C++ to Asm
it's been long since i've disassembled c++ code, and different compilers
do it differently, but it usually looks something like this(16 bit code
and stack parameter passing):

        CMyClass *myClassPtr = new CMyClass(5);  // pass a 5 to the constructor
of the class

asm would look something like this:

        mov     ax,20h  ; lets say the size of our class is 20h bytes
        push    ax      ; push it on stack
        call    malloc  ; return pointer to allocated memory in AX
        mov     [myClassPtr],ax
        or      ax,ax   ; check to see if mem alloc successfull
        jz      bad_alloc

        mov     ax,5
        push    ax      ; ax = 5, which is the value to send to the constructor
        mov     ax,[myClassPtr] ; ax = pointer to new class object
        push    ax      ; give address of object to constructor
        call    CMyClass        ; call the contructor of the object


        delete myClassPtr;

        mov     ax,[myClassPtr]         ; ax = pointer to class object
        or      ax,ax                   ; test if it's valid
        jz      not_valid

        push    ax              ; send address of object to destructor
        call    ~CMyClass       ; call descturcor

        push    ax              ; send address of object to free()
        call    free            ; free the memory


hope this helps.  Oh, some compilers may not provide all of the error
checking here, but mine does, so that's why I wrote it.


Fri, 23 Mar 2001 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Passing arguments from C++ to ASM with Borland C++

2. C++ to asm

3. converting C++ to ASM

4. Please I would appreciate some input, Far pointer from C++ to asm

5. C++ And ASM

6. C/C++ to ASM

7. getting global variable from c++ in asm (MASM)

8. C++ to asm

9. Hmm C++ or Asm??

10. C++ and ASM

11. linking C++ and asm objects

12. C++ to Asm


Powered by phpBB® Forum Software