简体   繁体   English

从程序集向C发送4位数字,以ASCII字符形式显示在LCD上

[英]Sending a 4 digit number from assembly to C to be displayed on an LCD as ASCII characters

So the title is confusing and I apologize. 因此标题令人困惑,我深表歉意。 I have a mixed language assembly/C project that is 90% done, but I'm stuck. 我有一个90%完成的混合语言Assembly / C项目,但是我被卡住了。 I have a 4 digit number calculated in assembly, say 2500, stored in a register as 09C4, in say R8. 我有一个在汇编中计算出的4位数字,例如2500,存储在寄存器中,例如09C4,例如R8。 I need to get it to display in decimal format on an LCD screen by passing each decimal digit to a C function called LCD_write. 我需要通过将每个十进制数字传递给一个名为LCD_write的C函数,以使其在LCD屏幕上以十进制格式显示。 How would I convert from hex to decimal, then pass the 4 digit number to a C function one digit at a time? 如何将十六进制转换为十进制,然后一次将4位数字传递给C函数?

Also, I cannot change the C file, only the assembly file. 另外,我不能更改C文件,只能更改程序集文件。 R0 will pass the row to display on the LCD, R1 will pass the column and R2 will pass the hex representation of the ASCII character. R0将通过行以在LCD上显示,R1将通过列,而R2将通过ASCII字符的十六进制表示。

I know this isn't the best description, but if anybody can help I would greatly appreciate it. 我知道这不是最好的描述,但是如果有人可以提供帮助,我将不胜感激。

Thanks! 谢谢!

Well, it is going to depend on your compiler and arch, but the easiest way to do this is going to be by doing an inline move from the R0 register to some variable. 好吧,这将取决于您的编译器和架构,但是最简单的方法是通过从R0寄存器到某个变量的内联移动。

not correct, and won't compile (probably) 不正确,并且不会编译(可能)

but it will be something like: 但是会是这样的:

int i;
__asm__( mov i, R0)

don't worry about the hex/decimal conversion in a computer it is the same thing until it is displayed... 不用担心计算机中的十六进制/十进制转换,直到显示出来都是一样的...

I am not super familiar with asm but basically you want to reimplement itoa in asm. 我对asm不太熟悉,但是基本上您想在asm中重新实现itoa There is an example here 这里有一个例子

The hex transformation will be very similar, but the +0x48 should change and take into account the position of the [af] chars in the ascii table 十六进制转换将非常相似,但+ 0x48应该更改并考虑[af]字符在ascii表中的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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