Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
MOS Technology 6502
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Example code=== The following 6502 [[assembly language]] [[source code]] is for a subroutine named <code>TOLOWER</code>, which copies a [[null-terminated string|null-terminated]] [[string (computer science)|character string]] from one location to another, converting upper-case letter characters to lower-case letters. The string being copied is the "source", and the string into which the converted source is stored is the "destination". <!-- NOTE: This is not intended to be optimized code, but to illustrate the variety of instructions available on the CPU. --> <!-- NOTE: Now it is optimized. :) Best to post examples that reflect good programming style & efficiency, rather than examples that are obfuscated in an effort to use the maximum number of different instructions. Also, please avoid using non-standard assembler syntax in 6502 programming examples, e.g., a pseudo-op such as DW, which is not supported by all assemblers. The MOS Technology standard exists for a reason. --> {| | style="vertical-align:top;"| <pre> 0080 0080 00 04 0082 00 05 0600 0600 A0 00 0602 B1 80 0604 F0 11 0606 C9 41 0608 90 06 060A C9 5B 060C B0 02 060E 09 20 0610 91 82 0612 C8 0613 D0 ED 0615 38 0616 60 0617 91 82 0619 18 061A 60 061B </pre> | <syntaxhighlight lang="ca65" highlight="19"> ; TOLOWER: ; ; Convert a null-terminated character string to all lower case. ; Maximum string length is 255 characters, plus the null term- ; inator. ; ; Parameters: ; ; SRC β Source string address ; DST β Destination string address ; ORG $0080 ; SRC .WORD $0400 ;source string pointer DST .WORD $0500 ;destination string pointer ; ORG $0600 ;execution start address ; TOLOWER LDY #$00 ;starting index ; LOOP LDA (SRC),Y ;get from source string BEQ DONE ;end of string ; CMP #'A' ;if lower than UC alphabet... BCC SKIP ;copy unchanged ; CMP #'Z'+1 ;if greater than UC alphabet... BCS SKIP ;copy unchanged ; ORA #%00100000 ;convert to lower case ; SKIP STA (DST),Y ;store to destination string INY ;bump index BNE LOOP ;next character ; ; NOTE: If Y wraps the destination string will be left in an undefined ; state. We set carry to indicate this to the calling function. ; SEC ;report string too long error &... RTS ;return to caller ; DONE STA (DST),Y ;terminate destination string CLC ;report conversion completed &... RTS ;return to caller ; .END </syntaxhighlight> |}
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
MOS Technology 6502
(section)
Add topic