Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Chibicc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
邓家琪
Chibicc
Commits
afc9e8f0
Commit
afc9e8f0
authored
5 years ago
by
Rui Ueyama
Browse files
Options
Downloads
Patches
Plain Diff
Add + and - operators
parent
f722daaa
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.c
+21
-1
21 additions, 1 deletion
main.c
test.sh
+1
-0
1 addition, 0 deletions
test.sh
with
22 additions
and
1 deletion
main.c
+
21
−
1
View file @
afc9e8f0
...
...
@@ -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
;
}
This diff is collapsed.
Click to expand it.
test.sh
+
1
−
0
View file @
afc9e8f0
...
...
@@ -18,5 +18,6 @@ assert() {
assert 0 0
assert 42 42
assert 21
'5+20-4'
echo
OK
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment