about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--subx/014index_addressing.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/subx/014index_addressing.cc b/subx/014index_addressing.cc
index 8ab545d3..e811290d 100644
--- a/subx/014index_addressing.cc
+++ b/subx/014index_addressing.cc
@@ -69,3 +69,47 @@ uint32_t effective_address_from_sib(uint8_t mod) {
 +run: effective address is initially 0x60 (disp32)
 +run: effective address is 0x60
 +run: storing 0x00000011
+
+//:
+
+:(scenario add_r32_to_mem_at_base_r32_index_r32_plus_disp8)
+% Reg[3].i = 0x10;  // source
+% Reg[0].i = 0x59;  // dest base
+% Reg[1].i = 0x5;  // dest index
+% SET_WORD_IN_MEM(0x60, 1);
+# op  ModR/M  SIB   displacement  immediate
+  01  5c      08    02                       # add EBX to *(EAX+ECX+2)
+# ModR/M in binary: 01 (indirect+disp8 mode) 011 (src EBX) 100 (dest in SIB)
+# SIB in binary: 00 (scale 1) 001 (index ECX) 000 (base EAX)
++run: add EBX to r/m32
++run: effective address is initially 0x59 (EAX)
++run: effective address is 0x5e (after adding ECX*1)
++run: effective address is 0x60 (after adding disp8)
++run: storing 0x00000011
+
+:(before "End Mod 1 Special-cases(addr)")
+case 4:  // exception: mod 0b01 rm 0b100 => incoming SIB (scale-index-base) byte
+  addr = effective_address_from_sib(mod);
+  break;
+
+//:
+
+:(scenario add_r32_to_mem_at_base_r32_index_r32_plus_disp32)
+% Reg[3].i = 0x10;  // source
+% Reg[0].i = 0x59;  // dest base
+% Reg[1].i = 0x5;  // dest index
+% SET_WORD_IN_MEM(0x60, 1);
+# op  ModR/M  SIB   displacement  immediate
+  01  9c      08    02 00 00 00              # add EBX to *(EAX+ECX+2)
+# ModR/M in binary: 10 (indirect+disp32 mode) 011 (src EBX) 100 (dest in SIB)
+# SIB in binary: 00 (scale 1) 001 (index ECX) 000 (base EAX)
++run: add EBX to r/m32
++run: effective address is initially 0x59 (EAX)
++run: effective address is 0x5e (after adding ECX*1)
++run: effective address is 0x60 (after adding disp32)
++run: storing 0x00000011
+
+:(before "End Mod 2 Special-cases(addr)")
+case 4:  // exception: mod 0b10 rm 0b100 => incoming SIB (scale-index-base) byte
+  addr = effective_address_from_sib(mod);
+  break;
ef='#n171'>171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330