1

I have a MASM program which uses AVX but I get errors when I try to assemble it with JWASM (a MASM clone). I couldn't find any directives to properly assemble the AVX instructions (like .mmx or .xmm).

.686
.xmm
.model flat,c

.code

AVXPackedInt_16 proc
; Prologo funzione
    push ebp
    mov ebp,esp

; Carica Argomento
    mov eax,[ebp+8]                         ; eax = pointer to a
    mov ecx,[ebp+12]                        ; ecx = pointer to b
    mov edx,[ebp+16]                        ; edx = pointer to res

    vmovdqa ymm0,ymmword ptr [eax]          ; Usando questa istruzione dobbiamo allineare rispetto ad un limite di 32-bit.      ymm0 = a
    vmovdqa ymm1,ymmword ptr [ecx]          ; ymm1 = b

; Addizione
    vpaddw ymm2,ymm0,ymm1                   ; ymm2 = ymm0 + ymm1, wraparound
    vpaddsw ymm3,ymm0,ymm1                  ; ymm3 = ymm0 + ymm1, signed saturation

; Sottrazione
    vpsubw ymm4,ymm0,ymm1                   ; ymm4 = ymm0 - ymm1, wraparound
    vpsubsw ymm5,ymm0,ymm1                  ; ymm5 = ymm0 - ymm1, signed saturation

; Valore Minimo
    vpminsw ymm6,ymm0,ymm1                  ; Valore Minimo con Segno

; Valore Massimo
    vpmaxsw ymm7,ymm0,ymm1                  ; Valore Massimo con Segno

