This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ARM7 printf long long int

Hi, my program does not do the expected things, printf a unsigned long long int.

#include <aduc7026.h>
#include"stdio.h"

void RS232_init(void);
int main (void)
{
	unsigned long long int A;
	RS232_init();
	printf("Start \n");
	while(1)
	{
		while(1)
		{
			printf("Enter a Hex-number\n");
			if (scanf("%X",&A)) break;
			scanf("%*");				//Clearing scanf input stream
		}
		printf ("Your input %64.64lX\n",A);
		A *= A;
		printf ("The result %64.64lX\n",A);
	}
}

void RS232_init(void)
{
	GP1CON = 0x011;			// Setup tx & rx pins on P1.0 and P1.1
   							// Start setting up UART at 9600bps
   	COMCON0 = 0x080;		// Setting DLAB
   	COMDIV0 = 0x088;		// Setting DIV0 and DIV1 to DL calculated
   	COMDIV1 = 0x000;
   	COMCON0 = 0x007;		// Clearing DLAB
}
the Output via RS232: Start Enter a Hex-number Your input 0000000000000000000000000000000000000000000000000000000011111111 The result 0000000000000000000000000000000000000000000000000000000087654321 Enter a Hex-number but when stepping through the programm ?C?QMUL?A: 0x00080F78 E08CB290 UMULL R11,R12,R0,R2 0x00080F7C E02CC192 MLA R12,R2,R1,R12 0x00080F80 E021C093 MLA R1,R3,R0,R12 0x00080F84 E1A0000B MOV R0,R11 0x00080F88 E12FFF1E BX R14 after the UMULL the expected result (0x0123456787654321) is in R12/R11 for some just a little moment... Sometimes i think C is the pureness of evil.

Parents
  • I just want to force printf to give me unsigned long long integer
    for example 0x11111111 * 0x11111111 i expect 0x0123456787654321 but the result from printf is only 000000000087654321.

    What a mess! I'am very very disapointed!

    Maybe the compiler does not recognize "unsigned long long integer"?
    But there's no error-message!

    Who can help?

Reply
  • I just want to force printf to give me unsigned long long integer
    for example 0x11111111 * 0x11111111 i expect 0x0123456787654321 but the result from printf is only 000000000087654321.

    What a mess! I'am very very disapointed!

    Maybe the compiler does not recognize "unsigned long long integer"?
    But there's no error-message!

    Who can help?

Children
  • I just want to force printf to give me unsigned long long integer

    Then why are you telling printf that the length is long integer (l) instead of long long integer (ll) ?

  • "Maybe the compiler does not recognize 'unsigned long long integer'?"

    The compiler recognises it, and the compiler has given you one.

    However, you have told printf to print a long, and that's exactly what it has done - it has printed a long which is precisely one half of the long long that you supplied!

    As a programmer with 10 years 8051 assembler experience, you should understand that silly things will happen if you supply inconsistent parameters to a fucntion call!

    "But there's no error-message!"

    That's because the program is perfectly valid.
    That problem is that your program does not actually describe what you want it to do.

    Again, as a programmer with 10 years 8051 assembler experience, you should realise program execution is a YAFIYGI process:

    "You Asked For It; You Got It!"

    You really do need to sit down with a basic 'C' textbook and start with the basics before you go running & jumping into the deep end before you can walk or swim!