Given a vector of bytes with length multiple of 8, how can I, using mmx instructions, convert all 2's to 5's, for example?

.data
    v1 BYTE 1, 2, 3, 4, 1, 2, 3, 4

Thanks.

Try something like below:

.section .data
    v1: .byte 1, 2, 3, 4, 1, 2, 3, 4
    v2: .byte 1, 5, 5, 5, 5, 5, 5, 5

.section .bss

.section .text
	.global _start
_start:
	movq	v1, %mm0
	movq	v2, %mm1	

	pcmpeqb %mm0, %mm1
	movq	%mm1, %rdi

	movq	$60, %rax
	syscall

the answer in %mm1 is ff 00 00 00 00 00 00 00

For your example you would use to test your vector for twos

.section .data
    v1: .byte 1, 2, 3, 4, 1, 2, 3, 4
    v2: .byte 2, 2, 2, 2, 2, 2, 2, 2

.section .bss

.section .text
	.global _start
_start:
	movq	v1, %mm0
	movq	v2, %mm1	

	pcmpeqb %mm0, %mm1
	movq	%mm1, %rdi

	movq	$60, %rax
	syscall

Edited 6 Years Ago by gerard4143: n/a

I forgot to mention in the 1st post what assembler I was using and that 2 and 5 are paraemeters of procedure.

In the meanwhile I have solved my own problem.

.data
 
v1      BYTE    1, 2, 3, 4, 1, 2, 2, 1, 1, 2, 3, 4, 1, 2, 2, 1
tam     DWORD   $-v1
isto    BYTE    3
aquilo  BYTE    8
res     BYTE    128 dup(?)

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

.code

start:
 
    mov ecx, tam
    shr ecx, 3

    mov esi, offset v1

    @@:
        movq        mm0, [esi+8*ecx]

        movzx       eax, isto
        movd        mm1, eax
        punpcklbw   mm1, mm1
        punpcklwd   mm1, mm1
        punpckldq   mm1, mm1

        pcmpeqb     mm1, mm0

        movzx       eax, aquilo
        movd        mm2, eax
        punpcklbw   mm2, mm2
        punpcklwd   mm2, mm2
        punpckldq   mm2, mm2

        pand        mm2, mm1

        pandn       mm1, mm0 
        por         mm2, mm1

        movq        [esi+8*ecx], mm2 

    LOOP @B
           	
    exit

end start

P.S: I am using masm32.

This article has been dead for over six months. Start a new discussion instead.