From 8a0268317fbce2baa2e5119c796750ea6c80a813 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 18 Oct 2017 02:27:56 -0700 Subject: 4084 subx: extract helpers for 'push' and 'pop'. We will be using them in 'call' and 'ret' as well. --- html/subx/012indirect_addressing.cc.html | 75 +++++++++++++++----------------- 1 file changed, 34 insertions(+), 41 deletions(-) (limited to 'html/subx/012indirect_addressing.cc.html') diff --git a/html/subx/012indirect_addressing.cc.html b/html/subx/012indirect_addressing.cc.html index 35dd62ab..781b9ad2 100644 --- a/html/subx/012indirect_addressing.cc.html +++ b/html/subx/012indirect_addressing.cc.html @@ -412,53 +412,46 @@ if ('onhashchange' in window) { 347 % Reg[ESP].u = 0x14; 348 # op ModRM SIB displacement immediate 349 ff 30 # push *EAX (reg 0) to stack -350 +run: push effective address +350 +run: push effective address 351 +run: effective address is mem at address 0x60 (reg 0) -352 +run: ESP is now 0x00000010 -353 +run: contents at ESP: 0x000000af +352 +run: decrementing ESP to 0x00000010 +353 +run: pushing value 0x000000af 354 355 :(before "End Op ff Subops") 356 case 6: { 357 trace(2, "run") << "push effective address" << end(); 358 const int32_t* val = effective_address(modrm); -359 trace(2, "run") << "pushing value 0x" << HEXWORD << *val << end(); -360 Reg[ESP].u -= 4; -361 *reinterpret_cast<uint32_t*>(&Mem.at(Reg[ESP].u)) = *val; -362 trace(2, "run") << "ESP is now 0x" << HEXWORD << Reg[ESP].u << end(); -363 trace(2, "run") << "contents at ESP: 0x" << HEXWORD << *reinterpret_cast<uint32_t*>(&Mem.at(Reg[ESP].u)) << end(); -364 break; -365 } -366 -367 //:: pop -368 -369 :(scenario pop_mem_at_r32) -370 % Reg[0].i = 0x60; -371 % Reg[ESP].u = 0x10; -372 % SET_WORD_IN_MEM(0x10, 0x00000030); -373 # op ModRM SIB displacement immediate -374 8f 00 # pop stack into *EAX (reg 0) -375 +run: pop into effective address -376 +run: effective address is mem at address 0x60 (reg 0) -377 +run: storing 0x00000030 -378 +run: ESP is now 0x00000014 -379 -380 :(before "End Single-Byte Opcodes") -381 case 0x8f: { // pop stack into r/m32 -382 uint8_t modrm = next(); -383 uint8_t subop = (modrm>>3)&0x7; -384 switch (subop) { -385 ¦ case 0: { -386 ¦ ¦ trace(2, "run") << "pop into effective address" << end(); -387 ¦ ¦ int32_t* dest = effective_address(modrm); -388 ¦ ¦ *dest = *reinterpret_cast<uint32_t*>(&Mem.at(Reg[ESP].u)); -389 ¦ ¦ trace(2, "run") << "storing 0x" << HEXWORD << *dest << end(); -390 ¦ ¦ Reg[ESP].u += 4; -391 ¦ ¦ trace(2, "run") << "ESP is now 0x" << HEXWORD << Reg[ESP].u << end(); -392 ¦ ¦ break; -393 ¦ } -394 } -395 break; -396 } +359 push(*val); +360 break; +361 } +362 +363 //:: pop +364 +365 :(scenario pop_mem_at_r32) +366 % Reg[0].i = 0x60; +367 % Reg[ESP].u = 0x10; +368 % SET_WORD_IN_MEM(0x10, 0x00000030); +369 # op ModRM SIB displacement immediate +370 8f 00 # pop stack into *EAX (reg 0) +371 +run: pop into effective address +372 +run: effective address is mem at address 0x60 (reg 0) +373 +run: popping value 0x00000030 +374 +run: incrementing ESP to 0x00000014 +375 +376 :(before "End Single-Byte Opcodes") +377 case 0x8f: { // pop stack into r/m32 +378 uint8_t modrm = next(); +379 uint8_t subop = (modrm>>3)&0x7; +380 switch (subop) { +381 ¦ case 0: { +382 ¦ ¦ trace(2, "run") << "pop into effective address" << end(); +383 ¦ ¦ int32_t* dest = effective_address(modrm); +384 ¦ ¦ *dest = pop(); +385 ¦ ¦ break; +386 ¦ } +387 } +388 break; +389 } -- cgit 1.4.1-2-gfad0