2021年3月22日星期一

looping over a 0-terminated string: reduce number of instructions in the loop

I have the following loop in my assembly language: if r12 is my input string, r14 is my output string, r13 is the counter. If there is no more characters in r12, I quit the loop. I used cmpb to detect the condition.

Is it possible to reduce the # of lines inside the loop? I feel I can use test instead of cmp to reduce 1 line? but I am not sure exactly how?


loop:       moveq(%r12, %r13, 1), %rdi              cmpb $0x00, %dil       movq $0x00, (%r14, %13, 1)       je exit         call swap       movq %rax, (%r14, %r13, 1)       incq %r13  jmp loop    exit:       //continue processing  
https://stackoverflow.com/questions/66757081/looping-over-a-0-terminated-string-reduce-number-of-instructions-in-the-loop March 23, 2021 at 11:57AM

没有评论:

发表评论