-1

I am trying to read the time from the CMOS using asm but i get this error:

/tmp/ccyx8l5L.s:1236: Error: too many memory references for 'mov'
/tmp/ccyx8l5L.s:1240: Error: too many memory references for 'out'
/tmp/ccyx8l5L.s:1244: Error: too many memory references for 'in'
/tmp/ccyx8l5L.s:1252: Error: too many memory references for 'mov'

and here is the code:

for (index = 0; index < 128; index++) {
    asm("cli");
    asm("mov al, index"); /* Move index address*/
    asm("out 0x70,al"); /* Copy address to CMOS register*/
    /* some kind of real delay here is probably best */
    asm("in al,0x71"); /* Fetch 1 byte to al*/
    asm("sti"); /* Enable interrupts*/
    asm("mov tvalue,al");

    array[index] = tvalue;
}

I am using gcc to compile

Riddhesh Sanghvi
  • 1,218
  • 1
  • 12
  • 22
  • 2
    possible duplicate of [asm in C "too many memory references for \`mov'"](http://stackoverflow.com/questions/15035379/asm-in-c-too-many-memory-references-for-mov) – Gangadhar Oct 10 '15 at 16:40

2 Answers2

2

gcc uses AT&T syntax. Compile with -masm=intel

Janycz
  • 155
  • 9
2

As Janycz points out, your code uses intel syntax for the assembler, while gcc (by default) expects at&t. If you are using gcc, how about something like this:

int main()
{
   unsigned char array[128];

   for (unsigned char index = 0; index < 128; index++) {

      asm("cli\n\t"
         "out %%al,$0x70\n\t"
         /* some kind of real delay here is probably best */
         "in $0x71, %%al\n\t" /* Fetch 1 byte to al*/
         "sti" /* Enable interrupts*/

         : "=a" (array[index]) : "a" (index) );
   }

}

This minimizes the amount of asm you have to write (4 lines vs your 6) and allows the compiler to perform more optimizations. See the docs for gcc's inline asm to understand how all this works.

I haven't tried running this, since it won't run on protected mode operating systems (like Windows). In and Out are protected instructions and can't be used by user-mode applications. I assume you are running this on DOS or something?

David Wohlferd
  • 7,110
  • 2
  • 29
  • 56