anchor.diff:  	       (ash (opcode-extension desc) 3)
   	       (mod (code-number opnd) 8))))))))
   
  -	       
  +;;; Always include the RXB bits of a potential REX byte.
  +(defun encode-memory-operand (memory-operand)
  +  (with-accessors ((base-register base-register)
  +		   (index-register index-register)
  +		   (scale scale)
  +		   (displacement displacement))
  +      memory-operand
  +    (cond ((and (null base-register)
  +		(null index-register))
  +	   ;; We have only a displacement.
  +	   `(#b000
  +	     #b00000101
  +	     ,@(encode-integer displacement 4)))
  +	  ((and (null index-register)
  +		(null displacement))
  +	   ;; We have only a base register.
  +	   (multiple-value-bind (rex.b r/m)
  +	       (floor (code-number base-register) 8)
  +	     (if (= r/m 4)
  +		 `(,rex.b
  +		   #b00000100  ; ModR/M byte
  +		   #b00100100) ; SIB byte
  +		 `(,rex.b
  +		   ,r/m))))
  +	  ((and (null index-register)
  +		(typep displacement '(signed-byte 8)))
  +	   ;; We have a base register and an 8-bit displacement.
  +	   (multiple-value-bind (rex.b r/m)
  +	       (floor (code-number base-register) 8)
  +	     (if (= r/m 4)
  +		 `(,rex.b
  +		   #b01000100 ; ModR/M byte
  +		   #b00100100 ; SIB byte
  +		   ,(encode-integer displacement 1))
  +		 `(,rex.b
  +		   ,(+ #b01000000 r/m)
  +		   ,@(encode-integer displacement 1)))))
  +	  ((and (null index-register)
  +		(typep displacement '(signed-byte 32)))
  +	   ;; We have a base register and a 32-bit displacement.
  +	   (multiple-value-bind (rex.b r/m)
  +	       (floor (code-number base-register) 8)
  +	     (if (= r/m 4)
  +		 `(,rex.b
  +		   #b10000100 ; ModR/M byte
  +		   #b00100100 ; SIB byte
  +		   ,(encode-integer displacement 1))
  +		 `(,rex.b
  +		   ,(+ #b01000000 r/m)
  +		   ,@(encode-integer displacement 4)))))
  +	  ((null base-register)
  +	   ;; The only encoding provided when there is no base
  +	   ;; register has a 32-bit displacement, so even if the
  +	   ;; displacement is small or even 0, we must use this
  +	   ;; encoding.
  +	   (multiple-value-bind (rex.x i)
  +	       (floor (code-number index-register) 8)
  +	     `(,(ash rex.x 1)
  +	       #b00000100 ; ModR/M byte
  +	       ,(+ (ash (round (log scale 2)) 6)
  +		   (ash i 3)
  +		   #b101)
  +	       ,@(encode-integer (or displacement 0) 4))))
  +	  ((null displacement)
  +	   (multiple-value-bind (rex.b b)
  +	       (floor (code-number base-register) 8)
  +	     (multiple-value-bind (rex.x i)
  +		 (floor (code-number index-register) 8)
  +	       (if (= b 5)
  +		   ;; If the base register is 5 (EBP) or 13, then we
  +		   ;; have a problem, because there is no encoding for
  +		   ;; that situation without a displacement.  So we
  +		   ;; use a displacement of 0.
  +		   `(,(+ (ash rex.x 1) rex.b)
  +		     #b01000100 ; ModR/M byte
  +		     ,(+ (ash (round (log scale 2)) 6)
  +			 (ash i 3)
  +			 b)
  +		     0)
  +		   `(,(+ (ash rex.x 1) rex.b)
  +		     #b00000100 ; ModR/M byte
  +		     ,(+ (ash (round (log scale 2)) 6)
  +			 (ash i 3)
  +			 b))))))
  +	  (t
  +	   (multiple-value-bind (rex.b b)
  +	       (floor (code-number base-register) 8)
  +	     (multiple-value-bind (rex.x i)
  +		 (floor (code-number index-register) 8)
  +	       (if (typep displacement '(signed-byte 8))
  +		   `(,(+ (ash rex.x 1) rex.b)
  +		     #b01000100 ; ModR/M byte
  +		     ,(+ (ash (round (log scale 2)) 6)
  +			 (ash i 3)
  +			 b)
  +		     ,@(encode-integer displacement 1))
  +		   `(,(+ (ash rex.x 1) rex.b)
  +		     #b10000100 ; ModR/M byte
  +		     ,(+ (ash (round (log scale 2)) 6)
  +			 (ash i 3)
  +			 b)
  +		     ,@(encode-integer displacement 4)))))))))
  +
  +(defmethod encode-instruction-1 (desc (opnd memory-operand))
  +  (destructuring-bind (type size) (first (operands desc))
  +    (declare (ignore size))
  +    (let ((override (operand-size-override desc)))
  +      (ecase type
  +	(modrm
  +	 (destructuring-bind (rex.xb &rest rest)
  +	     (encode-memory-operand opnd)
  +	   (let ((rex-bits (+ (if (rex.w opnd) #b1000 0) rex.xb)))
  +	     `(,@(if override
  +		     '(#x66)
  +		     (if (plusp rex-bits)
  +			 `(,(+ #x40 rex-bits))
  +			 '()))
  +	       ,@rest))))))))
  
positive.code: ;;; the representation of VALUE in a little-endian encoding, i.e., the
  ;;; bytes in the resulting list are ordered from least to most
  ;;; significant.
  (defun encode-immediate (value size)
    (loop for position from 0 by 8
  	repeat size
  	collect (ldb (byte 8 position) value)))
  
negative.code: 		   (override '(#x66))
  		   (t '()))
  	   ,@(opcodes desc)
  	   ,@(encode-integer (value opnd) size)))))))
  
  (defmethod encode-instruction-1 (desc (opnd gpr-operand))
    (destructuring-bind (type size) (first (operands desc))
  