aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2023-02-27 23:39:46 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2023-02-27 23:39:46 +0100
commit390fd302e0314ea4cf5c150b3adb745e765d745e (patch)
tree96c74abbeb7aedc710ac32c2ad15c22b61cd3dd7
parentd44466c852dd353166c79d1cc618646b21e17f8c (diff)
downloadjuicebox-asm-390fd302e0314ea4cf5c150b3adb745e765d745e.tar.gz
juicebox-asm-390fd302e0314ea4cf5c150b3adb745e765d745e.zip
Add README and LICENSE
-rw-r--r--LICENSE21
-rw-r--r--README.md47
2 files changed, 68 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..edb7177
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 Johannes Stölp
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f5842c6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,47 @@
+# juicebox-asm
+
+An `x64` jit assembler for learning purpose with the following two main goals:
+- Learn about x64 instruction encoding.
+- Learn how to use the rust type system to disallow invalid operands.
+
+## Example
+
+```rust
+use juicebox_asm::prelude::{Reg32::*, *};
+use juicebox_asm::rt::Runtime;
+
+fn main() {
+ let mut asm = Asm::new();
+
+ // Reference implementation
+ // int ret = 0;
+ // int n = 0;
+ //
+ // loop:
+ // ret += n;
+ // --n;
+ // if (n != 0) goto loop;
+ //
+ // return;
+
+ let mut lp = Label::new();
+
+ asm.mov(eax, Imm32::from(0));
+ asm.mov(ecx, Imm32::from(42));
+
+ asm.bind(&mut lp);
+ asm.add(eax, ecx);
+ asm.dec(ecx);
+ asm.test(ecx, ecx);
+ asm.jnz(&mut lp);
+
+ asm.ret();
+
+ let rt = Runtime::new(&asm.into_code());
+ let func = unsafe { rt.as_fn::<extern "C" fn() -> u32>() };
+ assert_eq!(func(), (0..=42).into_iter().sum());
+}
+```
+
+## License
+This project is licensed under the [MIT](LICENSE) license.