Thread: C++ w/ Assembly

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    7

    Post C++ w/ Assembly

    hello, im having problems with Turbo C++ 3.0, this is whats going down, I compile the C++ source code to get its .obj file, then I compile my assembly source w/ TASM, to get its .obj then I use TC++'s linker to link them together but it says undefined symbol gotoxy(int,int) anyway, these are my sources, thank you for your help.

    ----------------------------------------------------------------------------------
    ;*************************
    ; module: modwc.asm
    ;
    ;*************************
    CODESG SEGMENT PARA

    _gotoxy PROC FAR
    PUBLIC _gotoxy
    ASSUME CS:CODESG
    PUSH BP
    PUSH AX
    PUSH DX

    MOV BP,SP
    MOV DX,[BP + 6]
    MOV CX,04
    SHL DX,CL ; move the y value to DH
    MOV AX,[BP + 8]
    XCHG DL,AL ; move the x value to DL
    MOV AH,02 ; SET CURSOR POSITION FUNCTION
    MOV BH,00 ; PAGE #
    INT 10h

    POP DX
    POP AX
    POP BP
    RET 4 ; pop 4 bytes off stack, (2 bytes for x, 2 bytes for y)
    _gotoxy ENDP

    CODESG ENDS

    end _gotoxy

    ------------------------------------------------------------------------------
    // module: modwasm.cpp

    extern void gotoxy(int,int);

    void main()
    {
    gotoxy(20,5);
    }

    --------------------------------------------------------------------------------

    thank you for your help.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    7

    Post

    tried that, still is being poopy. thanks for help.

  3. #3
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    What exactly does gotoxy() do? If it simply moves the hardware cursor, then just use port I/O in C/C++.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    7

    Post

    well the reason why I wouldn't use that is, I want it exactly as I have it, I dont' want to call any functions other than gotoxy, and I need to figure out how to make this work.

  5. #5
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    Well, this function uses no external functions to move the hardware cursor. It's made for DJGPP, yet I haven't tested it in DOS.

    Code:
    signed short int Put_Cursor(unsigned short int col, unsigned short int row)
    {
    	unsigned short int offset;
    
    	// If coordinates are legit, move that sucker.
    	if((col < 81) && (col > 0) && (row < 26) && (row > 0))
    	{
    		// Calculate offset.
    		offset = (row - 1) * 80 + (col - 1);
    
    		// Move it.
    		asm volatile ("outb %%al,%%dx": :"d" 0x3D4, "a" 0x0F);
    		asm volatile ("outb %%al,%%dx": :"d" 0x3D5, "a" ((unsigned char)(offset & 0xFF)));
    		asm volatile ("outb %%al,%%dx": :"d" 0x3D4, "a" 0x0E);
    		asm volatile ("outb %%al,%%dx": :"d" 0x3D5, "a" ((unsigned char)((offset >> 8) & 0xFF)));
    
    		return 0;
    	}
    
    	return -1;
    }

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    7

    Post

    well thank you for your help, but thats not what im looking for, i don't want to use an inline assembler, I just want to be able to link the two .obj's together so I can call the assembly procedure from the C++ source code. thanks for your help thou.

  7. #7
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    Sorry I couldn't help. Check your compiler and linker documentation. I'm sure the answer is there.

  8. #8
    Registered User
    Join Date
    Nov 2001
    Posts
    3
    Hi,

    KnightMareMan

    What about this statement?
    Code:
    CODESG SEGMENT PARA 
    
    PUBLIC gotoxy 
    
    gotoxy PROC FAR

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    7
    Well It just doesn't want to work, I will keep trying though, thank you all for the help.

    ~The Knight Mare Man

  10. #10
    Unregistered
    Guest
    Greetings,

    Try this:

    // module: modwasm.cpp

    extern "C" void gotoxy(int,int);

    void main()
    {
    gotoxy(20,5);
    }

  11. #11
    Registered User
    Join Date
    Aug 2001
    Posts
    7

    Post Still un-working

    Tried, and its still not working. Thanks anyway.

  12. #12
    Would that code actually work? I never knew you could use ASM and C++ and link them together...Interesting...
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learning Assembly
    By mrafcho001 in forum Tech Board
    Replies: 5
    Last Post: 03-12-2006, 05:00 PM
  2. C to assembly interface
    By Roaring_Tiger in forum C Programming
    Replies: 4
    Last Post: 02-04-2005, 03:51 PM
  3. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 01:11 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM