[ create a new paste ] login | about

Link: http://codepad.org/xZjkIm7R    [ raw code | output | fork ]

C, pasted on Jul 7:
#include <stdio.h>
//Cの式をオペランドとして持つアセンブラ命令
int main(void)
{
    int x   =   100;
    int y   =   500;
    int result;
    asm("nop");
//#割り当て場所はメモリでもレジスタでも構わない設定
    asm("movl  %0,  %%eax" :: "g"(x): "ax");
    asm("movl  %0,  %%ebx" :: "g"(y): "bx");
    asm("addl  %%ebx, %%eax" ::: "ax","bx");
    asm("movl  %%eax, %0"  : "=g"(result) :: "ax");
    asm("nop");
//割り当て場所はレジスタである
    asm("movl  %0,  %%eax" :: "r"(x): "ax");
    asm("movl  %0,  %%ebx" :: "r"(y): "bx");
    asm("addl  %%ebx, %%eax" ::: "ax","bx");
    asm("movl  %%eax, %0"  : "=r"(result) :: "ax");
    asm("nop");
//割り当て場所はメモリである
    asm("movl  %0,  %%eax" :: "m"(x): "ax");
    asm("movl  %0,  %%ebx" :: "m"(y): "bx");
    asm("addl  %%ebx, %%eax" ::: "ax","bx");
    asm("movl  %%eax, %0"  : "=m"(result) :: "ax");
    asm("nop");
//割り当て場所はEAX, EBX, ECX, EDXレジスタのいずれか
    asm("movl  %0,  %%eax" :: "q"(x): "ax");
    asm("movl  %0,  %%ebx" :: "q"(y): "bx");
    asm("addl  %%ebx, %%eax" ::: "ax","bx");
    asm("movl  %%eax, %0"  : "=q"(result) :: "ax");
    asm("nop");
//
    asm("movl  %0,  %%eax" :: "D"(x): "ax");        //EDIレジスタに割り当て指定
    asm("movl  %0,  %%ebx" :: "S"(y): "bx");        //ESIレジスタに割り当て指定
    asm("addl  %%ebx, %%eax" ::: "ax","bx");
    asm("movl  %%eax, %0"  : "=c"(result) :: "ax"); //ECXレジスタに割り当て指定
    asm("nop");
    printf("%d\n",result);
    return 0;
  }


Output:
1
600


Create a new paste based on this one


Comments: