简体   繁体   中英

Delay Loop Printing Integers in Assembly

I'd like to make a quick program in assembly for the ARM Cortex M4 architecture that prints a consecutive integer every 2 seconds. So every 2 seconds, it goes 1, 2 and so on. Since this architecture is 32MHz, I know that there will be 64,000,000 cycles for 2 seconds. I want to use a delay loop, despite knowing that it isn't very efficient. I have a C file that will print the result instead of doing it in the assembly file, the function is just called fprint. I figured if I saw the solution (which I simply don't know how to arrive at), it would help me in my assembly journey.

Thanks for the help!

Try something like this:

delay_2s:
        ldr     r0, =32000000
loop:   subs    r0, r0, #1
        bnz     loop
        bx      lr

Note that the duration of one iteration can vary depending on the microarchitecture used. I have here set it up for two cycles per iteration, but it could also be three cycles per iteration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM