Commit 50ebcb21 authored by zygzagZ's avatar zygzagZ

Minimal POC

parent 1069f66d
......@@ -40,3 +40,12 @@ Info.o : src/Info.cpp src/Info.h src/InfoList.h src/Absyn.h
ParseError.o : src/ParseError.cpp src/Info.h src/InfoList.h src/Absyn.h src/ParseError.h
${CC} ${CCFLAGS} -c src/ParseError.cpp
lib/runtime.o : lib/runtime.c Makefile
gcc -m32 -static -L/usr/lib/gcc-cross/i686-linux-gnu/8/ -c lib/runtime.c -o lib/runtime.o -fno-stack-protector
hello32.o : hello32.s Makefile
as --32 hello32.s -o hello32.o
hello : hello32.o lib/runtime.o Makefile
ld -m elf_i386 -Llib/ -e main lib/runtime.o hello32.o -lc -o hello
hello:
.string "Hello\n"
.globl main
.globl printStr
.globl printInt
.globl readInt
.globl readStr
.globl error
.globl exit
main:
pushl %ebp
movl %esp, %ebp
pushl $hello
call printStr
movl $0, %eax
pushl $0
call exit
hello: .string "Hello\n"
.globl main
main:
pushq %rbp
mov %rsp, %rbp
lea hello(%rip), %rdi
call puts
mov $0, %rax
leave
ret
File added
// gcc -m32 -static -L/usr/lib/gcc-cross/i686-linux-gnu/8/ -c runtime.c -o runtime.o
// as --32 hello32.s -o hello32.o
// ld -m elf_i386 -L. -e main runtime.o hello32.o -lc
#include <stdio.h>
int printInt(int a) {
printf("%d\n", a);
}
int printStr(const char *c) {
printf("%s\n", c);
}
char * readStr() {
char *line = NULL;
size_t len = 0;
getline(&line, &len, stdin);
return line;
}
int readInt () {
char minus = 0;
int result = 0;
char ch;
ch = getchar();
while (1) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus = 1; else result = ch-'0';
while (1) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result*10 + (ch - '0');
}
if (minus)
return -result;
else
return result;
}
Markdown is supported
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