Calculate the displacement for 16-bit effective address calculation.
This is according to Intel manual, Mar'17, Vol. 2, Table 2-1.
The displacement is absent (i.e. 0) when Mod is 00b. An exception to this is when R/M is 110b, in which case there is a 16-bit displacement that is added to the index. This case is not handled by this function, but is instead handled in its caller function x86-effective-addr-16.
The displacement is a signed 8-bit value when Mod is 01b. The displacement is a signed 16-bit value when Mod is 10b. This function is not called when Mod is 11b.
If an error occurs when trying to read the displacement, 0 is returned as displacement, but the caller ignores the returned displacement given the error.
This function is called only when the address size is 16 bits.
Function:
(defun x86-effective-addr-16-disp (proc-mode temp-rip mod x86) (declare (xargs :stobjs (x86))) (declare (type (integer 0 4) proc-mode) (type (signed-byte 48) temp-rip) (type (unsigned-byte 2) mod)) (declare (xargs :guard (2bits-p mod))) (let ((__function__ 'x86-effective-addr-16-disp)) (declare (ignorable __function__)) (case mod (0 (mv nil 0 0 x86)) (1 (b* (((mv flg byte x86) (rime-size-opt proc-mode 1 temp-rip 1 :x nil x86 :mem-ptr? nil)) ((when flg) (mv flg 0 0 x86))) (mv nil byte 1 x86))) (2 (b* (((mv flg word x86) (rime-size-opt proc-mode 2 temp-rip 1 :x nil x86 :mem-ptr? nil)) ((when flg) (mv flg 0 0 x86))) (mv nil word 2 x86))) (otherwise (mv 'mod-value-wrong 0 0 x86)))))
Theorem:
(defthm i16p-of-x86-effective-addr-16-disp.disp (implies (x86p x86) (b* (((mv ?flg ?disp ?increment-rip-by ?x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86))) (i16p disp))) :rule-classes :rewrite)
Theorem:
(defthm natp-of-x86-effective-addr-16-disp.increment-rip-by (b* (((mv ?flg ?disp ?increment-rip-by ?x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86))) (natp increment-rip-by)) :rule-classes :rewrite)
Theorem:
(defthm x86p-of-x86-effective-addr-16-disp.x86 (implies (x86p x86) (b* (((mv ?flg ?disp ?increment-rip-by ?x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86))) (x86p x86))) :rule-classes :rewrite)
Theorem:
(defthm integerp-of-x86-effective-addr-16-disp.disp (implies (x86p x86) (b* (((mv ?flg ?disp ?increment-rip-by ?x86) (x86-effective-addr-16-disp proc-mode temp-rip mod x86))) (integerp disp))) :rule-classes :type-prescription)
Theorem:
(defthm mv-nth-2-x86-effective-addr-16-disp-<=-4 (<= (mv-nth 2 (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) 4) :rule-classes :linear)