diff options
author | nrootconauto <nrootconauto@gmail.com> | 2022-01-10 15:34:19 -0500 |
---|---|---|
committer | nrootconauto <nrootconauto@gmail.com> | 2022-01-10 15:34:19 -0500 |
commit | 7b5a4988ea5c01cda45ffe140ee6084bb9f74d15 (patch) | |
tree | c762d629e1a0a4cf8c98c1cfcf85a4d885d6f2c3 | |
parent | 1844ed7c0d4788d40e11bae2b9816fe677ef800a (diff) |
asm.c restored.v0.0.6
-rw-r--r-- | README.MD | 13 | ||||
-rw-r--r-- | asm.c | 10 | ||||
-rw-r--r-- | asmtest.hc | 4 |
3 files changed, 20 insertions, 7 deletions
@@ -79,6 +79,19 @@ I64 x=#exe{StreamPrint("10");}; I64 int_pi=ToI64(pi); ``` + # Assembler + This compiler includes an assembler,see `asmtest.hc` for usage. **Put global variables and functions in reigsters before addressing them,the OS may put them within a range that isnt within range of a 32bit jump**(Most memory operations use 32bit offsets,see `MOFFSxx` in `HCRT/Opcodes.DD` if you really want to.). + ``` + U0 Hi() { + asm { + MOV RAX, &Hello; + CALL RAX; + } + } + ``` + If you suspect the assembler is acting up,open in gdb and type `disas GetVariable("Func_with_asm_in_it").func.funcptr,+100` for a dissambly. I would love to fix any problems in the assembler. Also,make sure you follow the ABI for your OS when using assembler code. And **DONT JUMP INTO ASM BLOCKS FROM HolyC Code**. All registers are unloaded prior to entering an asm block and before any label that an asm block jumps to. + + # Internals This compiler uses a modified myjit which runs under windows(new feature),linux(and breifly tested on FreeBSD). The main part of the Compiler is in compile.c. The compiler uses a value stack for temporary values(if they are on the stack on the same time they interfere). The grammar is in `HolyC.y`. The lexer uses a rope data structure provided by a patched `ext/mropes`. I plan on making a game with this compiler so I will add to the runtime as needed. If you want to add functions,look at `runtime.c`,but a functional text editor is provided in `HolyEd/EDITOR.HC`. @@ -225,10 +225,9 @@ void* AST2X64Mode(AST* a, int64_t* lab_offset) { return NULL; } void* GetRegister(char* name) { -#ifndef BOOTSTRAP +#ifndef BOOTSTRAPED return NULL; -#endif // BOOTSTRAP - if(Compiler.tagsFile) return NULL; +#endif // BOOTSTRAPED if(!Compiler.loadedHCRT) return 0; CVariable* enc = GetHCRTVar("GetRegister"); @@ -239,10 +238,9 @@ void* GetRegister(char* name) { return ((void* (*)(char*))enc->func->funcptr)(name); } int IsOpcode(char* name) { -#ifndef BOOTSTRAP +#ifndef BOOTSTRAPED return NULL; -#endif // BOOTSTRAP - if(Compiler.tagsFile) return 0; +#endif // BOOTSTRAPED if(!Compiler.loadedHCRT) return 0; CVariable* enc = GetHCRTVar("IsOpcode"); @@ -84,7 +84,8 @@ asm { PUSH R12; MOV R12,10; @@Loop: - CALL &HelloWorld; + MOV RAX, &HelloWorld; + CALL RAX; DEC R12; CMP R12,0; JNE @@Loop; @@ -100,3 +101,4 @@ asm { _import C_HELLO U0 Hi(); Dummy; Hi; + |