I'm following the book "Introduction to 64bit Intel Assembly Language Programming for Linux" and one of the tasks is that we should attempt to manually add two floats stored in memory.
In the following solution, I've attempted to calculate the exponent, deducting their respective bias, and then shift each of the floats by them to create a sort of real number which I should be able to add together.
I'm stuck how to feasibly break the sum back into a distinct mantissa and exponent. The book hasn't got to branching, looping, etc. so I'm assuming the author wants this activity done using bit manipulation and integer adding.
; Write an assembly program to perform a product of 2 float values
;; using integer arithmetic and bit operations
;;
;; Start with 2 float values in memory and store the product in memory
;;
segment .data
float_1 dd 12.5
float_2 dd 12.1
segment .bss
float_r resd 1
segment .text
global _start
_start:
;/* Calculate signage */
mov eax, [float_1]
mov ebx, [float_2]
btr eax, 31 ; determine signage of floats
setc cl ; store sign bit in cl of float 1
btr ebx, 31
setc ch ; store sign bit in ch of float 2
;/* Determine exponents */
shr eax, 23 ; exponent of float 1 in eax/ax/al
sub eax, 127 ; deduct bias
shr ebx, 23 ; exponent of float 2 in ebx/bx/bl
sub ebx, 127
;/* Determine mantissas
;* This includes using exponent to create an integer */
mov edx, [float_1]
and edx, 0x7FFFFF ; keep 23 bits at end
bts edx, 23 ; create implicit 1
shl al ; shift it left (/ right if -) based on exponent
mov eex, [float_2]
and eex, 0x7FFFFF
bts eex, 23
shl bl
;/* Combine time */
; idek what to do here
; mov [float_r], ?? ; save result
;/* EOP */
mov eax, 1
xor ebx, ebx
int 0x80
Any help would be appreciated. As indicated, I am learning proper 64bit assembly so any general advice is more than welcome too.