It is currently Sat Apr 04, 2020 9:19 am

 All times are UTC

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Simple Calculation Program IssuesPosted: Mon Mar 28, 2011 4:11 pm

Joined: Sat Mar 19, 2011 2:25 am
Posts: 3
Location: MI
Hi, I'm a new poster here, and was looking for some input about a simple calculation program that I'm trying to code in 68k assembly; essentially, the program prompts and takes input for the number of quarters, dimes, nickels, and pennies - then proceeds to calculate the number of dollars and cents total, and prints them out to the console.

I have 'word' variables for the number of each coin, as well as the coins' values. I also have variables for the total dollar value and total cent (remainder) value.

I multiply the coin count variables by their respective values, add all of those totals together, and divide by 100.

Unfortunately, I seem to be running into an 'Invalid addressing error' each time I use MULU to multiply the coin counts by their respective values. I would be happy to post my code if needed; I just didn't want to make the post much longer than it already is! Any assistance and design suggestions for me would be greatly appreciated. Thanks so much!

Top

 Post subject: Posted: Mon Mar 28, 2011 5:35 pm

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
Code:
CLR.L D1 ; Accumulator
MOVE.W quarters,D0
MULU.W #25,D0
MOVE.W dimes,D0
MULU.W #10,D0
;..
DIVU   #100,D1
MOVE.W   D1,dollars
SWAP   D1
MOVE.W   D1,cents

Top

 Post subject: Posted: Mon Mar 28, 2011 8:27 pm

Joined: Sat Mar 19, 2011 2:25 am
Posts: 3
Location: MI
Thanks a lot Clive, that line of thought and code seems to work a bit better than my own; unfortunately, I have one more help request to make involving the output of the dollar and cent final values.

As they're both longwords, I'm thinking I would want to use TRAP task 3 after moving both variables to D1.L. Unfortunately, I'm getting what appears to be a large hexadecimal value expressed as decimal (65537 dollars and 65556 cents) and can't for the life of me figure out precisely *why*. Any guidance would be greatly appreciated, and an explanation of why would be even better! Thanks in advance for your time!

Top

 Post subject: Posted: Mon Mar 28, 2011 9:07 pm

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
One of your material problems is that the 68000 divide assumes a 32-bit divend will produce a 16-bit quotient and 16-bit remainder packed into a single register.

ie
DIVU #y,D1
D1:HIGH = D1 MOD y, D1:LOW = D1 DIV y

Getting a 32-bit quotient will require the cascading of hardware divides, a software solution, general cleverness, or a 68020.

If you simply need dollars and cents to be LONGs, and can cope with a range of 0..6553599 for your accumulator.

Code:
DIVU     #100,D1 ; workable for values of 0 to 6553599 cents
MOVE.L   D1,D2
AND.L    #\$FFFF,D2
MOVE.L   D2,dollars
CLR.W    D1
SWAP     D1
MOVE.L   D1,cents

Top

 Post subject: Posted: Mon Mar 28, 2011 9:59 pm

Joined: Sat Mar 19, 2011 2:25 am
Posts: 3
Location: MI
Ah, I see now. Thanks for explaining that - it seems like the initial code worked perfectly when defining Dollars and Cents as words instead of longwords; I was confused by my understanding of the MULU operation - I was of the assumption that it was typeless (like DIVU) and operated only on LONGs, hence my defining of dollars and cents as LONGs. I probably should have picked that up a bit quicker from your first code blurb. Thanks so much for the help, just that little bit went a long way for my understanding!

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 4 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects