Author Topic: Treating x86 as it was a 6502 with 32bit operands only  (Read 1441 times)

Offline skypilot

  • New Member
  • Posts: 1
Treating x86 as it was a 6502 with 32bit operands only
« on: July 30, 2016, 11:15:38 PM »
What instructions and register would you use, if you would treat the x86 as a 6502? But instead of only having 8bit instructions, you only has 32bit instructions.

As a total newbie, with some 6402 experience. I would lite to start with only learning a subset of x86,  and also study exactly what machine code that it generates.

Could you say that eax is the accumulator.  But what register would be used as a index register, as a offset form a given address? could ebx be used for that? But how would the assembly code look if you take a label as a base pointer and want to add that with a index register (ebx?) as an offset?

And is there any old school document on how to program 32bit programs without usage of 16bit addresses? I'm not quite sure where to learn this stuff.


 

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Treating x86 as it was a 6502 with 32bit operands only
« Reply #1 on: August 11, 2016, 03:21:25 AM »
Breaking x86 up into smaller portions is smart, I'd start by focusing on the integer instructions, then work up to floating-point instructions as needed. Later, you could pick up more advanced extensions of the x86.

The general purpose registers on the 32-bit x86 are EAX, EBX, ECX, EDX, ESI, and EDI. These can be used for pretty much anything, but several are treated specially by certain instructions. For example; ECX, ESI, and EDI are used by the REP MOVSB instruction to move the number of bytes specified in ECX from the memory location referenced by ESI to the memory location referenced by EDI. However, in most cases you can use these registers for anything you want, which is why they are called "general purpose". ESP and EBP are used to manage the stack frame so it's not recommended that you use them for anything else.

EAX:Accumulator Register
EBX:Base Register
ECX:Counter Register
EDX:Data Register
ESI:Source Index Register
EDI:Destination Index Register
ESP:Stack Pointer Register
EBP:Stack Base Pointer Register

If you're planning on doing some old-school stuff, I suggest you look to some old school documents. Bad joke aside, that college archive has a lot of really nice documentation, lectures and examples. If you look at some of the archives you'll find a huge list of examples from first steps to a Wolfenstein-3D clone called Everitt-3D. There is a GitHub repository uploaded by Peter Johnson which has a lot of the files (including pmodelib) which are a bit harder to find now-a-days.

About Bryant Keller
bkeller@about.me