Have sign-extend-complex deal correctly with bytes of size 0.
[movitz-ia-x86.git] / instr-mov.lisp
blob466b91ce21642d9e0e208463d606d32d43a22b4e
1 ;;;;------------------------------------------------------------------
2 ;;;;
3 ;;;; Copyright (C) 2000, 2004,
4 ;;;; Department of Computer Science, University of Tromso, Norway
5 ;;;;
6 ;;;; Filename: instr-mov.lisp
7 ;;;; Description: MOV instructions
8 ;;;; Author: Frode Vatvedt Fjeld <frodef@acm.org>
9 ;;;; Created at: Thu Jan 27 14:43:05 2000
10 ;;;; Distribution: See the accompanying file COPYING.
11 ;;;;
12 ;;;; $Id: instr-mov.lisp,v 1.2 2004/01/16 11:54:14 ffjeld Exp $
13 ;;;;
14 ;;;;------------------------------------------------------------------
16 (in-package "IA-X86-INSTR")
18 ;;; ----------------------------------------------------------------
19 ;;; MOV classes
20 ;;; ----------------------------------------------------------------
23 ;;; ----------------------------------------------------------------
24 ;;; MOV instructions [IISR 11-281]
25 ;;; ----------------------------------------------------------------
27 (def-instr mov (instruction))
28 (def-instr movb (mov)
29 (:+ #xb0 1 (imm8 +r8))
30 (:r #x88 (r8 r/m8))
31 (:r #x8a (r/m8 r8))
32 (:moffs #xa0 (moffs8 al))
33 (:moffs #xa2 (al moffs8))
34 (:digit (#xc6 0) 1 (imm8 r/m8)))
36 (def-instr movw (mov)
37 (:r #x89 (r16 r/m16) :operand-mode :16-bit)
38 (:r #x8b (r/m16 r16) :operand-mode :16-bit)
39 (:r #x8c (sreg r/m16))
40 (:r #x8e (r/m16 sreg))
41 (:+ #xb8 2 (imm16 +r16) :operand-mode :16-bit)
42 (:digit (#xc7 0) 2 (imm16 r/m16) :operand-mode :16-bit)
43 (:moffs #xa1 (moffs16 ax))
44 (:moffs #xa3 (ax moffs16)))
47 (def-instr movl (mov)
48 (:r #x89 (r32 r/m32) :operand-mode :32-bit)
49 (:r #x8b (r/m32 r32) :operand-mode :32-bit)
50 (:+ #xb8 4 (imm32 +r32) :operand-mode :32-bit)
51 (:digit (#xc7 0) 4 (imm32 r/m32) :operand-mode :32-bit)
52 (:moffs #xa1 (moffs32 eax))
53 (:moffs #xa3 (eax moffs32)))
55 ;;; ----------------------------------------------------------------
56 ;;; MOVSX instructions [IISR 11-291]
57 ;;; ----------------------------------------------------------------
59 (def-instr movsx (instruction))
60 (def-instr movsxb (movsx)
61 (:r #c(#x0fbe 2) (r/m8 r16) :operand-mode :16-bit)
62 (:r #c(#x0fbe 2) (r/m8 r32) :operand-mode :32-bit))
63 (def-instr movsxw (movsx)
64 (:r #c(#x0fbf 2) (r/m16 r32)))
66 ;;; MOV string
68 (def-instr movs (instruction))
69 (def-instr movsb (movs) (:simple #xa4))
70 (def-instr movsw (movs) (:simple #xa5 :operand-mode :16-bit))
71 (def-instr movsd (movs) (:simple #xa5 :operand-mode :32-bit))
73 ;;; ----------------------------------------------------------------
74 ;;; MOVZX instructions [IISR 11-292]
75 ;;; ----------------------------------------------------------------
77 (def-instr movzx (instruction))
78 (def-instr movzxb (movzx)
79 (:r #c(#x0fb6 2) (r/m8 r16) :operand-mode :16-bit)
80 (:r #c(#x0fb6 2) (r/m8 r32) :operand-mode :32-bit))
81 (def-instr movzxw (movzx)
82 (:r #c(#x0fb7 2) (r/m16 r32)))
84 ;;; ----------------------------------------------------------------
85 ;;; MOV to/from Control Registers
86 ;;; ----------------------------------------------------------------
88 (def-instr movcr (instruction)
89 (:digit (#x0f22 0) 0 (r/m32 cr0) :direct t)
90 (:digit (#x0f22 2) 0 (r/m32 cr2) :direct t)
91 (:digit (#x0f22 3) 0 (r/m32 cr3) :direct t)
92 (:digit (#x0f22 4) 0 (r/m32 cr4) :direct t)
94 (:digit (#x0f20 0) 0 (cr0 r/m32) :direct t)
95 (:digit (#x0f20 2) 0 (cr2 r/m32) :direct t)
96 (:digit (#x0f20 3) 0 (cr3 r/m32) :direct t)
97 (:digit (#x0f20 4) 0 (cr4 r/m32) :direct t))
99 ;;; ----------------------------------------------------------------
100 ;;; MOV to/from Debug Registers
101 ;;; ----------------------------------------------------------------
103 (def-instr movdr (instruction)
104 (:digit (#x0f21 0) 0 (r/m32 dr0) :direct t)
105 (:digit (#x0f21 1) 0 (r/m32 dr1) :direct t)
106 (:digit (#x0f21 2) 0 (r/m32 dr2) :direct t)
107 (:digit (#x0f21 3) 0 (r/m32 dr3) :direct t)
108 (:digit (#x0f21 4) 0 (r/m32 dr4) :direct t)
109 (:digit (#x0f21 5) 0 (r/m32 dr5) :direct t)
110 (:digit (#x0f21 6) 0 (r/m32 dr6) :direct t)
111 (:digit (#x0f21 7) 0 (r/m32 dr7) :direct t)
113 (:digit (#x0f23 0) 0 (dr0 r/m32) :direct t)
114 (:digit (#x0f23 1) 0 (dr1 r/m32) :direct t)
115 (:digit (#x0f23 2) 0 (dr2 r/m32) :direct t)
116 (:digit (#x0f23 3) 0 (dr3 r/m32) :direct t)
117 (:digit (#x0f23 4) 0 (dr4 r/m32) :direct t)
118 (:digit (#x0f23 5) 0 (dr5 r/m32) :direct t)
119 (:digit (#x0f23 6) 0 (dr6 r/m32) :direct t)
120 (:digit (#x0f23 7) 0 (dr7 r/m32) :direct t))
122 ;;; ----------------------------------------------------------------
123 ;;; CMOVcc -- Conditional Move
124 ;;; ----------------------------------------------------------------
126 (def-instr cmova (instruction) ; if above
127 (:r #x0f47 (r/m16 r16) :operand-mode :16-bit :priority 10)
128 (:r #x0f47 (r/m32 r32) :operand-mode :32-bit :priority 10))
130 (def-instr cmovae (instruction) ; if above or equal
131 (:r #x0f43 (r/m16 r16) :operand-mode :16-bit :priority 10)
132 (:r #x0f43 (r/m32 r32) :operand-mode :32-bit :priority 10))
134 (def-instr cmovb (instruction) ; if below
135 (:r #x0f42 (r/m16 r16) :operand-mode :16-bit :priority 10)
136 (:r #x0f42 (r/m32 r32) :operand-mode :32-bit :priority 10))
138 (def-instr cmovbe (instruction) ; if below or equal
139 (:r #x0f46 (r/m16 r16) :operand-mode :16-bit :priority 10)
140 (:r #x0f46 (r/m32 r32) :operand-mode :32-bit :priority 10))
142 (def-instr cmovc (instruction) ; if carry
143 (:r #x0f42 (r/m16 r16) :operand-mode :16-bit :priority 20)
144 (:r #x0f42 (r/m32 r32) :operand-mode :32-bit :priority 20))
146 (def-instr cmove (instruction) ; if equal
147 (:r #x0f44 (r/m16 r16) :operand-mode :16-bit :priority 10)
148 (:r #x0f44 (r/m32 r32) :operand-mode :32-bit :priority 10))
150 (def-instr cmovg (instruction) ; if greater
151 (:r #x0f4f (r/m16 r16) :operand-mode :16-bit :priority 10)
152 (:r #x0f4f (r/m32 r32) :operand-mode :32-bit :priority 10))
154 (def-instr cmovge (instruction) ; if greater or equal
155 (:r #x0f4d (r/m16 r16) :operand-mode :16-bit :priority 10)
156 (:r #x0f4d (r/m32 r32) :operand-mode :32-bit :priority 10))
158 (def-instr cmovl (instruction) ; if less
159 (:r #x0f4c (r/m16 r16) :operand-mode :16-bit :priority 10)
160 (:r #x0f4c (r/m32 r32) :operand-mode :32-bit :priority 10))
162 (def-instr cmovle (instruction) ; if less or equal
163 (:r #x0f4e (r/m16 r16) :operand-mode :16-bit :priority 10)
164 (:r #x0f4e (r/m32 r32) :operand-mode :32-bit :priority 10))
166 (def-instr cmovna (instruction) ; if not above
167 (:r #x0f46 (r/m16 r16) :operand-mode :16-bit :priority 0)
168 (:r #x0f46 (r/m32 r32) :operand-mode :32-bit :priority 0))
170 (def-instr cmovnae (instruction) ; if not above or equal
171 (:r #x0f42 (r/m16 r16) :operand-mode :16-bit :priority 0)
172 (:r #x0f42 (r/m32 r32) :operand-mode :32-bit :priority 0))
174 (def-instr cmovnb (instruction) ; if not below
175 (:r #x0f43 (r/m16 r16) :operand-mode :16-bit :priority 0)
176 (:r #x0f43 (r/m32 r32) :operand-mode :32-bit :priority 0))
178 (def-instr cmovnbe (instruction) ; if not below or equal
179 (:r #x0f47 (r/m16 r16) :operand-mode :16-bit :priority 0)
180 (:r #x0f47 (r/m32 r32) :operand-mode :32-bit :priority 0))
182 (def-instr cmovnc (instruction) ; if not carry
183 (:r #x0f43 (r/m16 r16) :operand-mode :16-bit :priority 20)
184 (:r #x0f43 (r/m32 r32) :operand-mode :32-bit :priority 20))
186 (def-instr cmovne (instruction) ; if not equal
187 (:r #x0f45 (r/m16 r16) :operand-mode :16-bit :priority 10)
188 (:r #x0f45 (r/m32 r32) :operand-mode :32-bit :priority 10))
190 (def-instr cmovng (instruction) ; if not greater
191 (:r #x0f4e (r/m16 r16) :operand-mode :16-bit :priority 0)
192 (:r #x0f4e (r/m32 r32) :operand-mode :32-bit :priority 0))
194 (def-instr cmovnge (instruction) ; if not greater or equal
195 (:r #x0f4c (r/m16 r16) :operand-mode :16-bit :priority 0)
196 (:r #x0f4c (r/m32 r32) :operand-mode :32-bit :priority 0))
198 (def-instr cmovnl (instruction) ; if not less
199 (:r #x0f4d (r/m16 r16) :operand-mode :16-bit :priority 0)
200 (:r #x0f4d (r/m32 r32) :operand-mode :32-bit :priority 0))
202 (def-instr cmovnle (instruction) ; if not less or equal
203 (:r #x0f4f (r/m16 r16) :operand-mode :16-bit :priority 0)
204 (:r #x0f4f (r/m32 r32) :operand-mode :32-bit :priority 0))
206 (def-instr cmovno (instruction) ; if not overflow
207 (:r #x0f41 (r/m16 r16) :operand-mode :16-bit :priority 10)
208 (:r #x0f41 (r/m32 r32) :operand-mode :32-bit :priority 10))
210 (def-instr cmovnp (instruction) ; if not parity
211 (:r #x0f4b (r/m16 r16) :operand-mode :16-bit :priority 10)
212 (:r #x0f4b (r/m32 r32) :operand-mode :32-bit :priority 10))
214 (def-instr cmovns (instruction) ; if not sign
215 (:r #x0f49 (r/m16 r16) :operand-mode :16-bit :priority 10)
216 (:r #x0f49 (r/m32 r32) :operand-mode :32-bit :priority 10))
218 (def-instr cmovnz (instruction) ; if not zero
219 (:r #x0f45 (r/m16 r16) :operand-mode :16-bit :priority 0)
220 (:r #x0f45 (r/m32 r32) :operand-mode :32-bit :priority 0))
222 (def-instr cmovo (instruction) ; if overflow
223 (:r #x0f40 (r/m16 r16) :operand-mode :16-bit :priority 10)
224 (:r #x0f40 (r/m32 r32) :operand-mode :32-bit :priority 10))
226 (def-instr cmovp (instruction) ; if parity
227 (:r #x0f4a (r/m16 r16) :operand-mode :16-bit :priority 0)
228 (:r #x0f4a (r/m32 r32) :operand-mode :32-bit :priority 0))
230 (def-instr cmovpe (instruction) ; if parity even
231 (:r #x0f4a (r/m16 r16) :operand-mode :16-bit :priority 10)
232 (:r #x0f4a (r/m32 r32) :operand-mode :32-bit :priority 10))
234 (def-instr cmovpo (instruction) ; if parity odd
235 (:r #x0f4b (r/m16 r16) :operand-mode :16-bit :priority 20)
236 (:r #x0f4b (r/m32 r32) :operand-mode :32-bit :priority 20))
238 (def-instr cmovs (instruction) ; if sign
239 (:r #x0f48 (r/m16 r16) :operand-mode :16-bit :priority 10)
240 (:r #x0f48 (r/m32 r32) :operand-mode :32-bit :priority 10))
242 (def-instr cmovz (instruction) ; if cmovz
243 (:r #x0f44 (r/m16 r16) :operand-mode :16-bit :priority 0)
244 (:r #x0f44 (r/m32 r32) :operand-mode :32-bit :priority 0))
246 ;;; ----------------------------------------------------------------
247 ;;; MOV class PRINT-OBJECT
248 ;;; ----------------------------------------------------------------
250 (cl:defmethod cl:print-object ((obj mov) stream)
251 (cl:if (cl:and cl:*print-pretty*
252 (cl:= 2 (cl:length (instruction-operands obj))))
253 (cl:progn
254 (cl:format stream
255 "#<asm ~@[~A ~]~A ~A => ~A>"
256 (instruction-prefixes obj)
257 (cl:type-of obj)
258 (cl:first (instruction-operands obj))
259 (cl:second (instruction-operands obj)))
260 obj)
261 (cl:call-next-method obj stream)))