c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Feature request: inline assembly clobbering

Open fgsoftware1 opened this issue 10 months ago • 7 comments

fgsoftware1 avatar Feb 25 '25 10:02 fgsoftware1

Do you have any suggested syntax?

lerno avatar Feb 25 '25 16:02 lerno

Do you have any suggested syntax?

not at all but here goes some:

uint cr0;

asm
{
   "movl %0, $cr0 "
}(eax);

another thing i though was explicit input/output operands maybe using attributes style?

fgsoftware1 avatar Feb 25 '25 16:02 fgsoftware1

Umm.. did you test the asm syntax yet?

lerno avatar Feb 26 '25 22:02 lerno

Umm.. did you test the asm syntax yet?

i haven't figure out how to do blocks and i think processing asm blocks at the end is a bad idea in some cases like:


u32 cr0;
    asm volatile ("mov %%cr0, %0" : "=r" (cr0));
    cr0 |= 1 << 31;
    asm volatile ("mov %0, %%cr0" : : "r" (cr0)); 

fgsoftware1 avatar Feb 27 '25 14:02 fgsoftware1

Umm.. did you test the asm syntax yet?

i haven't figure out how to do blocks and i think processing asm blocks at the end is a bad idea in some cases like:

u32 cr0; asm volatile ("mov %%cr0, %0" : "=r" (cr0)); cr0 |= 1 << 31; asm volatile ("mov %0, %%cr0" : : "r" (cr0));

this is an example in C

fgsoftware1 avatar Feb 27 '25 14:02 fgsoftware1

The way asm works in C3 is like:

int x;
asm
{
  in $eax, 3;
  in $ax, $dx;
  incb $al;
  incl [&x];
  ...
}

A clobber would perhaps look like

asm
{
  @invalidate($eax);
  @invalidate(mem);
}

lerno avatar Mar 10 '25 10:03 lerno

The way asm works in C3 is like:

int x; asm { in $eax, 3; in $ax, $dx; incb $al; incl [&x]; ... }

A clobber would perhaps look like

asm { @invalidate($eax); @invalidate(mem); }

yeah that looks nice

fgsoftware1 avatar Mar 10 '25 12:03 fgsoftware1