19 ms·
No I mean a disassembler, I can see how an assembler is nice to write in a language like that but I've never seen much byte manipulation examples. For example g
by speps 7y ago
No I mean a disassembler, I can see how an assembler is nice to write in a language like that but I've never seen much byte manipulation examples. For example going from machine code to the list of opcodes for example.
- siraben 7y agoThat would be an interesting project. AFAIK Emacs has a bytecode disassembler[0] but I'm not aware of disassemblers for other instruction sets. [0] https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/disass.el https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-...
- pjmlp 7y agoThere you go, "CHIP-8 in Common Lisp: Disassembly" https://stevelosh.com/blog/2017/01/chip8-disassembly/ https://stevelosh.com/blog/2017/01/chip8-disassembly/
- lispm 7y agoEvery Common Lisp has a DISASSEMBLE function built-in. Compile a function and call the disassembler. For example SBCL https://github.com/sbcl/sbcl/blob/master/src/compiler/disassem.lisp https://github.com/sbcl/sbcl/blob/master/src/compiler/disass... and its ARM64 instructions: https://github.com/sbcl/sbcl/blob/master/src/compiler/arm64/insts.lisp https://github.com/sbcl/sbcl/blob/master/src/compiler/arm64/...
- dreamcompiler 7y agoHere's the times13 function in CCL on x86-64. (Note that #x68 is 13 shifted left 3 times to allow tag bits in the LS 3 bit positions. Also the below could be optimized a lot more but this is the default compilation.) ? (defun times13 (x) (* 13 x)) TIMES13 ? (disassemble 'times13) ;;; (defun times13 (x) (* 13 x)) (recover-fn-from-rip) ; [0] (cmpl ($ 8) (% nargs)) ; [7] (jne L41) ; [10] (pushq (% rbp)) ; [12] (movq (% rsp) (% rbp)) ; [13] (pushq (% arg_z)) ; [16] ;;; (* 13 x) (movl ($ #x68) (% arg_y.l)) ; [17] (movq (@ -8 (% rbp)) (% arg_z)) ; [22] (movq (% rbp) (% rsp)) ; [26] (popq (% rbp)) ; [29] (jmp (@ .SPBUILTIN-TIMES)) ; [30] ;;; #<no source text> (:align 3) L41 ; [@56] (uuo-error-wrong-number-of-args) ; [41] NIL