how to successfully look at contents of 386 segment registers

Started by DaveM, September 10, 2009, 12:46:57 PM

Previous topic - Next topic

DaveM

I'm actually only interested in looking at the 'old' registers from the 8086 (which didn't have FS and GS). I tried to look at ES and thought the VKDebug macro would do it:

PrintHex ES,"ES"

That seems to crash. Is PrintHex only meant to work with the 8 'normal registers'?

(I was trying to find out where my REP STOSB was actually writing to hence why I wanted to know if ES was set right.)


DaveM

Thanks. It does appear that doing:

PrintHex DS,  "message"

or

PrintHex ES, "message"

does reliably cause an exception. I haven't tried the other segment registers, but I basically did what you suggested and shoved it into AX first which the macro has no problem with.

It turns out that my REP STOSB instuction was causing an exception not because ES:[EDI] was wrong, but because I had set the count register by using CX instead of ECX.

Getting back into x86 I'm finding a lot of the bugs I'm creating in my code are all to do with inappropriate choices of 16 bit vs. 32 bit versions of the register set.

hutch--

Dave M,

If it is 32 bit code you are writing, you in fact leave the sement registers alone as the entire 32 bit address space is set as FLAT memory model, OFFSET 0 to 4 gig. Normally using a SEGMENT/OFFSET mode of adedressing is incorrect in FLAT memory model. To share the misery with you, when I first started writing 32 bit code I had similar fun.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

DaveM

Thanks Hutch, that's actually very reassuring to me (I'm not being sarcastic - honest)

Actually I did look at the MASM32 help topics and noted what it said about FLAT. FLAT sounds nice to me - sounds so good to program with I'm wondering how is it possible on an Intel chip  :lol

But then I got confused because when I dumped the segment registers they were not zero for sure, but after studying the Microsoft Press Ross P Nelson book, I now get what that means. The segment registers are actually selectors that index a segment desciptor table - vastly different to the old days on a real 8086/88 they merely contained  FFFF-0000 and you just shifted left four bits and you have the absolute base address of the segment.

I can recommend that book, it's damn good. That guy emphasizes the effect the Multics project had on the 386 design - he gives a lot of background as well as providing a comprehensive technical reference.