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?
pmaxub
would do exactly what you need in one instruction: a per-elementmax
with unsigned byte elements (the ASCII codes for the 0-9 digits are in order and consecutive). With strings that aren't 4, 8, or 16 bytes long, you'd need to either pad the output buffer or store in parts, though. – Peter Cordesdb
directive correctly? It looks like your string is supposed to include commas, but the way you wrote it is exactly equivalent tos1: db "1362310"
This is obviously ambiguous. Are you sure it wasn't supposed to bedb 1, 3, 6, 2, 3, 10
(array of byte elements) ordb "1, 3, 6, 2, 3, 10"
(string containing commas)? – Peter Cordess1: 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). – Peter Cordes