Created
June 3, 2020 09:27
-
-
Save jellyfish26/4d5e09ae2f29132c521f9b4934e89b50 to your computer and use it in GitHub Desktop.
The leap year determination is written by inline assembler.
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> | |
int main (int argc, char **argv) { | |
int year = 0, check = 0; | |
scanf("%d", &year); | |
char ok[] = "leap", ng[] = "not leap"; | |
__asm__ volatile("mov %%rcx, %%rax;\n\t" | |
"mov $400, %%rbx;\n\t" | |
"idiv %%rbx;\n\t" | |
"cmp $0, %%rdx\n\t" | |
"jz ok\n\t" | |
"mov %%rcx, %%rax;\n\t" | |
"mov $100, %%rbx;\n\t" | |
"mov $0, %%rdx;\n\t" | |
"idiv %%rbx;\n\t" | |
"cmp $0, %%rdx\n\t" | |
"jz ng\n\t" | |
"mov %%rcx, %%rax;\n\t" | |
"mov $4, %%rbx;\n\t" | |
"mov $0, %%rdx;\n\t" | |
"idiv %%rbx;\n\t" | |
"cmp $0, %%rdx\n\t" | |
"jz ok\n\t" | |
"jmp ng\n\t" | |
"ok:\n\t" | |
"mov $1, %%rcx\n\t" | |
"jmp exit\n\t" | |
"ng:\n\t" | |
"mov $0, %%rcx\n\t" | |
"jmp exit\n\t" | |
"exit:\n\t" | |
: "=c"(check) | |
: "c" (year) | |
: "%rax", "%rbx", "%rdx" | |
); | |
printf("%s\n", (check ? ok : ng)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment