Example testing file and system + return fasm implementation...
This commit is contained in:
parent
3d60a10e63
commit
70cc687d65
9
heyo.x
Normal file
9
heyo.x
Normal file
@ -0,0 +1,9 @@
|
||||
type integer = 4;
|
||||
type character = 1;
|
||||
|
||||
main ():
|
||||
system (1, 1, #text, size);
|
||||
return;;
|
||||
|
||||
text: character [] = "Heyo world!";
|
||||
size: integer = 12;
|
40
xiranda.c
40
xiranda.c
@ -42,6 +42,18 @@ static char * word_list [] = {
|
||||
"type", "loop", "if", "else", "case", "return", "import", "system"
|
||||
};
|
||||
|
||||
static char * register_list [] = {
|
||||
"rax","rdi","rsi","rdx","r10","r8","r9"
|
||||
/*"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
|
||||
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
|
||||
"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
|
||||
"r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d",
|
||||
"ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
|
||||
"r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w",
|
||||
"al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
|
||||
"r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"*/
|
||||
};
|
||||
|
||||
static void add_coin (int type, int data, char * text) {
|
||||
coin_enum [coin_code] = type;
|
||||
coin_data [coin_code] = data;
|
||||
@ -155,14 +167,42 @@ int main (void) {
|
||||
|
||||
printf ("\n");
|
||||
|
||||
printf ("format ELF64 executable 3\n\n");
|
||||
printf ("segment readable executable\n\n");
|
||||
|
||||
for (length = 0; length < coin_code; ++length) {
|
||||
if ((coin_enum [length] == coin_return) && (coin_enum [length + 1] == coin_stop)) {
|
||||
printf ("; return;\nxor rax, rax\nret\n\n");
|
||||
length += 1;
|
||||
} else if ((coin_enum [length] == coin_return) && (coin_enum [length + 1] == coin_number) && (coin_enum [length + 2] == coin_stop)) {
|
||||
printf ("; return {number};\nmov rax, %s\nret\n\n", coin_text [length + 1]);
|
||||
length += 2;
|
||||
} else if ((coin_enum [length] == coin_system) && (coin_enum [length + 1] == coin_open)) {
|
||||
int use = 0;
|
||||
/*int fit = 0;*/
|
||||
printf ("; system ({...});\n");
|
||||
length += 2;
|
||||
while (coin_enum [length] != coin_close) {
|
||||
switch (coin_enum [length]) {
|
||||
case coin_machine: length += 1; printf ("mov %s, %s\n", register_list [use], coin_text [length]); use++; break;
|
||||
case coin_number: printf ("mov %s, %s\n", register_list [use], coin_text [length]); use++; break;
|
||||
case coin_marker: printf ("mov %s, [%s]\n", register_list [use], coin_text [length]); use++; break;
|
||||
default: break;
|
||||
}
|
||||
length += 1;
|
||||
if (coin_enum [length] == coin_next)
|
||||
length += 1;
|
||||
}
|
||||
if (coin_enum [length] == coin_close)
|
||||
length += 1;
|
||||
if (coin_enum [length] != coin_stop)
|
||||
echo ("EXPECTED STOP ';'\n");
|
||||
printf ("syscall\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf ("segment readable writable\n\n");
|
||||
|
||||
buffer = deallocate (buffer);
|
||||
|
||||
return (log_success);
|
||||
|
Loading…
Reference in New Issue
Block a user