Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which 32-bit/64-bit CPU architecture has the easiest instruction set?

I feel extremely comfortable dealing with 32-bit PowerPC assembly code, but I am completely lost when trying to make sense of x86 code. Do any of the other common architectures like ARM, MIPS, Sparc etc have an easier than x86 instruction set?

like image 634
sigjuice Avatar asked Sep 05 '09 06:09

sigjuice


2 Answers

Well, most RISCs are very much alike, so if you know the PPC well, then transitioning to ARM, MIPS, or SPARC will all be a snap. I actually learnt SPARC first and then was able to pick up a MIPS and the PPC in a couple of hours.

The thing that makes the x86 so confusing isn't really its assembly language, but the design of the processor. People tend to get hung up on:

  • Segmented memory addressing -- all those ds, cs, es registers: what do they mean, how are they combined with an index register to make a fully resolved memory address? There's actually three different ways that happens, so you're learning a bunch of different modes.
  • Nonorthogonal instruction set -- some instructions only work with certain registers, other instructions have meanings that overlap, some things look like they should be fast but are really slow, etc.
  • Register-memory architecture -- the x86 is designed to have few (named) registers, so that each opcode usually has one argument that is a register and another argument that is a memory address. This is different from the PPC's load-store arch, where the memory operations are explicit. Since the stack pointer tends to bounce around a lot, this can make it hard to figure out which variable is really being used!
  • Spastic stack pointer -- where most PPC calling conventions have you move the stack pointer just once on entering a function and then once when returning, typically x86 code will be pushing and popping all over the place. You end up counting the pushes and pops to figure out just where your stack pointer has gotten to, which always makes my head hurt.

So, to get comfortable with the x86, divide and conquer: pick one of those points, learn how it works, then move on to the next. It may help to start by learning the calling conventions first, because that'll make all the other instructions that reference the stack pointer make more sense.

like image 97
Crashworks Avatar answered Oct 01 '22 22:10

Crashworks


Without a definition of "easy" im pretty sure most people would agree that the x86 instruction set is easily the most horrible for a mainstream popular CPU.

If one were to write up a list of good or best practices one should follow when designing an instruction set, the x86 would be a good example of all the opposites.

  • Not orthogonal, not all registers are equal in functionality.
  • Small limited number of specialised registers - results in too many stack operations.
  • Nasty prefix operators.
  • ...
like image 36
mP. Avatar answered Oct 01 '22 20:10

mP.