Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 试图复制一个;电传打字机效应“;但是字符之间的时间保持不变_Loops_Assembly_Arm_Printf_Cpu Registers - Fatal编程技术网

Loops 试图复制一个;电传打字机效应“;但是字符之间的时间保持不变

Loops 试图复制一个;电传打字机效应“;但是字符之间的时间保持不变,loops,assembly,arm,printf,cpu-registers,Loops,Assembly,Arm,Printf,Cpu Registers,我正试图制作一个程序,使“teleprinter效应”,打印一个由r0中的参数传递的字符串,逐字符,在上一次打印和下一次打印之间有一段时间。 这个程序运行正常,但发生了一些奇怪的事情。有一个r2寄存器包含“time loser”值。理论上,最大值是“lose_time”子例程必须执行的循环次数越多,因此每次打印字符之间的时间就越多。但实际上,即使我把r2值改成一个很高的值,它也不会改变任何东西。为什么? 远程服务: .global tele .type tele%function @ r0 =

我正试图制作一个程序,使“teleprinter效应”,打印一个由r0中的参数传递的字符串,逐字符,在上一次打印和下一次打印之间有一段时间。 这个程序运行正常,但发生了一些奇怪的事情。有一个r2寄存器包含“time loser”值。理论上,最大值是“lose_time”子例程必须执行的循环次数越多,因此每次打印字符之间的时间就越多。但实际上,即使我把r2值改成一个很高的值,它也不会改变任何东西。为什么?

远程服务:

.global tele
.type tele%function

@ r0 = array
@ r1 = signle char
@ r2 = time-loser

tele:
        mov r2,#700    // if I edit this, it doesn't change anything
        push {ip,lr}    // save lr
loop:
        ldr r1,[r0],#1    // at each loop it increase the array pointer and so r1 takes the next value in the array
        cmp r1,#0    // if the value is NULL
        beq end    // array is ended and returns
        push {r0,r2}    // save the r0(array address) and r2(my time-loser value)
        ldr r0,=message
        bl printf    // prints one single char
        bl lose_time    // then lose time
        pop {r0,r2}    // and take r0, r2 values back
        b loop    // do the cycle again
lose_time:
        sub r2,r2,#1    // sub 1
        cmp r2,#0    // until it reaches 0
        bxeq lr    // if reaches 0, it returns to "loop" subroutine
        b lose_time    // else do the cycle again
end:
        pop {ip,lr}    // if the program ends, it takes the lr back
        bx lr    // and returns

message:
        .asciz "%c\n"
int tele(char *);

int main(){
        char string[] = "Teleprinter effect";
        tele(string);
        return 0;
}
奇怪的是,即使我输入700(非常低的值),打印也会延迟。它的打印速度非常慢,就像我输入了一个非常高的数字。那为什么呢

main.c:

.global tele
.type tele%function

@ r0 = array
@ r1 = signle char
@ r2 = time-loser

tele:
        mov r2,#700    // if I edit this, it doesn't change anything
        push {ip,lr}    // save lr
loop:
        ldr r1,[r0],#1    // at each loop it increase the array pointer and so r1 takes the next value in the array
        cmp r1,#0    // if the value is NULL
        beq end    // array is ended and returns
        push {r0,r2}    // save the r0(array address) and r2(my time-loser value)
        ldr r0,=message
        bl printf    // prints one single char
        bl lose_time    // then lose time
        pop {r0,r2}    // and take r0, r2 values back
        b loop    // do the cycle again
lose_time:
        sub r2,r2,#1    // sub 1
        cmp r2,#0    // until it reaches 0
        bxeq lr    // if reaches 0, it returns to "loop" subroutine
        b lose_time    // else do the cycle again
end:
        pop {ip,lr}    // if the program ends, it takes the lr back
        bx lr    // and returns

message:
        .asciz "%c\n"
int tele(char *);

int main(){
        char string[] = "Teleprinter effect";
        tele(string);
        return 0;
}
修好了

我将r2保存到内存中,但只是在调用延迟循环后才恢复它

// r2 is 700
bl printf    // prints one single char
// r2 is garbage
bl lose_time    // then lose time
// r2 is 0
pop {r0,r2}    // and take r0, r2 values back
// r2 is 700 again

一个人在这里帮了我:

ldr r1,[r0],#1
@Michael你说得对。顺便说一句,我把它修好了。