Autor Tema: No entiendo esa linea en assembler...  (Leído 2623 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Patoso

  • Visitante
No entiendo esa linea en assembler...
« en: 29 de Diciembre de 2009, 15:27:16 »
Buenas tardes foreros!

Buscando por este foro encontré:
--------------------------------------------

/* *********************************************************************  */  
  unsigned  int  EepromRead(unsigned int Addr )
 /* *********************************************************************  */
   {  

    Addr = EEPROM_0 + ( Addr * 2 );
    asm( " mov %0,w0 " :  : "g" (Addr)  : "w0" );   // Addr HL

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


La última línea, ¿alguien puede explicarme qué hace? es la primera vez que veo una línea así  :shock:

La parte de asm lo entiendo y lo mismo el mov pero ¿todo eso de los dos puntos? ¿qué es?

Muchas gracias.

Un saludo.  :-/

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re: No entiendo esa linea en assembler...
« Respuesta #1 en: 29 de Diciembre de 2009, 15:42:14 »
¿Eso es C, verdad?, ¿para qué compilador está escrito?
Sospecho que esa sintaxis es propia del compilador.

Patoso

  • Visitante
Re: No entiendo esa linea en assembler...
« Respuesta #2 en: 29 de Diciembre de 2009, 16:17:21 »

es C30, pero hace un "asm" que es assembler, ¿no?

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re: No entiendo esa linea en assembler...
« Respuesta #3 en: 29 de Diciembre de 2009, 16:25:29 »
Sí, es ASM embebido dentro de un programa en C30.

Mira lo que dice el manual:
8.4 USING INLINE ASSEMBLY LANGUAGE
Within a C function, the asm statement may be used to insert a line of assembly
language code into the assembly language that the compiler generates. In-line
assembly has two forms: simple and extended.
In the simple form, the assembler instruction is written using the syntax:
asm ("instruction");
where instruction is a valid assembly-language construct. If you are writing inline
assembly in ANSI C programs, write __asm__ instead of asm.
In an extended assembler instruction using asm, the operands of the instruction are
specified using C expressions. The extended syntax is:
Código: ASM
  1. asm("template" [ : [ "constraint"(output-operand) [ , ... ] ]
  2. [ : [ "constraint"(input-operand) [ , ... ] ]
  3. [ "clobber" [ , ... ] ]
  4. ]
  5. ]);
You must specify an assembler instruction template, plus an operand constraint
string for each operand. The template specifies the instruction mnemonic, and
optionally placeholders for the operands. The constraint strings specify operand
constraints, for example, that an operand must be in a register (the usual case), or that
an operand must be an immediate value.
For example, here is how to use the dsPIC device’s swap instruction (which the
compiler does not generally use):
Código: ASM
  1. asm ("swap %0" : "+r"(var));

Here var is the C expression for the operand, which is both an input and an output
operand. The operand is constrained to be of type r, which denotes a register operand.
The + in +r indicates that the operand is both an input and output operand.

Patoso

  • Visitante
Re: No entiendo esa linea en assembler...
« Respuesta #4 en: 29 de Diciembre de 2009, 17:09:00 »
genial!  muy útil!

muchas gracias! ¿de dónde te sacaste ese texto?


Patoso

  • Visitante
Re: No entiendo esa linea en assembler...
« Respuesta #6 en: 30 de Diciembre de 2009, 14:29:36 »
Ya estuve mirando :D

Sólo decir que era el capítulo 9.4 y no el 8.4, por si alguien quiere echarle un vistazo.

Un saludo  :-/

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re: No entiendo esa linea en assembler...
« Respuesta #7 en: 30 de Diciembre de 2009, 14:38:22 »
Sí, porque el documento ya va por la revisión H y el que yo tenía en mi disco duro es la revisión B, cuando los dsPIC sólo eran 30F, y no existían ni los 24F, ni los 24H ni los 33F.