0

So I have to make an assembly functions which would change the way the processor rounds the numbers. I've got that one. Now I need to prove it. So I need to have 1 value to be written to the screen, then change the rounding method, then write the same value and check that it changed on the least significant mantis bits. How then can I f.e write a 3.14 value in IEEE 754 format, like this:

0 10000000 10010001111010111000011

I mean the function can printf it out or it can return it, so I can call that function from C.

minecraftplayer1234
  • 2,127
  • 4
  • 27
  • 57
  • Do you want to write that function in assembly? Or in C? What architecture and operating system are you programming for? – fuz May 20 '17 at 21:30
  • In assembly. I am on Manjaro 64 bit, but I want it to be 32 bit program (therefore I compile with `-m32`) – minecraftplayer1234 May 20 '17 at 21:32

2 Answers2

1

There is no way to output binary with printf. If you need to do that you'll have to write your own function. This has already been covered on SO, e.g. here.

If you want to break down the components of a float (IEEE 754 single precision), then you can use a union a bit like this:

union float_bits
{
   float f;
   struct bits
   {
      unsigned int s:1;
      unsigned int m:23;
      unsigned int e:8;
   } b;
};

You would then load your float into f and read the sign/mantissa/exponent from b.s/b.m/b.e.

Community
  • 1
  • 1
Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
0

You can copy the value of the FPU registry to memory using FST instruction, load it into CPU registers (C local variable) using MOV instruction (assuming you're under x86 architecture)

Keep in mind, that FPU registers have 80 bits

ekaerovets
  • 1,158
  • 10
  • 18