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-18 15:41

>>29
RPN just gets you the order of operations. That's trivial stuff. Mapping values to registers and selecting instructions is the interesting part. Relevant links:

https://en.wikipedia.org/wiki/Strahler_number
https://en.wikipedia.org/wiki/Sethi%E2%80%93Ullman_algorithm

And use the standard syntax, not that backwards GNU shit.

>>30
Once you need more storage than available registers then a dataflow-directed method should be far better than "stack emulation", although testing this will be left as an exercise for the reader.

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