Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I know when switching from MIPS to x86 assembly?

Tags:

x86

assembly

mips

At school we have been programming in MIPS assembly language for some time. I'm interested into delving into x86 assembly and I have heard that is somewhat harder (even my MIPS textbook says this).

What core information should I know as a MIPS programmer before making the dive into the x86 world?

like image 647
mmcdole Avatar asked Jan 17 '09 21:01

mmcdole


People also ask

Is MIPS same as x86?

x86 have more complex instructions than MIPS. So there is probably a single instruction for common sequences in MIPS (most notably memory addressing).

What is the actual difference between x86 ARM and MIPS architectures?

What is the difference between MIPS and ARM? MIPS and ARM are two different instruction set architectures in the family of RISC instruction set. Although both the instruction sets have a fixed and same instruction size, ARM has only 16 registers while MIPS has 32 registers.

What is the difference between MIPS and Assembly?

MIPS is a company that makes processors and the name of the ISA and the name of the Assembly Language and the processors will all bear the name MIPS. Just like Intel processors, Assembly Language and instruction set can be properly called Intel (although we also see x86 and other variations).


2 Answers

The biggest things to keep in mind are:

  • Few general purpose registers, and the ones you do have are not pure GP -- many instructions require you to use certain registers for a specific purpose.
  • x86 instructions are two-opcode form rather than three-opcode which can make certain operations more complex. That is, instead of add r0, r1, r2 (r0 = r1 + r2), you do add eax, ebx (eax += ebx).
  • Segments in protected mode (all 32-bit code outside of DOS, effectively) make your memory addressing scheme extremely non-obvious, which can bite you in the ass when you're starting out.
  • You're going to be looking up the flags set/cleared by instructions all the time. Learn to love the Intel manuals.
  • Edit, one thing I forgot: The use of subregisters (e.g. ah to access the high 8 bits of the low 16-bits of the eax register) can make tracking manipulations to your registers very difficult. Be careful and comment liberally until you get things down.

Other than that, x86 is pretty straight forward. When you learn to abuse instructions like 'lea' and 'test', you learn to love it. Also, protip: Intel will send you copies of the instruction set manuals for free, don't even have to pay for shipping. Look around their site for the fulfillment email and request the books by SKU.

like image 63
Serafina Brocious Avatar answered Sep 20 '22 22:09

Serafina Brocious


x86 has a very limited set of available registers compared to most other architectures. This doesn't really make the assembly language any harder to learn, but sometimes makes it harder to implement code in practice.

Also, because of the x86 history of strong backward compatibility, the instruction set is not terribly symmetric (definitely pre-RISC) and there can be lots of exceptions to the rule and corner cases to pay attention to.

like image 21
Greg Hewgill Avatar answered Sep 19 '22 22:09

Greg Hewgill