Skip to content

Instantly share code, notes, and snippets.

(hexize (asm (:x86oid)
(add :al :bl)
(add :ax :bx)
(add :eax :ebx)
(add :al #x30)
(add (make-displacement #x50) :al)
(add :al (make-displacement #x50))
(add (make-indirect-base :si :bp) :bx)
(add :eax (make-indirect-base :si :bp))
(lodsb)
(hexize (asm (:x86oid)
(inc :eax)
(dec :ax)
(push :edx)
(pop :si)
(int 3)
(nop)))
;;=> "66 40 | 48 | 66 52 | 5E | CD 03 | 90"
(asm (:x86oid)
(inc :eax)
(dec :ax)
(push :edx)
(pop :si)
(int 3)
(nop))
;;=> ((102 64) (72) (102 82) (94) (205 3) (144))
(define-x86oid-mnemonic dec (op1)
((nass.x86oid.types::r16)
(list (logior #x48 (encode-reg-bits op1))))
((nass.x86oid.types::r32)
(list #x66 (logior #x48 (encode-reg-bits op1)))))
(add :ax :bx)
;;=> 1
(add :al :bl)
;;=> 0
(add :al 3)
;;=> 4
Below is the assembly output for the following function:
;;; Note that dispatch-entry is a lisp structure. This is sorta equivalent
;;; to a C structure, the way they are stored is very similar
(defun dispatch-entry-equal (entry1 entry2)
(declare (dispatch-entry entry1 entry2))
(equal (dispatch-entry-type entry1)
(dispatch-entry-type entry2)))
;; OPTIMIZED (safety 0) (speed 3) <lisp acts like C here and treats types
;; OPTIMIZED (safety 0) (speed 3) <lisp acts like C here and treats types
;; as compiler hints>
; disassembly for DISPATCH-ENTRY-EQUAL
; 04F7307F: 488B520F MOV RDX, [RDX+15] ; no-arg-parsing entry point
; 83: 488B7F0F MOV RDI, [RDI+15]
; 87: 488B05A2FFFFFF MOV RAX, [RIP-94] ; #<FDEFINITION object for EQUAL>
; 8E: B910000000 MOV ECX, 16
; 93: FF7508 PUSH QWORD PTR [RBP+8]
; 96: FF6009 JMP QWORD PTR [RAX+9]
(defop nop #x90 () "No operation.")
(defop nop #x90 () "No operation."
:prefix #xf3)
(defop nop #x1f () "No operation."
:register-opcode-field 0
:prefix #x0f)
(defop nop #x0f () "No operation."
:prefix #x0d)
The object is a STRUCTURE-OBJECT of type X86-INSTRUCTION.
NAME: FOO
PRIMARY-OPCODE: 0
EXTENSION: NIL
WRITER: NIL
READER: NIL
DOCUMENTATION: "look a test"
CATEGORIES: (:BINARY)
OPERANDS: ((E F))
FLAGS: NIL
;;; E means a r/m byte
;;; b means a byte regardless of operand code
;;; L means Lock prefix is valid
;;; r means r/m bit has part of the opcode
;;; d means bit 1 for direction is present
;;; w means bit 0 for operand size is present
(binop add #x00 r (d w)
((operand E b) (operand G b))
(:extra L)
;; arch defaults to *default-arch* which can be set in a (let ...)