Thread: C and ASM probelm

  1. #1
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215

    C and ASM probelm

    hi, unsure if this is the right part to post this sorry if it is.

    i was wondering if anyone could figure out what the error means when i try to run it, when i compile it says there is no errors but then when i try to run the program it comes up with serveral errors.

    Here is the code

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    
    #ifndef Q4_CPP
    #define Q4_CPP
    
    // Function defs
    #define DOS_INT       int 21h
    #define VIDEO_INT     int 10h
    #define KEYBOARD_INT  int 16h
    
    // Sub function defs
    #define GET_DATE          2Ah
    #define GET_VID_STATE     0Fh
    #define SCROLL_UP         06h
    #define GET_TIME          2Ch
    #define CURSOR_TO         02h
    #define GET_CURSOR        03h
    #define SET_CURSOR_SHAPE  01h
    #define CHECK_KEYBOARD    11h
    
    #define SCREEN_HEIGHT  25
    #define SCREEN_WIDTH   80
    #define BLUE           1
    #define BLACK          0
    #define GREEN          4
    #define MSG_ROWS       4
    #define MSG_WIDTH      24
    #define WIN_TOP        (SCREEN_HEIGHT-MSG_ROWS) / 2
    #define WIN_LEFT       (SCREEN_WIDTH-MSG_WIDTH) /2
    #define WIN_HEIGHT     MSG_ROWS
    #define WIN_WIDTH      MSG_WIDTH
    
    typedef unsigned char BYTE;
    typedef unsigned int  WORD;
    
    void GetSystemDate(WORD *Year, BYTE *Month, BYTE *Day);
    void GetSystemTime(BYTE *Hour, BYTE *Min, BYTE *Sec);
    void DrawWindow(BYTE Left,BYTE Top,BYTE Right,BYTE Bottom, BYTE Attrib);
    void GotoXY(BYTE x, BYTE y);
    void CursorOff();
    void CursorOn();
    WORD KeyPressed();
    
    // Globals
    // Hold cursor scan lines to restore later. Could have returned from
    // Cursor off but prefer simple call line for this function.
    BYTE ScanStart,ScanEnd;
    
    #endif
    
    void main()
    
    {
    
      BYTE Month,Day,Hour,Min,Sec,PrevSec;
    
      WORD Year; 
    
    
      DrawWindow(0,0,SCREEN_WIDTH-1,SCREEN_HEIGHT-1,BLUE << 4);
    
      DrawWindow(WIN_LEFT,WIN_TOP,WIN_LEFT+WIN_WIDTH,WIN_TOP+WIN_HEIGHT,BLACK);
    
      DrawWindow(WIN_LEFT-1,WIN_TOP-1,WIN_LEFT+WIN_WIDTH-1,WIN_TOP+WIN_HEIGHT-1,GREEN <<4);
    
      textbackground(GREEN);
    
      textcolor(BLACK);
    
      GotoXY(WIN_LEFT+3,WIN_TOP); 
    
    
      GetSystemDate(&Year,&Month,&Day);
    
      cprintf("Date is %02d/%02d/%02d",Day,Month,Year); 
    
    
      GetSystemTime(&Hour,&Min,&Sec); 
    
    
    
      {
    
        GetSystemTime(&Hour,&Min,&Sec); 
    
    
        if (PrevSec != Sec)   // Only update every second to avoid flashing
    
        {
    
          GotoXY(WIN_LEFT+4,WIN_TOP+2);
    
          cprintf("Time is %02d:%02d:%02d",Hour,Min,Sec);
    
          PrevSec=Sec;
    
        }
    
      } // end while 
    
    
      // Restore defaults
    
    
      textbackground(BLACK);
    
      textcolor(WHITE);
    
      clrscr();
    
    } 
    
    void GetSystemTime(BYTE *Hour, BYTE *Min, BYTE *Sec)
    
    {
    
    asm {XOR AX,AX 
        MOV AH, GET_TIME
        DOS_INT 
        MOV BX, Hour //GET ADDRESS
        MOV BYTE ptr [BX], CH //COPY HOUR 
        MOV BX, Min
        MOV BYTE ptr [BX], CL
        MOV BX, Sec
        MOV BYTE ptr [BX], DH
        }
    
    }
    the errors is get are.

    1. undefined symbol _GotoXY in module
    2. undefined symbol _GetSystemDate in module
    3. undefined symbol _DrawWindow in module

    can anyone help and how to fix them?

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    1. int main
    2. You declare GotoXY, etc, but never define them.
    PS, do you have a ASM fixation? Assembly is painful unless you need to use. And its especially ugly in C.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    what do you mean "ASM fixation"?

    and does it really matter if it is int main() or void main()?
    Last edited by peckitt99; 11-01-2006 at 06:29 PM.

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Most of the post I've looked at of your's are about inline assembly in C. And yes, it does matter.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >and does it really matter if it is int main() or void main()?
    Yes it does. Read the FAQ:
    What's the difference between... > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])

    And there's also a gotoxy function contained in the FAQ. You might want to grab that.

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Is it a DOS program? If not, you can't use interrupts.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  7. #7
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    yeah it is a DOS program, should diplay a working clock.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Which compiler are you using?
    And which OS?

    VC6 / XP for instance is NOT a valid combination.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    the compiler is turbo C i think but unsure we got it downloaded from uni.
    the OS is just windows.

Popular pages Recent additions subscribe to a feed