============================================================ Using DEBUG to trace the CALL instruction ============================================================ -Ian! D. Allen - idallen@idallen.ca - www.idallen.com # Output from a debug script (call_push.txt) showing how CALL places # values on the stack. These comments (prefixed by '#') were added to # the script output file by hand, to explain what is going on. # First, fill memory with 2000h zeroes, to make things easier to see. # For the same reason, fill some of the stack area with zeroes. -f 0100 l 2000 00 -f ffe0 l 20 00 # Assemble a small circular sequence of CALL instructions at four # different locations in memory. The last CALL calls the first again. -a 0100 1426:0100 call 1234 1426:0103 -a 1234 1426:1234 call 5678 1426:1237 -a 5678 1426:5678 call 9abc 1426:567B -a 9abc 1426:9ABC call 1234 # Circular! (Don't run this program!) 1426:9ABF # Show the initial state of the registers and stack. Note that this # CALL instruction is a 3-byte instruction, so the IP goes up by 3 # before it gets pushed on the stack. The size of the IP is 2 # bytes, so pushing it makes the SP go down by 2 on each CALL. -r AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=1426 ES=1426 SS=1426 CS=1426 IP=0100 NV UP EI PL NZ NA PO NC 1426:0100 E83111 CALL 1234 -d ffe0 1426:FFE0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 1426:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ # Trace the CALL. See the IP and SP change. See the stack memory change. # IP: 0100 -> 0103 # SP: FFEE -> FFEC # [SP] = 0103 (IP) # IP = 1234 -t AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEC BP=0000 SI=0000 DI=0000 DS=1426 ES=1426 SS=1426 CS=1426 IP=1234 NV UP EI PL NZ NA PO NC 1426:1234 E84144 CALL 5678 -d ffe0 1426:FFE0 00 00 00 00 00 00 34 12-26 14 AB 0D 03 01 00 00 ......4.&....... 1426:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ # Trace the CALL. See the IP and SP change. See the stack memory change. # IP: 1234 -> 1237 # SP: FFEC -> FFEA # [SP] = 1237 (IP) # IP = 5678 -t AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEA BP=0000 SI=0000 DI=0000 DS=1426 ES=1426 SS=1426 CS=1426 IP=5678 NV UP EI PL NZ NA PO NC 1426:5678 E84144 CALL 9ABC -d ffe0 1426:FFE0 00 00 00 00 78 56 26 14-AB 0D 37 12 03 01 00 00 ....xV&...7..... 1426:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ # Trace the CALL. See the IP and SP change. See the stack memory change. # IP: 5678 -> 567B # SP: FFEA -> FFE8 # [SP] = 567B (IP) # IP = 9ABC -t AX=0000 BX=0000 CX=0000 DX=0000 SP=FFE8 BP=0000 SI=0000 DI=0000 DS=1426 ES=1426 SS=1426 CS=1426 IP=9ABC NV UP EI PL NZ NA PO NC 1426:9ABC E87577 CALL 1234 -d ffe0 1426:FFE0 00 00 BC 9A 26 14 AB 0D-7B 56 37 12 03 01 00 00 ....&...{V7..... 1426:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ # Trace the CALL. See the IP and SP change. See the stack memory change. # IP: 9ABC -> 9ABF # SP: FFE8 -> FFE6 # [SP] = 9ABF (IP) # IP = 1234 -t AX=0000 BX=0000 CX=0000 DX=0000 SP=FFE6 BP=0000 SI=0000 DI=0000 DS=1426 ES=1426 SS=1426 CS=1426 IP=1234 NV UP EI PL NZ NA PO NC 1426:1234 E84144 CALL 5678 -d ffe0 1426:FFE0 34 12 26 14 AB 0D BF 9A-7B 56 37 12 03 01 00 00 4.&.....{V7..... 1426:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ # Trace the CALL. See the IP and SP change. See the stack memory change. # IP: 1234 -> 1237 # SP: FFE6 -> FFE4 # [SP] = 1237 (IP) # IP = 5678 -t AX=0000 BX=0000 CX=0000 DX=0000 SP=FFE4 BP=0000 SI=0000 DI=0000 DS=1426 ES=1426 SS=1426 CS=1426 IP=5678 NV UP EI PL NZ NA PO NC 1426:5678 E84144 CALL 9ABC -d ffe0 1426:FFE0 26 14 AB 0D 37 12 BF 9A-7B 56 37 12 03 01 00 00 &...7...{V7..... 1426:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ # Trace the CALL. See the IP and SP change. See the stack memory change. # IP: 5678 -> 567B # SP: FFE4 -> FFE2 # [SP] = 567B (IP) # IP = 9ABC -t AX=0000 BX=0000 CX=0000 DX=0000 SP=FFE2 BP=0000 SI=0000 DI=0000 DS=1426 ES=1426 SS=1426 CS=1426 IP=9ABC NV UP EI PL NZ NA PO NC 1426:9ABC E87577 CALL 1234 -d ffe0 1426:FFE0 AB 0D 7B 56 37 12 BF 9A-7B 56 37 12 03 01 00 00 ..{V7...{V7..... 1426:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ # Trace the CALL. See the IP and SP change. See the stack memory change. # IP: 9ABC -> 9ABF # SP: FFE2 -> FFE0 # [SP] = 9ABF (IP) # IP = 1234 -t AX=0000 BX=0000 CX=0000 DX=0000 SP=FFE0 BP=0000 SI=0000 DI=0000 DS=1426 ES=1426 SS=1426 CS=1426 IP=1234 NV UP EI PL NZ NA PO NC 1426:1234 E84144 CALL 5678 -d ffe0 1426:FFE0 BF 9A 7B 56 37 12 BF 9A-7B 56 37 12 03 01 00 00 ..{V7...{V7..... 1426:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ # We now have pushed seven return addresses on the stack, through # seven consecutive CALL instructions. (If we let this program run, # the stack would eventually overwrite the code and it would die.) # All done! -q