Page 1 of 2

I need a help with this

Posted: Thu Nov 04, 2010 7:57 pm
by Amenofhis
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

Posted: Thu Nov 04, 2010 9:11 pm
by GARTHWILSON
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: Select all

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!)

Posted: Thu Nov 04, 2010 9:26 pm
by Amenofhis
that could go more than 99.. 1xx or more..

Posted: Thu Nov 04, 2010 9:43 pm
by GARTHWILSON
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.

Posted: Thu Nov 04, 2010 10:14 pm
by Amenofhis
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...

Posted: Thu Nov 04, 2010 10:28 pm
by GARTHWILSON
You will always have trouble getting help if you don't pay more attention to detail! You did not answer my question.

Posted: Thu Nov 04, 2010 10:35 pm
by Amenofhis
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..

Posted: Fri Nov 05, 2010 2:33 am
by GARTHWILSON
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: Select all

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.

Posted: Fri Nov 05, 2010 12:51 pm
by Amenofhis
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..

Posted: Fri Nov 05, 2010 1:58 pm
by 8BIT
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: Select all

   LDA #$00
   STA p
   STA p+1
Daryl

Posted: Fri Nov 05, 2010 5:40 pm
by Amenofhis
subtitue where, because i didt that already..
check the code
STA p
STA p+1

already there..

Posted: Sat Nov 06, 2010 2:42 am
by 8BIT
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: Select all

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

Posted: Tue Nov 09, 2010 10:34 pm
by Amenofhis
dude i have a error in row 36
with this
BRA F1 ; and continue looping.

why??

Posted: Tue Nov 09, 2010 11:14 pm
by kc5tja
What is the error?

Posted: Tue Nov 09, 2010 11:18 pm
by 8BIT
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