Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How to compile arithmetic expressions to x86?

Name: Anonymous 2015-07-10 21:16

hi prog, say I want to take as given some variables on the stack x,y,z,w and compile expressions (x+y)*(z+w) to x86 asm.

first off the instructions take registers or pointers and well x86 is weird and has instructions like this:

add x, y ;x OR y must be a register, result in x
mul x ;multiplies eax with x, result is put into eax


so this would work:

mov eax, stack0
add eax, stack1
mov ebx, stack2
add ebx, stack3
mul ebx


but how would you make an algorithm to do this in general?

Name: Cudder !cXCudderUE 2015-07-11 13:41

>>6
If you don't need to use memory then don't. Start using memory only when it doesn't all fit into registers - and arrange things suitably so that the values that are used first/most are the ones that get chosen for registers first. That's all there is to it.

It is also not fun at all to debug code for architectures with limited registers because an optimal register scheduling scheme will destroy even very recent and useful intermediate values with great eagerness.
I have no idea WTF you're complaining about. "It's too hard to debug"? It should be. This is not BASIC. If you're working at Asm level and worrying about debugging then YOU ARE DOING IT WRONG.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List