How do I subtract a decimal value in assembly. IA32 (linux)
1: mov edx, 1/2
sub ecx, ebx
sub ecx, edx
mov bal2, ecx
I tried this but it some how skips the subtraction with the decimal.
And if I enter .5 it gives me an error.
error:junk `.5′ after expression
As lightbulbone correctly says in his answer, you cannot work on floating point values when using general purpose registers (
eaxetc.). You could use the FPU, as lightbulbone suggests, but that is comparatively tedious.Alternatively – unless your code needs to run on ancient CPUs – you can use the SSE instructions for this task, which is much more straightforward. Code similar to what you are showing might look like the following: