Skip to content
Snippets Groups Projects
Commit afc9e8f0 authored by Rui Ueyama's avatar Rui Ueyama
Browse files

Add + and - operators

parent f722daaa
Branches
No related merge requests found
......@@ -7,10 +7,30 @@ int main(int argc, char **argv) {
return 1;
}
char *p = argv[1];
printf(".intel_syntax noprefix\n");
printf(".global main\n");
printf("main:\n");
printf(" mov rax, %d\n", atoi(argv[1]));
printf(" mov rax, %ld\n", strtol(p, &p, 10));
while (*p) {
if (*p == '+') {
p++;
printf(" add rax, %ld\n", strtol(p, &p, 10));
continue;
}
if (*p == '-') {
p++;
printf(" sub rax, %ld\n", strtol(p, &p, 10));
continue;
}
fprintf(stderr, "unexpected character: '%c'\n", *p);
return 1;
}
printf(" ret\n");
return 0;
}
......@@ -18,5 +18,6 @@ assert() {
assert 0 0
assert 42 42
assert 21 '5+20-4'
echo OK
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment