6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 16, 2024 5:27 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: i need help
PostPosted: Wed Nov 13, 2002 9:23 pm 
Offline

Joined: Wed Nov 13, 2002 9:17 pm
Posts: 2
Can someone tell me please what this code does.
I need it for my studies. Thank you.

Code:
EndL1    jsr CrLf             
         lda #$00             
         tax                 
Init     sta $0800,x         
         inx                 
         cpx #$00             
         bne Init             
         ldy #$00             
Eingabe  jsr ReadChr         
         cmp #CR             
         beq VorAus           
         jsr WriteChr         
         tax                 
         inc $0800,x         
         iny                 
         cpy #$3C             
         bne Eingabe


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 14, 2002 12:01 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8541
Location: Southern California
Line 1, JSR CrLf, calls a subroutine which no doubt outputs a carriage-return character and a line-feed charcter to whatever output device is selected.

LDA #00 and TAX puts 0 in both the accumulator and the X index register. Since you're going to fill a page of memory with 0's, the 65c02 could replace these two lines with LDX #00 and make the next line STZ (STore Zero) instead of STA.

Then you have a loop to zero-out 256 bytes of memory starting at address $0800. "Init" is a label marking the top of the loop where the BNE three lines down will branch up to repeatedly until the index register X rolls over back to 0.

Actually the CPX #0 is a wasted line, since this action happens automatically anyway with the INX. CPX #0 can be omitted to speed things up a little while still doing exactly the same thing.

The next loop will run as many as $3C times, with Y values from 0 to $3B. Y is used as the loop counter, being initialized by LDY #0. "Eingabe" labels the top of the loop for the BNE below to branch up to until finished.

Read a character and see if it's a carriage-return ($0D). If so, branch out of the loop to label VorAus. Otherwise keep going and write the charcter. What you're writing to is not clear here. The loop records how many times each character occurs; so after writing the character, you're going to increment the corresponding memory byte, whose address is $0800 plus the character's value which has been transferred to X by using TAX.

Increment Y (the loop counter), and loop back up again only if you are not up to the maximum number of times you wanted to run the loop. When you repeat the loop, you will read the next character.

If the Y value is not needed for anything in subroutine WriteChr, then it would be more efficient to initialize Y to $3C and then do DEY instead of INY. In other words, you're going to count down instead of up. Then you can get rid of the CPY line, and the "BNE Eingabe" will still work correctly because of the automatic compare-to-zero that happens with an increment or decrement instruction.

Get a good grade in your class and join us often on the forum.

Garth


Top
 Profile  
Reply with quote  
 Post subject: Re: 6502 Homework
PostPosted: Thu Nov 14, 2002 3:13 am 
Offline
Site Admin
User avatar

Joined: Fri Aug 30, 2002 1:08 am
Posts: 281
Location: Northern California
Pete,

Just curious, where are you going to school that's teaching 6502 assembly? You'd be surprised at the number of homework questions that get e-mailed to 6502.org.

Regards,
Mike

_________________
- Mike Naberezny (mike@naberezny.com) http://6502.org


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 14, 2002 10:03 am 
Offline

Joined: Wed Nov 13, 2002 9:17 pm
Posts: 2
Hi Mike

I am studying economic computer science in Wedel ,Germany. There we have weekly tasks in e.g. 6502 assembly.

I hope I it wouldnt be a problem to ask something about 6502 in the future.

Regards Pete


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

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