两位数字符串编号汇编

时间:2017-11-15 23:02:02

标签: string assembly nasm digits

所以我必须对s1和s2进行字符串处理,并且我有两个字符串d,其中包含s1和s2的每个位置的最大数字。

例如:

Consume()

所以这是代码

S1: 1, 3, 6, 2, 3, 10

S2: 6, 3, 11, 1, 2, 5

D: 6, 3, 11, 2, 3, 10

问题是,当它达到一个双位数元素(10或11)时,它只取第一个数字(1)并将它与同一位置上另一个数字的数字进行比较,然后取第二个数字并将其与另一个字符串中的下一个数字进行比较。 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

  

它说它应该是一个字节串

短语" of bytes" 非常强烈暗示我的数组。请教导您澄清,但我认为s1: db 1, 3, 6, 2, 3, 10是您应该使用的,因此元素是固定宽度的单字节整数。 (根本不是ASCII字符串)。

这意味着您可以使用简单的成对最大值,如SSE2 pmaxub(对于无符号字节)或SSE4.1 pmaxsb(对于有符号字节)。

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

start:
    movq   xmm1, [s1]       ; load all 6 elements, plus 2 bytes past the end but that's ok.  We ignore those bytes
    movq   xmm2, [s2]
    pmaxub xmm1, xmm2       ; element-wise vertical max

    ;but avoid storing outside of 6-byte d
    movd   [d], xmm1        ; store first 4 bytes of the result
    pextrw [d+4], xmm1, 2   ; store bytes 4 and 5 (word 2 of xmm1 = 3rd word)

    ...  ; the result isn't a string, you can't print it with printf.

对于不是2的倍数的字节数,例如如果l为7,则可以使用此代替pextrw

psrldq  xmm1, 3                ; bring the data you want to store down into the low 4 bytes of the register
movd    [d+4], xmm1            ; 4-byte store that overlaps by 1
顺便说一句,我意识到你打算一次循环1个字节的元素。也许使用cmp cl, al / cmovg eax, ecx / mov [edi], al来存储cl cl > al中的al(签名),最后存储d中最初的内容}。

我认为你的循环结构有点破碎,因为你有一条路径没有存储到d。无论哪个来源更大,您总是需要存储到<style> html, body { margin: 0; padding: 0; } img { position: relative; float: left; width: calc(100%/3); height: 100%; } </style> <body> <div class="container"> <div id="box"> <img src="1.jpg" /> <img src="2.jpg" /> <img src="3.jpg" /> </div> </div> </body>