extern int sys_read(int,int); extern int sys_request(int,int); extern int sys_write(int,int); extern int vocab_get(int); extern int vocab_set(int,int); extern void push(int); extern int pop(void); extern void rpush(int); extern int rpop(void); extern void rinit(void); static char memseg[1024] = { 0, 0, 0, 9, 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 16, 0, 0, 0, 13, 0, 0, 0, 1 }; static int interpret(int,int); int main(void) { /* int start, here, eax, ebx, esi, mode; here = (int) memseg + 512; mode = here; *(int*) mode = 11; //executing here += 4; //string "interpret" eax = here; *(int*)here++ = 9; *(char*)here++ = 'i'; *(char*)here++ = 'n'; *(char*)here++ = 't'; *(char*)here++ = 'e'; *(char*)here++ = 'r'; *(char*)here++ = 'p'; *(char*)here++ = 'r'; *(char*)here++ = 'e'; *(char*)here++ = 't'; here += 3; //align //initial definition of "interpret" esi = here; *(int*)here++ = 4; //WORD *(int*)here++ = 2; //LIT *(int*)here++ = mode; //addr of mode var *(int*)here++ = 10; //FETCH *(int*)here++ = 12; //EXECUTE *(int*)here++ = 13; //NOOP *(int*)here++ = 1; //RET //insert into vocab vocab_set(eax, esi); //string "quit" ebx = esi; eax = here; *(int*)here++ = 4; *(char*)here++ = 'q'; *(char*)here++ = 'u'; *(char*)here++ = 'i'; *(char*)here++ = 't'; //initial definition of "quit" esi = here; *(int*)here++ = 3; //rinit *(int*)here++ = ebx; //interpret *(int*)here++ = 9; //JMP *(int*)here++ = esi; //jmp addr 0 (interpret) //insert into vocab vocab_set(eax, esi); */ return interpret((int)memseg, (int)memseg); } static int interpret(int esi, int here) { int eax = 0, ebx = 0, ecx = 0, edi = 0; next: eax = *(int*) esi; esi += 4; exec: switch(eax) { case 0: //interpret esi = eax; eax = *(int*)eax; goto next; case 1: // ret (exit) esi = rpop(); goto next; case 2: // pushnext (lit) push(*(int*)esi); esi += 4; goto next; case 3: // rinit rinit(); goto next; case 4: // word esi += eax; eax += esi; goto next; case 5: // sys_read sys_read(pop(),pop()); goto next; case 6: // sys_request sys_request(pop(),pop()); goto next; case 7: // sys_write sys_write(pop(),pop()); goto next; case 8: // bye break; case 9: // goto esi = *(int*) esi; goto next; case 10: // @ fetch push(*(int*)pop()); goto next; case 11: // ! set *(int*)pop() = pop(); goto next; case 12: // EXECUTE eax = pop(); goto exec; case 13: // NOOP push(1); goto next; default: // eax is an addr, jump to it and push esi rpush(esi); esi = eax; goto next; } return 0; }