Google Answers Logo
View Question
 
Q: Convert c into 6502 ( No Answer,   6 Comments )
Question  
Subject: Convert c into 6502
Category: Computers > Programming
Asked by: mott85-ga
List Price: $10.00
Posted: 14 May 2005 17:25 PDT
Expires: 18 May 2005 08:55 PDT
Question ID: 521703
Can anyone convert this c function to 6502 asm

int main(void)
{
int i ;
inx=0;
for(i=0;i<10; I++)
{
x++
}
return (0);
}
Answer  
There is no answer at this time.

Comments  
Subject: Re: Convert c into 6502
From: bozo99-ga on 14 May 2005 19:31 PDT
 
It is faulty C.
Your variables "inx", "I" and "x" are undeclared.
Your "X++" line does not end in a semicolon.
Even if it worked it would loop but save no files and write no output
so the only effect would be to consume CPU time.

Using the X register as the loop variable you would want something
like this.

    LDX #0             # load 0 into X register
LOOP                   # label
                       # space for loop content if desired
    INX                # add 1 to X (where 255+1=0)
    CPX #11
    BNE LOOP
Subject: Re: Convert c into 6502
From: bozo99-ga on 14 May 2005 19:34 PDT
 
CPX #11            # compare X register to 11
    BNE LOOP           # Branch if Not Equal (using result of compare operation)
                       # to the LOOP variable which must be sufficiently close
                       # in the code because long jumps are specified differently
Subject: Re: Convert c into 6502
From: mott85-ga on 14 May 2005 19:53 PDT
 
so that converst the entire thing into 6502? i wouf of thought it
would of needed to be longer
Subject: Re: Convert c into 6502
From: anonoboy-ga on 15 May 2005 20:27 PDT
 
Writing English like that, how could you have expected to write good code?
Subject: Re: Convert c into 6502
From: pgmer6809-ga on 16 May 2005 21:30 PDT
 
THe assembly code has a bug in it.
The original C "for" statement was: for (i=0; i< 10; i++) { .... }
I.e. 10 times through the loop, with zero being the first time.
Note that i (not I) should never equal 10 (and neither should x).
So the BNE #11 statement should be instead BNE #10.
Subject: Re: Convert c into 6502
From: pgmer6809-ga on 16 May 2005 21:32 PDT
 
Oh Oh.
I mean CPX #11 should be CPX #10. Then BNE.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy