Skip to content

Instantly share code, notes, and snippets.

@takeisa
Last active September 10, 2022 09:14
Show Gist options
  • Save takeisa/e71588207dcf6b522433c66c530eb61f to your computer and use it in GitHub Desktop.
Save takeisa/e71588207dcf6b522433c66c530eb61f to your computer and use it in GitHub Desktop.
Example using GCC's inline assembler. Compute the sum of 1 to 10. GCCのインラインアセンブラを使った例。1から10までの総和を計算する。
#include <stdio.h>
// Example using GCC's inline assembler.
// Compute the sum of 1 to 10.
// GCCのインラインアセンブラを使った例。
// 1から10までの総和を計算する。
// use compiler option -masm=intel
int main(void) {
int sum;
asm volatile(
".intel_syntax noprefix\n\t"
" mov eax, 0\n\t"
" mov ebx, 1\n\t"
"LOOP1: add eax, ebx\n\t"
" inc ebx\n\t"
" cmp ebx, 11\n\t"
" jne LOOP1\n\t"
: "=a"(sum));
printf("sum=%d", sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment