-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab74829
commit 06ef9c6
Showing
7 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
int sum(int n){ | ||
int fun(int n){ | ||
if(n == 0) return n; | ||
return sum(n-1) + n; | ||
return fun(n-1) + n; | ||
} | ||
|
||
int main(){ | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
cp tex_build/15_A5.pdf . | ||
tar -c 15_A5_translator.c 15_A5_translator.h compiler.c compiler.h 15_A5.l 15_A5.nc 15_A5.y Makefile 15_A5.pdf 15_A5_quads* -f 15_A5.tar | ||
tar -c 15_A5_translator.c 15_A5_translator.h compiler.c compiler.h 15_A5.l 15_A5.nc 15_A5.y Makefile 15_A5.pdf 15_A5_quads* inputlib.asm -f 15_A5.tar | ||
rm 15_A5.pdf |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.data | ||
STRING1: | ||
.string "Hello, world!\n" | ||
.text | ||
.globl _main | ||
.globl printStr | ||
|
||
_main: | ||
# write string1 to stdout | ||
pushl $STRING1 | ||
call printStr | ||
addl $4, %esp | ||
|
||
# exit w code 0 | ||
xorl %edi, %edi | ||
movl $0x3c, %eax | ||
syscall | ||
|
||
printStr: | ||
# prologue, no callee-saved registers | ||
pushl %ebp | ||
movl %esp, %ebp | ||
|
||
# let's get the (32-bit) pointer out of the stack | ||
movl 8(%ebp), %ecx | ||
# edx will calc strlen | ||
xorl %edx, %edx | ||
_lenloop: | ||
cmpb $0, (%ecx, %edx, 1) | ||
je _lenloop_end | ||
incl %edx | ||
jmp _lenloop | ||
_lenloop_end: | ||
# edx now contains strlen | ||
# need to write to stdout, fd = 1 | ||
movl $1, %ebx | ||
# syscall number for write is 4 on 32-bit | ||
movl $4, %eax | ||
|
||
int $4 | ||
# eax contains return value from write, no. of written characters | ||
# our calling convention dictates eax as the return value, so all | ||
# done | ||
|
||
# epilogue | ||
movl %esp, %ebp | ||
popl %ebp | ||
ret |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include <stdio.h> | ||
|
||
extern int yylex(); | ||
int y = 10; | ||
|
||
int main() { | ||
int c; | ||
|