I am trying to compile the following assembly code with command:
nasm -f elf AvxScalarFloatingPointArithmetic_.asm
Assembly code:
.model flat,c
.const
AbsMask qword 7fffffffffffffffh, 7fffffffffffffffh
.code
; extern "C" void AvxSfpArithmetic_(double a, double b, double results[8]);
;
; Description: The following function demonstrates how to use basic
; scalar DPFP arithmetic instructions.
;
; Requires: AVX
AvxSfpArithmetic_ proc
push ebp
mov ebp,esp
; Load argument values
mov eax,[ebp+24] ;eax = ptr to results array
vmovsd xmm0,real8 ptr [ebp+8] ;xmm0 = a
vmovsd xmm1,real8 ptr [ebp+16] ;xmm1 = b
; Perform basic arithmetic using AVX scalar DPFP instructions
vaddsd xmm2,xmm0,xmm1 ;xmm2 = a + b
vsubsd xmm3,xmm0,xmm1 ;xmm3 = a - b
vmulsd xmm4,xmm0,xmm1 ;xmm4 = a * b
vdivsd xmm5,xmm0,xmm1 ;xmm5 = a / b
vmovsd real8 ptr [eax+0],xmm2 ;save a + b
vmovsd real8 ptr [eax+8],xmm3 ;save a - b
vmovsd real8 ptr [eax+16],xmm4 ;save a * b
vmovsd real8 ptr [eax+24],xmm5 ;save a / b
; Compute min(a, b), max(a, b), sqrt(a) and fabs(b)
vminsd xmm2,xmm0,xmm1 ;xmm2 = min(a, b)
vmaxsd xmm3,xmm0,xmm1 ;xmm3 = max(a, b)
vsqrtsd xmm4,xmm0,xmm0 ;xmm4 = sqrt(a)
vandpd xmm5,xmm1,xmmword ptr [AbsMask] ;xmm5 = fabs(b)
vmovsd real8 ptr [eax+32],xmm2 ;save min(a, b)
vmovsd real8 ptr [eax+40],xmm3 ;save max(a, b)
vmovsd real8 ptr [eax+48],xmm4 ;save sqrt(a)
vmovsd real8 ptr [eax+56],xmm5 ;save trunc(sqrt(a))
pop ebp
ret
AvxSfpArithmetic_ endp
end
Unfortunatelly there are some errors:
AvxScalarFloatingPointArithmetic_.asm:1: error: attempt to define a local label before any non-local labels
AvxScalarFloatingPointArithmetic_.asm: error: parser: instruction expected
AvxScalarFloatingPointArithmetic_.asm:2: error: attempt to define a local label before any non-local labels
AvxScalarFloatingPointArithmetic_.asm:3: error: parser: instruction expected
AvxScalarFloatingPointArithmetic_.asm:13: error: parser: instruction expected
How should I compile this file? The code should be correct. It is from the book: "Modern X86 Assembly Language Programming: 32-bit, 64-bit, SSE, and AVX".