Questions tagged [x87]

x87 is the legacy 80bit floating point subset of the x86 instruction set. It's obsoleted by SSE/SSE2 for float/double, but is still useful for 80bit extended precision. The 32bit x86 ABI also returns FP results in an x87 register. See the tag wiki for a tutorial link.

See the wiki for links, including the most useful one: http://www.ray.masmcode.com/tutorial/index.html.

249 questions
3
votes
3 answers

How to divide floating-point number in x86 assembly?

When i try to write Heron algorithm to count sqrt from ECX register, it doesn't work. It looks like the problem is dividing floating numbers, because the result is integer. My algorithm: sqrtecx: MOV EDX, 10 ; loop count MOV EAX, 5 ; x_0 in…
Mieszko Mikulski
  • 119
  • 1
  • 2
  • 3
3
votes
1 answer

x86 Assembly How to properly get XMM0 into ST0?

A wonderful Sunday everyone. I am currently learning a lot of assembly in the 32-bit environment (currently Windows). I am using FASM for this. I have the following code which I successfully made but I'm quite unhappy with the way I load XMM0 into…
Zvend
  • 33
  • 3
3
votes
0 answers

Assembly language initialization of floating-point unit

Just out of curiosity I'm fiddling around with some demoscene 256 byte intros. I came around one production which ran fine under MS-DOS 6.22 but crashes under FreeDOS 1.3 - "sometimes". It turned out that it ran fine when executed after some other…
Codor
  • 17,447
  • 9
  • 29
  • 56
3
votes
1 answer

Fast float-to-int formula with rounding toward -Inf: how does it work?

I've been playing around with x87 FPU programming,and I just came across the following magic spell for converting from float (32-bit) to int (32-bit): flds from # number to convert from fadds magic1 # add magic…
user1636349
  • 458
  • 1
  • 4
  • 21
3
votes
2 answers

Basic FPU instructions/stack overview?

I'm trying to get a basic understanding of floating point operations on x86. I understand that we have a dedicated FPU with a stack, but I'm not finding much relevant information on how the stack behaves in terms of different…
ProdigySim
  • 2,825
  • 1
  • 21
  • 17
3
votes
1 answer

MASM doesn't insert x87 WAIT prefixes with some combinations of CPU and FPU directives

Masm allows different cpu combinations before instructions but certain combinations do not correctly detect coprocessor instructions that require a wait prefix and will cause no wait prefix when a wait prefix is required. The following combinations…
3
votes
1 answer

Assembly Language equivalent to Ceil , Floor

What is the x86 equivalent of ceil , floor ? I can't particularly google the corresponding instructions . The equivalent may not necessarily be a one instruction though one instruction would be preferred.
Apoorv Jain
  • 113
  • 9
3
votes
1 answer

Porting MASM5 code in Quake 2 to GAS -- Unexpected rendering results

I am porting Quake 2's inline assembly code for MSVC to MASM then finally to GAS (for use with MinGW). The specific code in question is for the Skin drawing (R_PolysetCalcGradients for those who want to look it up). The code almost "works" what…
Maraakate
  • 81
  • 4
3
votes
2 answers

Objdump swapping fsubrp to fsubp on compiled assembly?

I am porting Quake 2's inline Win32 assembly to GAS. I started out by taking the inline assembly and then placing it into it's own ASM file. Fixed any issues, then started porting to GAS. I do know that the src/dst is reversed in AT&T vs Intel…
Maraakate
  • 81
  • 4
3
votes
2 answers

Call printf with x87 float

I have a simple program in x86 asm, which makes z = x/y. The thing is, the code should be written correctly when it comes to division, but nothing is printed. There is no output. I have no idea what's wrong, because I can't debug when the program…
J.G.
  • 103
  • 1
  • 6
3
votes
1 answer

Loading and storing long doubles in x86-64

I noticed a weird thing today. When copying a long double1 all of gcc, clang and icc generate fld and fstp instructions, with TBYTE memory operands. That is, the following function: void copy_prim(long double *dst, long double *src) { *src =…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
3
votes
1 answer

MMX Instructions and the x87 FPU Tag Word

section .data qVar1: dq 1 section .bss var28: resb 28 section .text _main: ; Use an MMX instruction movq mm0, [qVar1] ; Move quadword from r/m64 to mm. ; Read Tag Word fstenv [var28] …
Bite Bytes
  • 1,455
  • 8
  • 24
3
votes
3 answers

How to load the value stored in extended register(eax) into st0 of floating point stack?

How do I load the value stored in extended register(eax) into st0 of floating point stack? fld dword [eax] When I use the above instruction, I do not get the desired change in transfer maybe because the bracket signs have something to do with…
Sahay
  • 39
  • 1
  • 4
3
votes
1 answer

Using FPU with C inline assembly

I wrote a vector structure like this: struct vector { float x1, x2, x3, x4; }; Then I created a function which does some operations with inline assembly using the vector: struct vector *adding(const struct vector v1[], const struct vector v2[],…
demoo
  • 111
  • 2
  • 3
  • 11
3
votes
2 answers

Cube root on x87 FPU using Newton-Raphson method

I am trying to write an assembly program using the 8086 processor that will find the cube root of a number. Obviously I am using floating points. Algorithm based upon Newton-Raphson method: root := 1.0; repeat oldRoot := root; root :=…
GeekyDewd
  • 321
  • 1
  • 2
  • 18