So I have to strings s1 and s2 and I have two obtain the string d that contains the maximum numbers for each of the positions of s1 and s2.
For example:
S1: 1, 3, 6, 2, 3, 10
S2: 6, 3, 11, 1, 2, 5
D: 6, 3, 11, 2, 3, 10
So this is the code
bits 32
global start
extern exit,printf
import exit msvcrt.dll
import printf msvcrt.dll
segment data use32 class=data
format db "%s",0
s1 db "1","3","6","2","3","10"
l equ $-s1
s2 db "6","3" ,"11","1","2", "5"
d times l db 0
segment code use32 class=code
start:
mov esi,0
mov edi,0
cld
Repeta:
mov al,[s1+esi]
mov bl,[s2+esi]
cmp al,bl
jg et1
mov[d+edi],bl
inc edi
inc esi
jmp et2
et1:
mov[d+edi],al
inc edi
inc esi
et2:
cmp esi,l
jne Repeta
push d
push format
call[printf]
add esp,4*2
push dword 0
call [exit]
The problem is that when it reaches a double digit element(10 or 11) it takes only the first digit(1) and compares it with the number from the other string on the same position and after that it takes the second digit and compares it with the next number from the other string. How can I solve this?
The phrase "of bytes" very strongly implies array to me. Ask your instructor for clarification, but I think
s1: db 1, 3, 6, 2, 3, 10
is what you're supposed to be working with, so the elements are fixed width single byte integers. (And not ASCII strings at all).This means you can use a simple pairwise max like SSE2
pmaxub
(for unsigned bytes) or SSE4.1pmaxsb
(for signed bytes).For byte counts that aren't a multiple of 2, e.g. if
l
was 7, you could use this instead ofpextrw
:BTW, I realize that you're intended to loop over the elements 1 byte at a time. Maybe use
cmp cl, al
/cmovg eax, ecx
/mov [edi], al
to store what was originally incl
ifcl > al
(signed), otherwise store what was originally inal
.I think your loop structure is a bit broken, because you have one path that doesn't store to
d
. You always need to store tod
, regardless of which source was greater.