简体   繁体   中英

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. I have a 4 digit number calculated in assembly, say 2500, stored in a register as 09C4, in say 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. How would I convert from hex to decimal, then pass the 4 digit number to a C function one digit at a time?

Also, I cannot change the C file, only the assembly file. 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.

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.

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. 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

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