In general, if I'm told to undress and then handed a gown, I'd remove underwear from the start. However, I think it would depend on where I'm at and the reason for my exam. If I'm at a cardiologist, I'd probably leave my underwear on. If at a urologist or proctologist, I'd obviously take them off too.
In the past, it was never an issue for me, I was always told what to do. Typically, I'm handed a gown and told, “Everything off but your underwear”, or “Opening in the back. You can leave your underwear on”, or some other version of this phrase. On a side note, I LOVE being told these instructions by a nurse or MA!
However, I have had this quandary in the last few years at my dermatologist. When I first started going there, I was always told by the nurse to “get undressed. Take everything off”. That's about as direct as you can get to remove your underwear too. Then suddenly one year, the nurse laid out a gown and said “Get undressed. You *can leave on your underwear.” She kind of stressed the word “can”, so hesitantly I removed them also, since that's what I had always previously done there. The next year, the nurse kind of awkwardly told me, “Go ahead and get undressed. Take off what you're comfortable with. Just know that whatever you leave on, the doctor won't look underneath. So if you leave on, say, your socks, the doctor won't look under your socks or have you remove them.” It was a very awkward instruction from her. I, again, took off my underwear. The last two or three years, the gown is placed on the table, and I'm told to, “Get undressed.” No other specific or vague instructions given. So far, I've always taken off my underwear from the start. Always placed right on top of my pile of clothes.