fasmreadelf -h with gdbBecause yep, I suffered a data loss for my whole server and I haven’t recover it yet. (Lesson here everyone, have backups!!) So yeah now I’m working in a sorta decentralised way, using a git service and just code on whatever machine I got hands on.
But that’s not the focus today, what I wanna share is a hack I learned from tsoding, on how do you debug fasm programs, as they don’t have an option to build with debug symbols.
What you can do around it is: 1. compile your program normally, ofc
2. readelf -h <your executable>, find the
Entry point address: 3. use break *0x____ in
gdb 4. now you can use si to step through
Useful settings for gdb includes: - change the syntax to intel -
layout asm - layout regs -
watch *addr@n
Inspired by the index notation and tensors, we want to build a language that utilises the index notation like following:
f_{a,b}^c g_{c,d} p^a q^b r^d
which represents the mathematical formula of: g(f(p, q), r). And same as when you’re writing about components in physics, the order of them does not matter, and we’ll delegate to the pre- processor to rearrange them into a fixed (preferred) order, e.g.
g_{c,d} f_{a,b}^c p^a q^b r^d
which can be evaluated from in to out.
In the language, we’ll be separating into msinly two parts: 1. PREP: Pre-processor (physics/maths-layer), and 2. COMP: Compiler (programming-layer).
We apply the rules of mathematics and physics in this layer, one of the main job of pre- processor is to bind indices. The general rules are: - if the indices appeared in the LHS, it will not be summed over, - if they only appeared in the RHS, then - they may only appear exactly twice (unless it spans throughout addition), with one upper and one lower. Any other scenario will result in a pre- processor error.
After which, the pre-processor will have to infer the range S ⊂ ℤ0+ the index will have to iterate through.
Since this language is aimed to work with general relativity, we reserve some symbols for non-conventional use.
{} is the neutral bracket, it can be used
| separating the
differentiating index);() symbols commutative expansion, and[] symbols anti-commutative expansion;\ is just a regular character, it is not an
escape character, thus you can name variable like TeX.My goal is to let pattern emerge.
Vector: v^3: +1, +2, +4> Function call:
func: +2, +4|5> - has 2 and 4 as variable and - 5 more
pre-populated constant.
0+1, +2, +2, +4 /-1 2 2 cur:4-/
<4 /-cur:? 1 2 2 4-/
<2: /- func: -/
+2, +4|4>func /-2 4 cur:dist 1 2 2 4-/
### 1-pass compiler
I want to implement a compiler that can compile
the source file in one single pass.
Thus I implied the limit of (most) tokens have
to have one-to-one correspondence to assembly
instruction. So a simple program will get mapped
like following:
label:<1?!@>; =>label:=>func_label: => <1 =>
/-caller’s-/ => ? => WriteDistToCell ;mov rax, [CURP] test rax,
rax jnz @f+1 =>
:; =>: =>COLN ; =>SEMI /-some scoped code-/ :?!;
/-func body end:——————————–/ :. => : => COLN . => PRID
/-main body begin:——————————/ label:+2> =>label:=>COLN =>@@: <1 => mvlz 1 ; /-callee’s-/ => +2 => mov [CURP], 2 => > => cmvr 1 (beneath)=> call func_label => pop COLP ```
with the only non-bijective mapping be label:, which we
differentiate by: - if it’s the first occurrence, then move the
file-cursor to before start: and append the function’s
definition and returning to the main function after all branches
terminates, i.e. all if-else branches either merged or have a
ret-statement (.), or - if it’s not, then expand it as
invoking the function, i.e. mark the colon and populate the arguments
until >.
Note that, although most likely it can be decided which branch of the
test COLP, COLP will the code take, to remain consistent
we’ll keep the code as such for now and allow optimisation through flag
in the future.
Also, with regard to , (comma), its sole purpose during
the COMP-stage is to expand into > (shift right), but
offers distinction where > acts as function call end
marker. Even though comma acts as a separator in the brackets, it will
be processed and removed in the PREP-stage.