我正在尝试在汇编程序中编写一个函数,该函数以 3 为单位计数,从 1 到 rcx 以 3 计数,最大值为 20

问题描述 投票:0回答:0

例如,如果参数为 20,则循环应计数 1、4、7、10、13、16、19,然后结束。到目前为止我写的东西会算数,但它不会停留在 20.

    .globl __Z5counti
__Z5counti:

    # rcx = the number to count
    movq $1, %rdx    # rdx =1 counting...
    cmp  $0, %rcx
    je   .End
.Loop:
    addq $3, %rdx   # rdx += 3
    cmpq %rcx, %rdx # rdx == rcx?
    jle .Loop
.End:
    retq

我试过将 rcx 设置为 20,并做了一个应该在 rdx 为 <= rcx, but the output of rcx ends up being 14 instead of 20.

时停止的循环
assembly x86-64 att
© www.soinside.com 2019 - 2024. All rights reserved.