procedure DumpRegs;
var
Reg: array [0..7] of LongWord;
SReg: array [0..5] of Word;
EIP: LongWord;
EFLAGS : LongWord;
begin
asm
// save registers while they are not modified by another procedure call.
note that depending
// on your compiler settings, ebp may already be trashed (stack frame)
mov dword ptr Reg[4*0],eax
mov dword ptr Reg[4*1],ecx
mov dword ptr Reg[4*2],edx
mov dword ptr Reg[4*3],ebx
mov dword ptr Reg[4*4],esp // esp is already incorrect since it was
decreased by the amount of stack space the local variables require
mov eax, 16*4+6*2+4+4
add dword ptr Reg[4*4],eax // correct esp
mov dword ptr Reg[4*5],ebp
mov dword ptr Reg[4*6],esi
mov dword ptr Reg[4*7],edi
// save segment registers
mov word ptr SReg[2*0],ds
mov word ptr SReg[2*1],es
mov word ptr SReg[2*2],cs
mov word ptr SReg[2*3],ss
mov word ptr SReg[2*4],fs
mov word ptr SReg[2*5],gs
// save EFLAGS
pushfd
pop dword ptr EFLAGS
// now get eip.
//call $+3 -- $ is considered Hex instead of current line
address
//pop dword ptr EIP -- invalid operand (EIP)
end;
WriteStrLn('EAX = '+HexStr(Reg[0],8));
WriteStrLn('ECX = '+HexStr(Reg[1],8));
WriteStrLn('EDX = '+HexStr(Reg[2],8));
WriteStrLn('EBX = '+HexStr(Reg[3],8));
WriteStrLn('ESP = '+HexStr(Reg[4],8));
WriteStrLn('EBP = '+HexStr(Reg[5],8));
WriteStrLn('ESI = '+HexStr(Reg[6],8));
WriteStrLn('EDI = '+HexStr(Reg[7],8));
WriteStrLn('DS = '+HexStr(SReg[0],8));
WriteStrLn('ES = '+HexStr(SReg[1],8));
WriteStrLn('CS = '+HexStr(SReg[2],8));
WriteStrLn('SS = '+HexStr(SReg[3],8));
WriteStrLn('FS = '+HexStr(SReg[4],8));
WriteStrLn('GS = '+HexStr(SReg[5],8));
WriteStrLn('EFLAGS = '+HexStr(EFLAGS,8));
WriteStrLn('EIP = '+HexStr(EIP,8));
end;Questions:
What's Free Pascal's substitution for $ (used as Hex in FPC, current line address in normal assembler)?
EIP is recognized by the assembler? How come? AFAIK, it's not visible to the programmer. Thus, the above EIP should refer to EIP in the local variables section.
