6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 4:44 am

All times are UTC




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: I need a help with this
PostPosted: Thu Nov 04, 2010 7:57 pm 
Offline

Joined: Fri Nov 21, 2008 3:07 pm
Posts: 31
salida=io_area+3
salida2= io_area+2
.ORG $0200
sed
LDA n2
BEQ fin
f1: LDA p
CLC
ADC n1
STA p
;DEC n2
LDA n2
SEC
SBC #1
STA n2
BEQ fin
JMP f1


fin:LDA p
STA salida
BRK

n1: .db $10
n2: .db $15
p: .DB $0

It works just grate problem is it only shows the multiplication of 2 digits it means it only show until 99 after that doens't show any multiplication a above 99

can u tell me what i have to do?? or do it .. to see pleae? thank you


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 9:11 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Here's the code again with slight modification. (Also: Put [code] and [/code] around the code to keep the spaces and the fixed width, and make sure you don't have "Disable BBCode in this post" checked.)
Code:
salida=io_area+3   ; ("salida" means "output" in Spanish)
salida2= io_area+2
    .ORG $0200
     sed
     STZ p         ; Initialize the product as 0.
     LDA n2
     BEQ fin       ; ("fin" means "end" in Spanish)

f1:    LDA p
       CLC
       ADC n1
       STA p

    ;  DEC n2
       LDA n2
       SEC
       SBC #1
       STA n2
     BNE f1


fin: LDA p
     STA salida
     BRK
 
     n1: .db $10    ; multiplicand
     n2: .db $15    ; multiplier
     p:  .DB $0     ; product

So now do you want to make only the product able to be more than 99, or do the inputs have to be able to be more than 99 also? (Obviously with this method, a large value of N2 will make the routine take a very long time!)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 9:26 pm 
Offline

Joined: Fri Nov 21, 2008 3:07 pm
Posts: 31
that could go more than 99.. 1xx or more..


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 9:43 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
But do you need only the result to go over 99, like 41*13=533, where both inputs are only one byte and the output is two, or do you need to be able to input higher numbers, to do for example 329*13=4277, where the 329 input is more than 99? Neither one is difficult, but it will be a little longer if the inputs must be able to exceed 99.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 10:14 pm 
Offline

Joined: Fri Nov 21, 2008 3:07 pm
Posts: 31
GARTHWILSON wrote:
But do you need only the result to go over 99, like 41*13=533, where both inputs are only one byte and the output is two, or do you need to be able to input higher numbers, to do for example 329*13=4277, where the 329 input is more than 99? Neither one is difficult, but it will be a little longer if the inputs must be able to exceed 99.


yeah i want to exceed the 99...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 10:28 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
You will always have trouble getting help if you don't pay more attention to detail! You did not answer my question.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 04, 2010 10:35 pm 
Offline

Joined: Fri Nov 21, 2008 3:07 pm
Posts: 31
sorry i want that i able to input any higher number i be able to obtain the result


exp: 12*58 = 696
exp: 13*160= 2080

i be able to obtain those result

i friend told me i could do it in 2 lines... dont know.. how..


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 05, 2010 2:33 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
OK so this:
Quote:
exp: 13*160= 2080

means you need the inputs to be able to go over 99, not just the output. There is a difference. Of course 9999*9999 is 99,980,001 which needs four bytes for output, and 999*999 is 998001 which needs three bytes of output; but for now I will assume that it is adequate as long as the output is only two bytes, limited to 9999, the same precision as the input, instead of double precision. You cannot have both inputs be over 99 that way, but I assume that's ok for now.

So we will make both inputs n1 & n2, as well as the output p and "salida" to be two bytes each, assuming there are two bytes available there for each, and change the routine to this:

Code:
salida=io_area+3   ; ("salida" means "output" in Spanish)
salida2= io_area+2
    .ORG $0200
     sed

     STZ p         ; Initialize the product as 0.
     STZ p+1

     LDA n2
     BNE f1
     LDA n2+1      ; Now we have a high byte to check too.
     BEQ fin       ; ("fin" means "end" in Spanish)

f1:    LDA p
       CLC
       ADC n1
       STA p

       LDA p+1     ; Insert these 3 lines for 2nd pair of digits.
       ADC n1+1    ; (Do not CLC first this time.)
       STA p+1

    ;  DEC n2
       LDA n2
       SEC
       SBC #1
       STA n2
     BNE f1
       LDA n2+1     ; If the low byte turned to 0, check the high byte.
     BEQ fin        ; If it was already 0, you're done.
       SBC #1       ; Otherwise decrement it
       STA n2+1
     BRA f1         ; and continue looping.


fin: LDA p          ; Now transfer both output bytes to "salida".
     STA salida
     LDA p+1
     STA salida+1
     BRK
 
     n1: .db $10    ; multiplicand
     n2: .db $15    ; multiplier
     p:  .DB $0     ; product


For getting into numbers that big however, adding n2 times is not efficient timewise. Usually the computer is made to internally keep and handle numbers in hex and only convert to and from decimal when it's time for human I/O and the multiplication is done by shifting bits and adding with a much shorter process. There are several hex multiplication routines at http://6502.org/source/ and http://6502org.wikidot.com/software-math-intmul and http://6502org.wikidot.com/errata-softw ... forth#toc1

I did not try the code above, but it's simple enough that hopefully I didn't make a dumb mistake.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 05, 2010 12:51 pm 
Offline

Joined: Fri Nov 21, 2008 3:07 pm
Posts: 31
weird but i have an error on
STZ p
STZ p+1
i dont know why... still im looking...

BTW im still new in this programing lang... sorry if i dont notice..


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 05, 2010 1:58 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
STZ is a 65C02 opcode and is invalid for 6502 devices. Check your assembler to see if you can enable 65C02 opcodes. Otherwise, you can substitute
Code:
   LDA #$00
   STA p
   STA p+1


Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 05, 2010 5:40 pm 
Offline

Joined: Fri Nov 21, 2008 3:07 pm
Posts: 31
subtitue where, because i didt that already..
check the code
STA p
STA p+1

already there..


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Nov 06, 2010 2:42 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
Amenofhis wrote:
subtitue where, because i didt that already..
check the code
STA p
STA p+1

already there..


Here is an updated listing with my changes

Code:
salida=io_area+3   ; ("salida" means "output" in Spanish)
salida2= io_area+2
    .ORG $0200
     sed

;     STZ p         ; Initialize the product as 0.   *** remove STZ
;     STZ p+1        *** remove STZ
     LDA #$00      ; *** replace with this
     STA p         ; Initialize the product as 0.
     STA p+1

     LDA n2
     BNE f1
     LDA n2+1      ; Now we have a high byte to check too.
     BEQ fin       ; ("fin" means "end" in Spanish)

f1:    LDA p
       CLC
       ADC n1
       STA p

       LDA p+1     ; Insert these 3 lines for 2nd pair of digits.
       ADC n1+1    ; (Do not CLC first this time.)
       STA p+1

    ;  DEC n2
       LDA n2
       SEC
       SBC #1
       STA n2
     BNE f1
       LDA n2+1     ; If the low byte turned to 0, check the high byte.
     BEQ fin        ; If it was already 0, you're done.
       SBC #1       ; Otherwise decrement it
       STA n2+1
     BRA f1         ; and continue looping.


fin: LDA p          ; Now transfer both output bytes to "salida".
     STA salida
     LDA p+1
     STA salida+1
     BRK
 
     n1: .db $10    ; multiplicand
     n2: .db $15    ; multiplier
     p:  .DB $0     ; product


Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 09, 2010 10:34 pm 
Offline

Joined: Fri Nov 21, 2008 3:07 pm
Posts: 31
dude i have a error in row 36
with this
BRA F1 ; and continue looping.

why??


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 09, 2010 11:14 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
What is the error?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 09, 2010 11:18 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
Amenofhis wrote:
dude i have a error in row 36
with this
BRA F1 ; and continue looping.

why??


BRA is also a 65C02 opcode. replace it with JMP F1 for 6502 compatability. Sorry, I should have caught that one too.

Daryl


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 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: