Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Assembly/Binary Arithmetic

Options
  • 30-03-2007 2:50am
    #1
    Registered Users Posts: 1,916 ✭✭✭


    Hello,

    I have a bit of a problem with a college assignment and I'm hoping someone can give me a nudge in the right direction.

    I'll try not to go into too much detail but let me know if I should elaborate on anything. The architecture concerned is the MC68000; specifically the 68332.

    The program is essentially a calculator which can accept numbers in Binary, Decimal or Hex. It should work for addition, subtraction, division and multiplication on signed(2's complement) numbers. All operations should be 64-bit; which to me indicates that it should be possible to input 64-bit numbers.

    The result of any operation can be displayed in the base chosen by the user; so in theory it should allow the addition of a Hex to a Binary number and then display the result in Decimal.

    The problem I'm having is with the required conversions. Converting an ASCII String into a number in order to perform calculations and the inverse; converting a number into an ASCII String to print to the terminal.

    For Binary and Hex; it's possible to manipulate the bits using bitwise operations and print out an arbitrary length number, although it seems to me that would be a bit of a nightmare to code for all the different combinations of conversions.

    Currently my program uses the 68k arithmetic commands to do the conversions but this means there is a limit on the numbers that can be inputted and printed. In order to accurately deal with 64-bit numbers there would need to be a 64*x->64 multiplication command and a 64/x->64Quotient:xRemainder division command... which do not exist! (x can be as small as 4-bits)

    So I guess my question is; am I right in saying the only way to convert binary and hex into decimal(and the inverse) is by division and multiplication of large numbers? Or am I completely useless and missed something blindingly obvious?

    And for those of you more familiar with 68k Assembly; wouldn't those commands outlined above take a large number of cycles to execute and also be quite difficult to code in the first place? Doubly so if worrying about signs of numbers...

    Does anyone have any suggestions as to how I can move forward without trying to take on too much?


Comments

  • Closed Accounts Posts: 2,174 ✭✭✭mathias


    Probably way off the mark and no help , but ,

    It seems to me , for binary conversions to decimal anyways , that a look up table of place powers of 2 and addition would be faster than division and multiplication.


    for example , 1011 in binary = ( from right to left ) = (1x 2^0) + (1x 2^1) + (0 x 2^2) + (1 x 2^3) = 11 base 10, as the powers in binary are all a fixed value all you need to know is the position of the 1 digits and add the corresponding powers up , an index table if you like.

    This approach will work for conversion to any base, dont really know enough about your language to be specific , but it is certainly an alternative to all that division if you can code it ,

    Here is an example VB module , ( not mine by the way ) see if you can somehow code that into your language ,

    http://www.devx.com/vb2themax/Tip/19316


  • Registered Users Posts: 1,916 ✭✭✭ronivek


    That was something I had considered but I wasn't too convinced if it was practical or not given the specification of the program; and I couldn't quite see how to code a decent algorithm to generate the tables and conversely utilise them without still wasting a lot of clock cycles.

    I guess I should look at that approach again in the morning with the help of that link; see if I can figure out how to somehow get it to work with what I have already or face rewriting the whole thing.

    Thanks for the reply; it has given me some hope!


  • Registered Users Posts: 5,379 ✭✭✭DublinDilbert


    Hi

    When i have to print something out in decimal i just do the following ( the code is in C but you get the idea ):-

    SendCharToDisplay((data/10000)+0x30 ); /* how many 10000 */
    data %= 10000; /* see what's less than 10000 */
    SendCharToDisplay((data/1000)+0x30 ); /* how many 1000 */
    data %= 1000; /* see what's less than 1000 */
    SendCharToDisplay((data/100)+0x30 ); /* how many 100 */
    data %= 100; /* see what's less than 100 */
    SendCharToDisplay((data/10)+0x30 ); /* how many 10s are there? */
    SendCharToDisplay((data%10)+0x30 ); /* how many 1s? */


    The code above will generate ascii characters, which should be fairly easy to handle in assmbly.
    DD


  • Registered Users Posts: 1,916 ✭✭✭ronivek


    Thanks for that. Your code is similar to what I have currently; however that puts a limit on the size of number that can be properly represented when using instructions with size limits.

    The 68000 is limited to 16-bit*16-bit=32-bit and 32-bit/16-bit=16-bitQuotient:16-bitRemainder instructions. Therefore larger numbers especially 2's complement numbers >32-bit can't be manipulated using the built-in commands.

    Even with the 68332 the commands still do not allow full 64-bit manipulation; and this is where I'm looking for help. How do I cater for the larger numbers without directly using large multiplication and division? Is there any way?


Advertisement