0

I am trying to write inline assembly in a C file and I get 2 errors :

open.c:10: Error: junkptr nombre' after expression`

open.c:10: Error: suffix or operands invalid forles'`

This is my file :

int open(char * nombre, unsigned char modo)
{
  int retval;
  int nrllamada = 6;
  asm("mov $8,%%ah \n\t"
      "les %%bx, dword ptr nombre \n\t"
      "int $0x22 \n\t"
      "mov %%eax,%0 \n\t"
      : "=r"(retval)
      : "a"(modo)
  );
  return retval;
}

3 Answers 3

1
"les %%bx, dword ptr nombre \n\t"

You have ptr nombre inside a string. That is probably not correct. surely you want to reference the char* nombre in the arguments to the function?

Sign up to request clarification or add additional context in comments.

Comments

0

The correct way to write in registers ES and BX the 32 bits pointer named nombre is to connect the C variable nombre to register ECX, move the lower 16 bits of ECX to register BX, rotate the ECX register 16 bits so the lower 16 bits goes to the higher 16 bits of the same register and vice versa and finally move the lower 16 bits of ECX to ES.

int open(char * nombre, unsigned char modo)
{
  int retval;
  // numero servicio 6
  // nombre del fichero a abrir (ES:BX) y modo (AL) de apertura
  asm("mov $6,%%ah \n\t"
      "mov %%cx,%%bx \n\t"
      "rol $16,%%ecx \n\t"
      "mov %%cx,%%es \n\t"
      "int $0x22 \n\t"
      "mov %%eax,%0 \n\t"
      : "=r"(retval)
      : "a"(modo), "c"(nombre)
  );
  return retval;       
}

Comments

0

GCC is 32-bit compiler. This means also, that you should most likely to try to get rid of the es:bx type pointer arithmetic and move to flat 32-bit addressing (where base of cs=ds=es=0 and each segment limit is 0xffffffff).

Accessing status registers in user space of protected mode gives very likely an access violation exception.

Also, what is the OS, where int 22h is allowed and where it expects es:bx input? In MS-DOS it shouldn't be called, as it's just used as a static variable to restore other interrupt vectors.

1 Comment

It is for a small kernel of tiny OS called OSO i am writing and that uses old techs like the fat12 file system and 16bits CPU architecture. The int22h is made to my kernel, i already have an interruption routine for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.