我如何从4倒计时,并汇编为0停止 [英] how do i count down from 4 and stop at 0 in assembler

查看:267
本文介绍了我如何从4倒计时,并汇编为0停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么指望从4下来,汇编为0停止。到目前为止,我已经试过这一点。我想则显示3210文本但是它打印3333333333333。
我试图用存储STR然后使用新号码减1再减去之后的新的结果。但它似乎是使用4所有的时间。

how do i count down from 4 and stop at 0 in assembler. I have tried this so far. I would like the text to be displayed then 3210. However It prints 3333333333333. I am trying to store the new result after the subtraction using STR then using the new number subtract 1 again. But it seems to be using 4 all the time.

        B main

    verses  DEFW    4
    temp    DEFW    0
    text    DEFB    " men went to mow a meadow ",0

        ALIGN

main    ADR R0,verses
        SWI 4

        ADR R0,text
        SWI 3



loop    ADR R0,verses
        SUB R0,R0,#1
        STR R0,verses
        SWI 4

        B loop



        SWI 2

在这里输入的形象描述

推荐答案

这是错误的:

ADR R0,verses

SWI 4 预计的的在打印R0 ,而不是 的值的地址。所以,你应该使用类似 LDR R0,经文来代替。你得到4的原因,当你做 ADR R0,经文是因为恰好位于地址4。但是,通过使用 ADR 你会得到4不管你存储的

SWI 4 expects the value to print in R0, not the address of the value. So, you should use something like LDR R0,verses instead. The reason you get 4 when you do ADR R0,verses is because verses just happens to be located at address 4. But by using ADR you'll get 4 whatever you store at verses.

另外,你的循环是无限的,因为你没有添加有史以来退出循环任何code。它应该是这个样子,而不是:

Also, your loop is infinite because you haven't added any code that ever exits the loop. It ought to look something like this instead:

LDR R0, verses
loop    SUBS R0,R0,#1
        BMI done
        SWI 4
        B loop
done

请注意:我不知道,如果 SWI 取值preserve 的值R0 。如果他们不这样做,你将不得不采取照顾自己,例如通过保存 R0 在堆栈中。

Note: I don't know if the SWIs preserve the value of R0. If they don't you'll have to take care of that yourself, e.g. by saving R0 on the stack.

这篇关于我如何从4倒计时,并汇编为0停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