Created
January 4, 2016 05:15
-
-
Save nitrix/d921de1767bf8fd933a7 to your computer and use it in GitHub Desktop.
little_bit's compiler
This file contains hidden or 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
| .global main | |
| .global printf | |
| .text | |
| main: | |
| mov %rsp, base | |
| jmp next | |
| core: | |
| next: | |
| mov ip, %rax | |
| add $8, ip | |
| mov (%rax), %rax | |
| jmp *%rax | |
| enter: | |
| /**/ | |
| mov retstack, %rax | |
| mov ip, %rbx | |
| mov %rbx, (%rax) | |
| add $8, retstack | |
| /**/ | |
| mov (%rbx), %rbx | |
| mov %rbx, ip | |
| jmp next | |
| exit: | |
| sub $8, retstack | |
| mov retstack, %rax | |
| mov (%rax), %rax | |
| add $8, %rax | |
| mov %rax, ip | |
| jmp next | |
| syscalls: | |
| terminate: | |
| mov $60, %rax | |
| xor %rdi, %rdi | |
| syscall | |
| print: | |
| cmp %rsp, base | |
| jle print_error | |
| pop %rsi | |
| mov $message, %rdi | |
| xor %eax, %eax | |
| call printf | |
| xor %rbp, %rbp | |
| jmp next | |
| print_error: | |
| mov $underflow, %rdi | |
| xor %eax, %eax | |
| call printf | |
| xor %rbp, %rbp | |
| add $8, %rsp | |
| jmp next | |
| stack: | |
| push: | |
| mov ip, %rax | |
| push (%rax) | |
| add $8, ip | |
| jmp next | |
| drop: | |
| add $8, %rsp | |
| jmp next | |
| dup: | |
| push (%rsp) | |
| jmp next | |
| swap: | |
| pop %rax | |
| pop %rbx | |
| push %rax | |
| push %rbx | |
| jmp next | |
| arithmetic: | |
| add: | |
| pop %rax | |
| add %rax, (%rsp) | |
| jmp next | |
| sub: | |
| pop %rax | |
| sub %rax, (%rsp) | |
| jmp next | |
| mult: | |
| pop %rax | |
| pop %rdx | |
| imul %rax | |
| push %rax | |
| jmp next | |
| div: | |
| pop %rax | |
| pop %rdx | |
| idiv %rax | |
| push %rax | |
| jmp next | |
| logical: | |
| and: | |
| pop %rax | |
| and %rax, (%rsp) | |
| jmp next | |
| or: | |
| pop %rax | |
| or %rax, (%rsp) | |
| jmp next | |
| not: | |
| notq (%rsp) | |
| jmp next | |
| xor: | |
| pop %rax | |
| xor %rax, (%rsp) | |
| jmp next | |
| comparison: | |
| equal: | |
| pop %rax | |
| cmp %rax, (%rsp) | |
| je comparison_true | |
| jmp comparison_false | |
| less_than: | |
| pop %rax | |
| cmp %rax, (%rsp) | |
| jl comparison_true | |
| jmp comparison_false | |
| greater_than: | |
| pop %rax | |
| cmp %rax, (%rsp) | |
| jg comparison_true | |
| jmp comparison_false | |
| comparison_false: | |
| movq $0, (%rsp) | |
| jmp next | |
| comparison_true: | |
| movq $-1, (%rsp) | |
| jmp next | |
| control: | |
| jump: | |
| pop %rax | |
| mov %rax, ip | |
| jmp next | |
| jump_zero: | |
| pop %rax | |
| cmp $0, (%rsp) | |
| je jump_zero_true | |
| add $8, %rsp | |
| jmp next | |
| jump_zero_true: | |
| mov %rax, ip | |
| add $8, %rsp | |
| jmp next | |
| memory: | |
| load: | |
| mov (%rsp), %rax | |
| mov (%rax), %rax | |
| mov %rax, (%rsp) | |
| jmp next | |
| .data | |
| base: | |
| .quad 0 | |
| message: | |
| .string "%lx\n\0" | |
| underflow: | |
| .string "stack underflow.\n\0" | |
| dictionary: | |
| .quad 6 | |
| .string "square" | |
| .quad square | |
| .quad 2 | |
| .string "0<" | |
| .quad lt0 | |
| .quad 4 | |
| .string "start" | |
| .quad start | |
| square: | |
| .quad dup | |
| .quad mult | |
| .quad exit | |
| lt0: | |
| .quad push | |
| .quad 0 | |
| .quad less_than | |
| .quad exit | |
| start: | |
| .quad push | |
| .quad -50 | |
| .quad enter | |
| .quad lt0 | |
| .quad print | |
| .quad push | |
| .quad 1 | |
| .quad enter | |
| .quad lt0 | |
| .quad print | |
| .quad push | |
| .quad square | |
| .quad load | |
| .quad print | |
| .quad terminate | |
| retstack: | |
| .quad retstack+8 | |
| .fill(128 * 8) | |
| ip: | |
| .quad start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment