Execute Brain****/x86 Assembly: Difference between revisions
m
Fixed syntax highlighting.
(Not quite right.) |
m (Fixed syntax highlighting.) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1:
===x86_64 Assembly===
GAS Syntax for Linux. Called it "Brainkrieg" after Teen Girl Squad. Operating principle is a little like a multi-cycle processor. Uses a jump table. Fixed data memory block.▼
▲GAS Syntax for Linux. Called it "Brainkrieg" after Teen Girl Squad. Operating principle is a little like a multi-cycle processor.
===Implementation:===
<syntaxhighlight lang="asm">// Assembly brainf*** interpreter
// Alternative name: "ASSembly brainF*** interpretER"
// Compiles with `gcc -nostdlib brainkrieg.sx -o brainkrieg`
Line 34 ⟶ 29:
#define STDIN $0
#define STDOUT $1
#define STDERR $2
#define DEBUGMODE 0
.global _start
Line 104 ⟶ 102:
cmpq end, %rbx
ja shutdown // End of code
incq %rbx
movq %rbx, inst_ptr
decode:
je out_data▼
je in_data▼
jmp fetch▼
// execute:
dp_left:
Line 138 ⟶ 131:
dec_data:
movq data_ptr, %rbx
jmp fetch
inc_data:
movq data_ptr, %rbx
jmp fetch
out_data:
Line 270 ⟶ 263:
.data
branch_table:
.rept 43
.endr
.quad inc_data
.quad dec_data
.rept 13
.quad fetch
.endr
.quad dp_left
.quad fetch
.quad dp_right
.rept 28
.quad fetch
.endr
.quad brf
.quad fetch
.quad brb
.rept 162
.quad fetch
.endr
.bss
brack_smph: // Bracket matching semaphore
.quad 0
Line 275 ⟶ 299:
junkChar: // Also used to check if input was used.
.byte 0
#if DEBUGMODE
debugChar:
.byte 0
#endif
err_val:
.byte 0
// fstat:
statstruct: // This struct is 144 bytes. Only want size (+48)
.zero FSIZEOFF
Line 295 ⟶ 325:
// Data:
data_ptr:
.quad 0
tape:
.zero
endtape:
.zero 1</syntaxhighlight>
|