Last active
September 10, 2022 09:14
-
-
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までの総和を計算する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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