EASy68K  
It is currently Sat Apr 04, 2020 6:44 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Fri Jan 27, 2006 10:21 pm 
Offline

Joined: Mon Jan 16, 2006 3:04 pm
Posts: 7
i have a similar problem as Velorien
it seems we're at the same college :)

i had an assignment where i had to multiply three 16-bit numbers and print out the result. well, i have managed to multiply the numbers, using an algorithm i found on the net. i had some problems with figuring out how to do it in assembly language but i figured it out :)
i have now placed my 48 bit result in 2 registers, actually one and a half, so one long word and one word. i've also copied the result into a memory location. now i'm having problems with printing it on the screen as a decimal result :(

and i have to do the assignment (asap), otherwise i will fail the whole year :( :(

so please help me, and please tell me at least what way i could use now to covert it to decimal and print it out. i've found some similar things on the internet, like converting numbers to ascii characters and then printing it out, but i didn't really figure that out completely....

i'll now post my code, so you can see how far (or not far?) :) i've gotten so far....i've removed my comments as they're in Croatian so i doubt you'd have any use of them :) (only translated some more important ones)

Code:

START    MOVE.L #4,D0
   TRAP #15
   MOVE D1, D2
   MOVE.L #4,D0
   TRAP #15
   MULU D1,D2
   MOVE.L #4,D0
   TRAP #15
   MOVE.W D2,D3
   MULU D1,D3
   MOVE.L D2,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSR.L #4,D4
   MOVE.W D4,D5
   MULU D1,D5
   MOVE.L D3,D6
   LSR.L #4,D6
   LSR.L #4,D6
   LSR.L #4,D6
   LSR.L #4,D6
   ADD.L D5,D6
   MOVE.W D3,D7
   ; after all this i have the result in registers D6 and D7
   ; now i'll shift things so i'll have 32 less significant bits in one and 16 more significant bits in the othew register
   MOVE.L D6,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSL.L #4,D6
   LSL.L #4,D6
   LSL.L #4,D6
   LSL.L #4,D6
   MOVE.W D7,D6
   MOVE.L D6,D5
   ; the result can now be written into memory by writing D4 first and then D5
   ; clear not needed registers
   CLR.L D3
   CLR.L D6
   CLR.L D7
   
   ; beginning of my try to print it out as decimal, i got only to copying the result into memory
   MOVE.W D4,$1100
   MOVE.L D5,$1102
   
   
   STOP #$2000



Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 11:51 pm 
Offline

Joined: Wed Jan 18, 2006 10:07 pm
Posts: 11
Evo poslao sam ti rjesenje na pm ;)

Btw mislim da mozes izravno kopipejstat rjesenje, manje vise, u zadatak i mozda ti ispise rjesenje jer vidim da koristis iste registre koje sam i ja koristio ^^

Pozdrav!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 12:59 am 
Offline

Joined: Tue Nov 15, 2005 7:58 am
Posts: 129
Location: Oregon, USA
This will be the same method as in the answer previously given for converting to base-10 ASCII.

You will have to be able to divide the 48-bit number by ten repeatedly. So you need an algorithm to do multiple precision division. For I/O, which is slow anyway, you could do repeated subtractions, which would be inefficient but simple. Or you can figure out how to do partial divisions using the built-in division operatons and put the results together. That would be most efficient but probably hardest to do. Or write a software division for 48+ bit values using one of the faster but more complex algorithms instead of just subtraction. I'd tend to look at how you'd do it by hand and try to emulate that -- pick a trial divisor, try, correct if necessary, multiply, subtract product and repeat, same as pencil-and-paper decimal division.

Good luck!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 1:06 am 
Offline

Joined: Wed Jan 18, 2006 10:07 pm
Posts: 11
Okay, i couldn't sleep so i solved your problem :)

Maybe...

Anyway this should work.

Code:
START    MOVE.L #4,D0
   TRAP #15
   MOVE D1, D2
   MOVE.L #4,D0
   TRAP #15
   MULU D1,D2
   MOVE.L #4,D0
   TRAP #15
   MOVE.W D2,D3
   MULU D1,D3
   MOVE.L D2,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSR.L #4,D4
   MOVE.W D4,D5
   MULU D1,D5
   MOVE.L D3,D6
   LSR.L #4,D6
   LSR.L #4,D6
   LSR.L #4,D6
   LSR.L #4,D6
   ADD.L D5,D6
   MOVE.W D3,D7
   ; after all this i have the result in registers D6 and D7
   ; now i'll shift things so i'll have 32 less significant bits in one and 16 more significant bits in the othew register
   MOVE.L D6,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSR.L #4,D4
   LSL.L #4,D6
   LSL.L #4,D6
   LSL.L #4,D6
   LSL.L #4,D6
   MOVE.W D7,D6
   MOVE.L D6,D5
   ; the result can now be written into memory by writing D4 first and then D5
   ; clear not needed registers
   CLR.L D3
   CLR.L D6
   CLR.L D7
   
   ; beginning of my try to print it out as decimal, i got only to copying the result into memory
   MOVE.W D4,$1100
   MOVE.L D5,$1102

      * Ovdje cu drzati ASCII vrijednost dobivenog broja
      lea $2100(PC), A3

      clr D2
      
      

      
Konverzija   * Pokusaj konverzije u decimalni oblik, sad ovo stavim u neku improvizaciju while petlje i trebalo bi radit :)
      * Trebala bi bit while petlja no nije mi se dalo radit pa je obična for petlja

      * Sastavi potrebno iz donje rijeci gornjih 32 bita tj. registra D4 i gornje rijeci
      * donja 32 bita tj. registra D5 u jedno i spremi u D3 registar

      move.w D4, D3
      swap   D3

      move.l D5, D6
      swap D6
      move.w D6, D3

      * Nakon toga podijeli dobiveno s 10 da bismo dobili gornji dio bitova rezultata i ostatak koji koristimo dalje
      divu #10, D3
      swap D3

      * Ostatak iz D3 premjestimo u D7 i swapamo ga tako da se nalazi u visoj rijeci D7
      move.w D3, D7
      swap D7

      * Zatim jos nakraju dodamo najnizu rijec iz prvobitnog registra D5 tako da tvori najnizu rijec u novom broju koji se nalazi u D7
      move.w D5, D7

      * Podijelimo s 10 i dobijemo rezultat i ostatak, ostatak je zapravo jedna znamenka 64 bitnog broja u decimalnom sustavu
      divu #10, D7

      * Swapamo D7 tako da dobijemo ostatak u nizoj rijeci te toj rijeci dodamo 48 tj. $30 kako bi je konvertirali u ASCII i premjestimo je u memoriju
      swap D7
      add.w #48, D7
      move.w D7, (A3)+

      clr D6

      swap D3
      move.w D3, D6
      swap D6
      
      swap D7

      * U D6 dobijem novi broj koji moram dijeliti da bi dobio ostale znamenke
      move.w D7, D6

      clr D4 * AKO NE RADI - Probaj maknuti ovo
      move.l D6, D5

      add.w #1, D2

      cmp #12, D2
      bge ispisi

      jmp Konverzija


ispisi      lea $2117(PC), A2



      clr D1
      clr D2
         
petlja      * Rezultat moramo obrnuto ispisati jer je zapisan od najmanje prema najvecoj znamenki
      move.b -(A2), D1

      MOVE #6, D0
          TRAP #15

      add.b #1, D2

      cmp #22, D2
      bge Kraj

      jmp petlja
   
   
kraj       STOP #$3000


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 1:19 am 
Offline

Joined: Mon Jan 16, 2006 3:04 pm
Posts: 7
thanks, it works up to a point. but if you multiply 65000 x 65000 x 65000 or something that big, it doesn't give a good result....

i'll try to figure it out, right now i'm so tired i can barely keep my eyes open :)

thx


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 1:22 am 
Offline

Joined: Wed Jan 18, 2006 10:07 pm
Posts: 11
Probaj maknut ovo sto sam ti oznacio kod tj. onaj clear D4 registra ;)
Edit: probao sam i ne radi :)

A sta da ti kazem, probaj nest skemijat ^^

Pozdrav!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 1:26 am 
Offline

Joined: Mon Jan 16, 2006 3:04 pm
Posts: 7
onda nist ne ispise, kod tih vecih brojeva, a kod manjih je opet ok....
limitirano je izgleda do 11 decimalnih znamenki
a to je 174876E7FF .... manje od 40 bita znaci


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 1:28 am 
Offline

Joined: Wed Jan 18, 2006 10:07 pm
Posts: 11
Mozda ti se posreci pa Magdalenic ne bude testirao program s tako velikim brojevima :)

Ili da probas, umjesto kao sto sam ja radio s rijecima, probati to s bajtovima nekako izvesti. Podijelis taj registar i pol na 6 bajtova i radis slicno kao sto sam ja radio, samo bajt po bajt (koji tvore rijec). Samo ideja :)


Last edited by Velorien on Sat Jan 28, 2006 1:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 1:30 am 
Offline

Joined: Mon Jan 16, 2006 3:04 pm
Posts: 7
budem probal igrati se sutra s tim jos malo, ako nis ne uspijem srediti, idem u utorak na konzultacije pa da se probam provuci s tim kaj imam bar :), ak ne prodje onda poslije kolokvija u srijedu lupat po tome i rjesiti nekak ....


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 2:44 am 
Offline

Joined: Mon Dec 20, 2004 6:03 pm
Posts: 50
Now this isn't fair, English please!



Nah, im JK-ing you. :wink


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 4:09 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
I'm going to start posting my answers in Klingon :laughing4: .

tlhIngan maH!

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 11:27 am 
Offline

Joined: Wed Jan 18, 2006 10:07 pm
Posts: 11
:lol:

Sorry for the foreign talk and stuff, but it's easier for me to explain in Croatian than in English :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 4:22 pm 
Offline

Joined: Mon Dec 20, 2004 6:03 pm
Posts: 50
OT: I wish I knew Romulan....


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group