I'm back, and now I really want to learn Assembly very well, but as I already know much about the base of x86 Assembly and all his opcodes, I want to solve the question that I always ask for myself: How to know the correct register to use?

Then I want someone that can help me with this BIG question.

PS: I want 16-Bits Registers

Best Regards,
Nathan Paulino Campos
Posted on 2010-03-26 18:51:39 by nathanpc
That do you mean? Registers are just memory - you use them as you need them. It's true, for example, that (R/E)SP is used as the stack pointer, but as long as you know what you're doing, you can use any register for anything. And this is even more true in 64-bit where you have more of them.

Please specify your question.
Posted on 2010-03-27 01:46:28 by ti_mo_n
"... as long as you know what you're doing..." I deduce that's what he's trying to figure out! :)

Certain instructions implicitly use certain registers. "mul and "div" come to mind, the "adjust" instructions, the "string" instructions, "loop", "rep", "shl reg, cl"... Besides "push" and "pop", "call" and "ret" use the stack - and sp... If we're using any of those instructions, we don't have much choice.

What's worse, 16-bit instructions are picky about addressing modes. Our "base" registers are bx and bp (bp being "special" in that it defaults to using ss:, instead of ds: like the rest of 'em). Our "index" registers are si and di. An effective address can include an (optional) offset/displacement, plus an (optional) base register, plus an (optional) index register. That's it! "" is not valid! (note that these registers - bx, bp, si, and di - are the ones C expects to be preserved across function calls) So if you're doing some addressing, you may want to "set aside" some of these registers for that.

All the registers left over after all that (if any) are good to use! :)

If you have a specific situation in mind, drag it out!


Posted on 2010-03-27 03:48:01 by fbkotler
Thanks guys, I'm going to do some tries and then I will see if itworks. :D
Posted on 2010-03-27 06:20:17 by nathanpc