[comp.sys.apple] assembly

demarco@cpsc.ucalgary.ca (Vince Demarco) (02/25/89)

;*	RESULT = (W - (( X + 77 )* Y) )  + 45) * (Z - 77) )


How would i write a 6502 program to calculate the above expression
no printing or result needs too be done and the variable values are
hard coded into the program

W=77
x=3
y=4
z=82

Please do it in a form merlin would recognize.

Thanks in advance, 

I know how to do this in pdp-11 but how is it done in 6502 assmbler

Vince

demarco@CPSC.UCalgary.CA

kamath@reed.UUCP (Sean Kamath) (02/26/89)

In article <794@cs-spool.calgary.UUCP> demarco@cpsc.ucalgary.ca (Vince Demarco) writes:
>
>;*	RESULT = (W - (( X + 77 )* Y) )  + 45) * (Z - 77) )
>
>
>How would i write a 6502 program to calculate the above expression
>no printing or result needs too be done and the variable values are
>hard coded into the program
>
>W=77
>x=3
>y=4
>z=82
>
>Please do it in a form merlin would recognize.
>
>I know how to do this in pdp-11 but how is it done in 6502 assmbler
>
>Vince

OK.  Let's have some fun.  A) Your parentheses aren't matched. B) assuming
that you meant "(((W - ((X + 77)* Y)) + 45) * (Z - 77))" then the answer is
-990.  Since this is bigger than a byte, let's use two's complement
arithmatic using 2 bytes, or a short.  Then 65535-990 = 64545, or $FC21.
Therefore, the easiest way to do what you want is to say:

	lda #$21
	sta result
	lda #$FC
	sta result

and be done with it.

Ah, but I bet you want to do it with other numbers. . .

Well, let's rewrite it a little easier to code:

(W+45-Y(X+77)) * (Z-77)

Now, in psuedo code:

	add 77 to X save in t1
	subtract 77 from Z and save in t2
	add 45 to W and save in t3

	* now is looke like (t3 - Y*t1) * t2
	* so now we have to do 16 bit arithmatic.
	* using the macros ADD16 and MUL16

	MUL16 Y,t1 and save in t1
	ADD16 t3,t1 and save in t1
	MUL16 t1,t2 save in result.

There are mul16 and add16 in the merlin macros that come with the assembler.

I actually ended up writing the code to do this, but I don't want to give it
out mainly because I'm not sure its what you want.  If people *really* want
me to post this rediculous code, I will.  It's pretty basic, though.

Sean kamath
-- 
UUCP:  {decvax allegra ucbcad ucbvax hplabs}!tektronix!reed!kamath
CSNET: reed!kamath@Tektronix.CSNET  ||  BITNET: kamath@reed.BITNET
ARPA: kamath%reed.bitnet@cunyvm.cuny.edu
US Snail: 3934 SE Boise, Portland, OR  97202-3126 (I hate 4 line .sigs!)

demarco@cpsc.ucalgary.ca (Vince Demarco) (02/27/89)

Thanks alot for the info, it doens't look that bad to do in the apple

Thanks alot for the information about doing the computation.


Vince

reply to

demarco@CPSC.UCalgary.CA

mw22+@andrew.cmu.edu (Michael Alan Wertheim) (02/28/89)

Before you can get a meaningful answer:

Are these numbers 8-bit, 16-bit, signed. unsigned, etc.

You DO realize that the 6502 doesn't have mulitply or divide instructions.....



Michael Wertheim
Carnegie Mellon University
Pittsburgh, PA

Arpa: mw22@andrew.cmu.edu
Bitnet: mw22%andrew@cmccvb

===========================
"God is money in action."