ASM and C

This is a discussion on ASM and C within the C++ Programming forums, part of the General Programming Boards category; I am attempting to mix C++ and Assembly. I have the following code: MIX.C Code: extern void sayhi(void); extern void ...

  1. #1
    stovellp
    Guest

    ASM and C

    I am attempting to mix C++ and Assembly. I have the following code:

    MIX.C
    Code:
    extern void sayhi(void);
    extern void quit(void);
    
    int CurrPos = (int)0xb8f9a;
    char CurrChar = 'H';
    //--------------------------------------------------------------------
    int main(void)
    	{
    	sayhi();
    	quit();
    	}
    MIX.ASM
    Code:
    GLOBAL _sayhi
    GLOBAL _quit
    
    extern _CurrPos
    extern _CurrChar
    SECTION .text
    
    _sayhi:	mov byte [_CurrPos],'H'
    	mov byte [0xb8f9e],_CurrChar
    	ret
    When I try to compile, i get the following error:
    Error: COFF format does not support non-32-bit relocations.

    This is for the line "mov byte [0xb8f9e],_CurrChar".

    Will I have to declare CurrChar as an int so that its 32 Bits?

    Paul

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448

    Maybe...

    I'm not sure this will work but you could try:
    Code:
    asm { //this has to be in the same line
         GLOBAL _sayhi
         GLOBAL _quit //Your asm code
    
         extern _CurrPos
         extern _CurrChar
         SECTION .text
    
         _sayhi: mov byte [_CurrPos],'H'
    	 mov byte [0xb8f9e],_CurrChar
    	 ret
            }
    Note that I've just copy-paste'd your code and don't know any assembly but this is how my book says you write asm in a C++ program.
    Hope this helps
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    try adding:
    Code:
    [BITS 32]
    to the top of the asm file. maybe it'll work, maybe not

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21