; Salva Risultati
    vmovdqa ymmword ptr [edx],ymm2          ; Salva "ymm0 + ymm1, wraparound" dentro la memoria puntata da "edx" cioe` res[0]
    vmovdqa ymmword ptr [edx+32],ymm3       ; Salva "ymm0 + ymm1, signed saturation"
    vmovdqa ymmword ptr [edx+64],ymm4       ; Salva "ymm0 - ymm1, wraparound"
    vmovdqa ymmword ptr [edx+96],ymm5       ; Salva "ymm0 - ymm1, signed saturation"
    vmovdqa ymmword ptr [edx+128],ymm6      ; Salva "valore minimo con segno"
    vmovdqa ymmword ptr [edx+160],ymm7      ; Salva "valore massimo con segno"

    vzeroupper                              ; Pone a zero i 128 bits di ordine maggiore di tutti i registri ymm salvando da penalita' riguardanti le performance

    pop ebp
    ret

AVXPackedInt_16 endp

AVXPackedInt_32 proc
; Prologo Funzione
    push ebp
    mov ebp,esp

; Carico Argomenti
    mov eax,[ebp+8]                         ; eax = pointer to a
    mov ecx,[ebp+12]                        ; ecx = pointer to b
    mov edx,[ebp+16]                        ; edx = pointer to res

    vmovdqa ymm0,ymmword ptr [eax]          ; Usando questa istruzione dobbiamo allineare rispetto ad un limite di 32-bit.      ymm0 = a
    vmovdqa ymm1,ymmword ptr [ecx]          ; ymm1 = b

    vphaddd ymm2,ymm0,ymm1                  ; addizione orizzontale
    vphsubd ymm3,ymm0,ymm1                  ; sottrazione orizzontale
    vpmulld ymm4,ymm0,ymm1                 ; moltiplicazione con segno
    vpsllvd ymm5,ymm0,ymm1                  ; shift logico a sinistra               ymm5 = ymm0 << ymm1
    vpsravd ymm6,ymm0,ymm1                  ; shift aritmetico a destra             

; Salva Risultati
    vmovdqa ymmword ptr [edx],ymm2          ; Salva ymm2
    vmovdqa ymmword ptr [edx+32],ymm3       ; Salva ymm3
    vmovdqa ymmword ptr [edx+64],ymm4       ; Salva ymm4
    vmovdqa ymmword ptr [edx+96],ymm5       ; Salva ymm5
    vmovdqa ymmword ptr [edx+128],ymm6      ; Salva ymm6
    vmovdqa ymmword ptr [edx+160],ymm7      ; Salva ymm7

    vzeroupper

    pop ebp
    ret

AVXPackedInt_32 endp
            end

I Get the following errors when I try to compile with Jwasm:

AVXPackedIntArith.asm(21) : Error A2049: Invalid instruction operands AVXPackedIntArith.asm(22) : Error A2049: Invalid instruction operands AVXPackedIntArith.asm(25) : Error A2049: Invalid instruction operands AVXPackedIntArith.asm(26) : Error A2049: Invalid instruction operands AVXPackedIntArith.asm(29) : Error A2049: Invalid instruction operands AVXPackedIntArith.asm(32) : Error A2049: Invalid instruction operands AVXPackedIntArith.asm(62) : Error A2049: Invalid instruction operands AVXPackedIntArith.asm(63) : Error A2049: Invalid instruction operands AVXPackedIntArith.asm(65) : Error A2209: Syntax error: vpslvd AVXPackedIntArith.asm(66) : Error A2209: Syntax error: vpsrvd AVXPackedIntArith.asm: 82 lines, 1 passes, 0 ms, 0 warnings, 11 errors

How can I solve this problem?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Z3R0
  • 1,011
  • 10
  • 19
  • 1
    Which version of MASM are you programming for? – fuz Jun 26 '22 at 14:25
  • mh I think it's 32-bit but I'd like to know about 64-bit too, thank you – Z3R0 Jun 26 '22 at 14:33
  • @fuz They mention JWasm in the question. – ecm Jun 26 '22 at 14:50
  • 1
    @Z3R0 What happens when you replace `.xmm` with `.xmm2` or `.xmm3`? – njuffa Jun 26 '22 at 15:52
  • 1
    So... are you using MASM or JWasm? Which one is it? – fuz Jun 26 '22 at 18:16
  • 3
    I don't think JWASM has complete support for AVX2/AVX512. You might want to consider UASM instead http://www.terraspace.co.uk/uasm.html . UASM is based on JWASM. – Michael Petch Jun 26 '22 at 20:17
  • 1
    I was in fact able to install UASM from source from an updated repository using `git clone https://github.com/darealshinji/UASM.git` then I did `make` then `sudo cp ./Release/uasm /usr/local/bin` . Then instead of using `jwasm` I used `uasm`. Assembling with `uasm filename.asm` worked as expected. If you want to install the binary without building from source code you can download the executables from the main UASM website http://terraspace.co.uk/uasm.html – Michael Petch Jun 26 '22 at 20:45
  • @MichaelPetch Hello thank you for your answer, I will try it on Debian based OS! Which directive should I include to use AVX inside the code? Like ".mmx" ecc? I don't know the directive and I can't find it on google :/ – Z3R0 Jun 27 '22 at 07:07
  • @fuz I'm doing a course on MASM that is on Visual Studio, but I have a debian based OS so I'm using Jwasm to assemble my code. Isn't this called MASM code? I mean I know it is Intel MS-Dos instructions, but isn't it called MASM code for the specific format of the code (that is different from ASM for example)? I'm new on assembly so I'm learning :D – Z3R0 Jun 27 '22 at 07:12
  • 1
    You only have to use `.xmm` to enable all SIMD including AVX/AVX2. So in your code no change necessary. – Michael Petch Jun 27 '22 at 14:35
  • 2
    @Z3R0 Each assembler supports a different syntax. Some times slightly, some times significantly different. So if you use JWasm, the syntax and directives accepted might differ from MASM and an answer for MASM will not be super helpful for you. – fuz Jun 27 '22 at 14:54
  • 1
    Did you happen to get a chance to try UASM? – Michael Petch Jun 28 '22 at 00:55
  • @MichaelPetch So I can correctly compile the assembly code with uasm, but when I try to link it with my others cpp files I get the error: AVXPackedIntArith.o: file not recognized: file format not recognized (that is my object file from the assembly file) :/ I am trying to link them together with the command: "686-w64-mingw32-g++ -static-libgcc -static-libstdc++ AVXPackedIntegerArithmetic.o YmmVal.o AVXPackedIntArith.o" These are 2 my cpp object files and 1 asm object file. I also tryed to compile with the "-c" option of "uasm", but still doesn't work :/ – Z3R0 Jun 28 '22 at 07:12
  • 1
    @MichaelPetch Sorry to bother you again but I have solved by compiling the asm file using: "uasm -coff filename.asm" (: I forgot about the -coff options I was using in jwasm xD – Z3R0 Jun 28 '22 at 07:35

0 Answers0