访问KEIL中的DCB和DCW内存类型

发布于 2025-01-23 12:50:06 字数 1058 浏览 4 评论 0原文

我是汇编的新手,目前正在研究一个项目,以尝试使用ARM Assembly语言和C ++开发单词云。我正在开发以下功能:

getfreq访问称为DCW内存类型的表中的数字。限制之一是该函数必须在汇编中写入,然后由我的C ++程序拨打,

这是当前如何查看函数的方式:

GetFreq ADR r3, table ;load the table into memory
        LDRB R2, [R3, #4] ;access a byte
        CMP r2, #0  ;compare it to 0 to see if we are at the end of the table
        LDRB R0, [R2]   ;return output
        BNE GetFreq  ;go to the next
        BX LR  

这是存储数据的方式:

            ALIGN               ; use this directive to start the entire data block on a word boundary
table       DCB "pears",0       ; strings must be null-terminated
            DCW 8               ; frequency is a 16-bit half-word
            DCB "apples",0
            DCW 16               
            DCB "pie",0
            DCW 30
            DCB "beans",0
            DCW 12
            DCB 0               ; A zero byte here indicates table termination

如果我删除cmp r2,#0 < /代码>我返回了值8,但是我似乎无法弄清楚如何访问其他数字。我也一直在努力寻找有关访问这种记忆的任何其他文档,因此我非常感谢所有帮助。

I'm a newbie at assembly and I am currently working on a project to try and develop a word cloud using ARM Assembly language and C++. I am developing the following function:

GetFreq to access a number in a table declared as a DCW memory type. One of the restraints is the function must be written in assembly and then called by my C++ program

This is currently how the function is looking:

GetFreq ADR r3, table ;load the table into memory
        LDRB R2, [R3, #4] ;access a byte
        CMP r2, #0  ;compare it to 0 to see if we are at the end of the table
        LDRB R0, [R2]   ;return output
        BNE GetFreq  ;go to the next
        BX LR  

This is how the data is being stored:

            ALIGN               ; use this directive to start the entire data block on a word boundary
table       DCB "pears",0       ; strings must be null-terminated
            DCW 8               ; frequency is a 16-bit half-word
            DCB "apples",0
            DCW 16               
            DCB "pie",0
            DCW 30
            DCB "beans",0
            DCW 12
            DCB 0               ; A zero byte here indicates table termination

If I remove the CMP r2, #0 I get the value 8 returned, however I can not seem to work out how to access the other numbers. I've also been struggling to find any other documentation on accessing memory like this, so I would really appreciate any and all help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文