Avnet Electronics Marketing - Community Forum
    |   
 
Home Design Services My Account About Avnet
Reply
Visitor
niteshupa
Posts: 1
Registered: ‎01-02-2012
0

multiplication of decimal numbers

Dear Sir,



I am using Spartan-6 LX9 board and running the code of decimal multiplication,which i have attached already. In this i am entering the value of a and b from keyboard and giving the result of value c on hyperterminal.But this exactly not doing the multiplication correctly.

so kindly give me idea or provide the sample code.....

Avnet Employee
JBethurem
Posts: 171
Registered: ‎02-18-2010
0

Re: multiplication of decimal numbers

Hello Nitesh,

 

First off, this is more a general coding question, not really specific to the Spartan-6 LX9 MicroBoard.  Thus this forum
may not be the right spot for this question.  

 

The problem may be that you are reading ASCII bytes from the UART.   Reading from UARTs is always a challenging.    
See an ASCII table.   So you have a couple of options.   If only multiplying single digit numbers, you could
just subtract 48 from the value to give you a decimal number.   Else you can use scanf to read in a decimal number:

 

scanf("%d", &A);

scanf("%d", &B);

 

Try that and see if that helps.

 

Jayson

Avnet Employee
professor
Posts: 53
Registered: ‎06-09-2009
0

Re: multiplication of decimal numbers

Hi Nitesh,

 

Jayson is correct and your code is producing the correct output even though it is not the output you might expect.

 

The input being read from the terminal via XUartLite_RecvByte() will be encoded in ASCII and you will need to convert to the decimal equivalent before performing the math operation.  Likewise, the multiplication product will need to be encoded back into ASCII, one digit at a time and sent out the the XUartLite_SendByte (most significant digit first) which can be a little tricky.  If you can afford to link in xil_printf() function, that works very well for most output formatting and will save you some time.

 

I have come up with a quick proof of concept solution for what I think you are trying to accomplish (it really was thrown together quickly and you may come up with a much better solution).  Try this on your end and see if this works better for you.

 

Regards,

 

-Kevin