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
Motorola 68000
(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 68000 [[assembly language|assembly]] code below is for a subroutine named {{code|strtolower}}, which copies a null-terminated string of 8-bit characters to a destination string, converting all alphabetic characters to lower case. <!--NOTE: This is not intended to be optimized code, but to illustrate the variety of instructions available on the CPU. --> <!--NOTE: Opcodes were assembled by hand, so there may be errors. --> {| | <syntaxhighlight lang="text"> 00100000 00100000 4E56 0000 00100004 306E 0008 00100008 326E 000C 0010000C 1018 0010000E 0C40 0041 00100012 6500 000E 00100016 0C40 005A 0010001A 6200 0006 0010001E 0640 0020 00100022 12C0 00100024 66E6 00100026 4E5E 00100028 4E75 0010002A </syntaxhighlight> | <syntaxhighlight lang="tasm" highlight="10"> ; strtolower: ; Copy a null-terminated ASCII string, converting ; all alphabetic characters to lower case. ; ; Entry parameters: ; (SP+0): Return address ; (SP+4): Source string address ; (SP+8): Target string address org $00100000 ;Start at 00100000 strtolower public link a6,#0 ;Set up stack frame movea 8(a6),a0 ;A0 = src, from stack movea 12(a6),a1 ;A1 = dst, from stack loop move.b (a0)+,d0 ;Load D0 from (src), incr src cmpi #'A',d0 ;If D0 < 'A', blo copy ;skip cmpi #'Z',d0 ;If D0 > 'Z', bhi copy ;skip addi #'a'-'A',d0 ;D0 = lowercase(D0) copy move.b d0,(a1)+ ;Store D0 to (dst), incr dst bne loop ;Repeat while D0 <> NUL unlk a6 ;Restore stack frame rts ;Return end </syntaxhighlight> |} The subroutine establishes a [[call frame]] using register A6 as the frame pointer. This kind of [[calling convention]] supports [[reentrancy (computing)|reentrant]] and [[recursion (computer science)|recursive]] code and is typically used by languages like [[C (programming language)|C]] and [[C++]]. The subroutine then retrieves the parameters passed to it ({{code|src}} and {{code|dst}}) from the stack. It then loops, reading an ASCII character (one byte) from the {{code|src}} string, checking whether it is a capital alphabetic character, and if so, converting it into a lower-case character, otherwise leaving it as it is, then writing the character into the {{code|dst}} string. Finally, it checks whether the character was a [[null character]]; if not, it repeats the loop, otherwise it restores the previous stack frame (and A6 register) and returns. Note that the string pointers (registers A0 and A1) are auto-incremented in each iteration of the loop. In contrast, the code below is for a stand-alone function, even on the most restrictive version of AMS for the [[TI-89 series]] of calculators, being kernel-independent, with no values looked up in tables, files or libraries when executing, no system calls, no exception processing, minimal registers to be used, nor the need to save any. It is valid for historical [[Julian calendar|Julian]] dates from 1 March 1 AD, or for [[Gregorian calendar|Gregorian]] ones. In less than two dozen operations it calculates a day number compatible with [[ISO 8601#Week dates|ISO 8601]] when called with three inputs stored at their corresponding LOCATIONS: ; ; WDN, an address - for storing result d0 ; FLAG, 0 or 2 - to choose between Julian or Gregorian, respectively ; DATE, year0mda - date stamp as binary word&byte&byte in basic ISO-format ;(YEAR, year ~ YEAR=DATE due to big-[[Endianness#Newer architectures|endianness]]) ; {{codett|lang=tasm|move.l DATE,d0}} {{codett|lang=tasm|move.l d0,d1}} ; ; Apply step 1 - [[SuperBASIC#Example|Lachman's congruence]] {{codett|lang=tasm|andi.l #$f00,d0}} {{codett|lang=tasm|divu #100,d0}} {{codett|lang=tasm|addi.w #193,d0}} {{codett|lang=tasm|andi.l #$ff,d0}} {{codett|lang=tasm|divu #100,d0 ; d0 has the month index i in the upper word (mod 100)}} ; ; Apply step 2 - Finding spqr as the year of the Julian leap day preceding DATE {{codett|lang=tasm|swap d0}} {{codett|lang=tasm|andi.l #$ffff,d0}} {{codett|lang=tasm|add.b d1,d0}} {{codett|lang=tasm|add.w YEAR,d0}} {{codett|lang=tasm|subi.l #$300,d1}} {{codett|lang=tasm|lsr #2,d1}} {{codett|lang=tasm|swap d1}} {{codett|lang=tasm|add.w d1,d0 ; spqr/4 + year + i + da}} ; ; (Apply step 0 - Gregorian adjustment) {{codett|lang=tasm|mulu FLAG,d1}} {{codett|lang=tasm|divu #50,d1}} {{codett|lang=tasm|mulu #25,d1}} {{codett|lang=tasm|lsr #2,d1}} {{codett|lang=tasm|add.w d1,d0}} {{codett|lang=tasm|add.w FLAG,d0 ; (sp32div16) + spqr/4 + year + i + da}} ; {{codett|lang=tasm|divu #7,d0}} {{codett|lang=tasm|swap d0 ; d0.w becomes the day number}} ; {{codett|lang=tasm|move.w d0,WDN ; returns the day number to address WDN}} {{codett|lang=tasm|rts}} ; ; Days of the week correspond to day numbers of the week as: ; Sun=0 Mon=1 Tue=2 Wed=3 Thu=4 Fri=5 Sat=6 ;
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
Motorola 68000
(section)
Add topic