Path: utzoo!utgpu!attcan!uunet!tektronix!reed!kamath From: kamath@reed.UUCP (Sean Kamath) Newsgroups: comp.sys.apple Subject: Re: assembly Keywords: stuff Message-ID: <11913@reed.UUCP> Date: 26 Feb 89 02:18:16 GMT References: <409@odin.cs.hw.ac.uk> <651@dsacg2.UUCP> <11134@s.ms.uky.edu> <794@cs-spool.calgary.UUCP> Reply-To: kamath@reed.UUCP (Sean Kamath) Organization: Reed College, Portland OR Lines: 65 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!)