home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
browse contents |
view JSON data
|
view as text
This file was processed as: LaTeX Document
(document/latex).
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| LaTeX Document (document/latex)
| magic
| Supported |
1%
| dexvert
| NWiper Show (other/nWiperShow)
| ext
| Unsupported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| LaTeX document, ASCII text, with CR line terminators
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| fmt/281 LaTeX (Subdocument)
| default
| |
100%
| detectItEasy
| Format: plain text[CR]
| default (weak)
|
|
id metadata |
---|
key | value |
---|
macFileType | [TEXT] |
macFileCreator | [MPS ] |
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 41 20 73 6d 61 6c 6c |\section|{A small|
|00000010| 20 61 73 73 65 6d 62 6c | 65 72 20 66 6f 72 20 74 | assembl|er for t|
|00000020| 68 65 20 4d 49 50 53 7d | 0d 54 68 69 73 20 69 73 |he MIPS}|.This is|
|00000030| 20 70 61 72 74 20 6f 66 | 20 74 68 65 20 63 6f 64 | part of| the cod|
|00000040| 65 20 67 65 6e 65 72 61 | 74 6f 72 20 66 6f 72 20 |e genera|tor for |
|00000050| 53 74 61 6e 64 61 72 64 | 20 4d 4c 20 6f 66 20 4e |Standard| ML of N|
|00000060| 65 77 20 4a 65 72 73 65 | 79 2e 0d 57 65 20 67 65 |ew Jerse|y..We ge|
|00000070| 6e 65 72 61 74 65 20 63 | 6f 64 65 20 69 6e 20 73 |nerate c|ode in s|
|00000080| 65 76 65 72 61 6c 20 73 | 74 61 67 65 73 2e 0d 54 |everal s|tages..T|
|00000090| 68 69 73 20 69 73 20 6e | 65 61 72 6c 79 20 74 68 |his is n|early th|
|000000a0| 65 20 6c 6f 77 65 73 74 | 20 73 74 61 67 65 3b 20 |e lowest| stage; |
|000000b0| 69 74 20 69 73 20 6c 69 | 6b 65 20 61 6e 20 61 73 |it is li|ke an as|
|000000c0| 73 65 6d 62 6c 65 72 2e | 0d 54 68 65 20 75 73 65 |sembler.|.The use|
|000000d0| 72 20 63 61 6e 20 63 61 | 6c 6c 20 61 6e 79 20 66 |r can ca|ll any f|
|000000e0| 75 6e 63 74 69 6f 6e 20 | 69 6e 20 74 68 65 20 5b |unction |in the [|
|000000f0| 5b 4d 49 50 53 43 4f 44 | 45 52 5d 5d 20 73 69 67 |[MIPSCOD|ER]] sig|
|00000100| 6e 61 74 75 72 65 2e 0d | 45 61 63 68 20 6f 6e 65 |nature..|Each one|
|00000110| 20 63 6f 72 72 65 73 70 | 6f 6e 64 73 20 74 6f 20 | corresp|onds to |
|00000120| 61 6e 20 61 73 73 65 6d | 62 6c 65 72 20 70 73 65 |an assem|bler pse|
|00000130| 75 64 6f 2d 69 6e 73 74 | 72 75 63 74 69 6f 6e 2e |udo-inst|ruction.|
|00000140| 0d 4d 6f 73 74 20 63 6f | 72 72 65 73 70 6f 6e 64 |.Most co|rrespond|
|00000150| 20 74 6f 20 73 69 6e 67 | 6c 65 20 4d 49 50 53 20 | to sing|le MIPS |
|00000160| 69 6e 73 74 72 75 63 74 | 69 6f 6e 73 2e 0d 54 68 |instruct|ions..Th|
|00000170| 65 20 61 73 73 65 6d 62 | 6c 65 72 20 72 65 6d 65 |e assemb|ler reme|
|00000180| 6d 62 65 72 73 20 61 6c | 6c 20 74 68 65 20 69 6e |mbers al|l the in|
|00000190| 73 74 72 75 63 74 69 6f | 6e 73 20 74 68 61 74 20 |structio|ns that |
|000001a0| 68 61 76 65 20 62 65 65 | 6e 20 0d 72 65 71 75 65 |have bee|n .reque|
|000001b0| 73 74 65 64 2c 20 61 6e | 64 20 77 68 65 6e 20 5b |sted, an|d when [|
|000001c0| 5b 63 6f 64 65 67 65 6e | 5d 5d 20 69 73 20 63 61 |[codegen|]] is ca|
|000001d0| 6c 6c 65 64 20 69 74 20 | 67 65 6e 65 72 61 74 65 |lled it |generate|
|000001e0| 73 20 4d 49 50 53 0d 63 | 6f 64 65 20 66 6f 72 20 |s MIPS.c|ode for |
|000001f0| 74 68 65 6d 2e 0d 0d 53 | 6f 6d 65 20 6f 74 68 65 |them...S|ome othe|
|00000200| 72 20 73 74 72 75 63 74 | 75 72 65 20 77 69 6c 6c |r struct|ure will|
|00000210| 20 62 65 20 61 62 6c 65 | 20 74 6f 20 75 73 65 20 | be able| to use |
|00000220| 74 68 65 20 4d 49 50 53 | 20 73 74 72 75 63 74 75 |the MIPS| structu|
|00000230| 72 65 20 74 6f 20 69 6d | 70 6c 65 6d 65 6e 74 0d |re to im|plement.|
|00000240| 61 20 5b 5b 43 4d 41 43 | 48 49 4e 45 5d 5d 2c 20 |a [[CMAC|HINE]], |
|00000250| 77 68 69 63 68 20 69 73 | 20 74 68 65 20 61 62 73 |which is| the abs|
|00000260| 74 72 61 63 74 20 6d 61 | 63 68 69 6e 65 20 74 68 |tract ma|chine th|
|00000270| 61 74 20 4d 4c 20 74 68 | 69 6e 6b 73 20 69 74 20 |at ML th|inks it |
|00000280| 69 73 20 72 75 6e 6e 69 | 6e 67 0d 6f 6e 2e 0d 28 |is runni|ng.on..(|
|00000290| 57 68 61 74 20 72 65 61 | 6c 6c 79 20 68 61 70 70 |What rea|lly happ|
|000002a0| 65 6e 73 20 69 73 20 61 | 20 66 75 6e 63 74 6f 72 |ens is a| functor|
|000002b0| 20 6d 61 70 73 20 73 6f | 6d 65 20 73 74 72 75 63 | maps so|me struc|
|000002c0| 74 75 72 65 20 0d 69 6d | 70 6c 65 6d 65 6e 74 69 |ture .im|plementi|
|000002d0| 6e 67 20 5b 5b 4d 49 50 | 53 43 4f 44 45 52 5d 5d |ng [[MIP|SCODER]]|
|000002e0| 20 74 6f 20 61 20 64 69 | 66 66 65 72 65 6e 74 20 | to a di|fferent |
|000002f0| 73 74 72 75 63 74 75 72 | 65 20 69 6d 70 6c 65 6d |structur|e implem|
|00000300| 65 6e 74 69 6e 67 20 0d | 5b 5b 43 4d 41 43 48 49 |enting .|[[CMACHI|
|00000310| 4e 45 5d 5d 2e 29 0d 0d | 7b 5c 65 6d 20 41 6e 79 |NE]].)..|{\em Any|
|00000320| 20 66 75 6e 63 74 69 6f | 6e 20 75 73 69 6e 67 20 | functio|n using |
|00000330| 61 20 73 74 72 75 63 74 | 75 72 65 20 6f 66 20 74 |a struct|ure of t|
|00000340| 68 69 73 20 73 69 67 6e | 61 74 75 72 65 20 6d 75 |his sign|ature mu|
|00000350| 73 74 20 61 76 6f 69 64 | 0d 74 6f 75 63 68 69 6e |st avoid|.touchin|
|00000360| 67 20 72 65 67 69 73 74 | 65 72 73 20 31 7e 61 6e |g regist|ers 1~an|
|00000370| 64 7e 33 31 2e 0d 54 68 | 6f 73 65 20 72 65 67 69 |d~31..Th|ose regi|
|00000380| 73 74 65 72 73 20 61 72 | 65 20 72 65 73 65 72 76 |sters ar|e reserv|
|00000390| 65 64 20 66 6f 72 20 75 | 73 65 20 62 79 20 74 68 |ed for u|se by th|
|000003a0| 65 20 61 73 73 65 6d 62 | 6c 65 72 2e 7d 0d 0d 40 |e assemb|ler.}..@|
|000003b0| 20 48 65 72 65 20 69 73 | 20 74 68 65 20 73 69 67 | Here is| the sig|
|000003c0| 6e 61 74 75 72 65 20 6f | 66 20 74 68 65 20 61 73 |nature o|f the as|
|000003d0| 73 65 6d 62 6c 65 72 2c | 20 5b 5b 4d 49 50 53 43 |sembler,| [[MIPSC|
|000003e0| 4f 44 45 52 5d 5d 2e 0d | 49 74 20 63 61 6e 20 62 |ODER]]..|It can b|
|000003f0| 65 20 65 78 74 72 61 63 | 74 65 64 20 66 72 6f 6d |e extrac|ted from|
|00000400| 20 74 68 69 73 20 66 69 | 6c 65 20 62 79 0d 24 24 | this fi|le by.$$|
|00000410| 5c 68 62 6f 78 7b 5c 74 | 74 20 6e 6f 74 61 6e 67 |\hbox{\t|t notang|
|00000420| 6c 65 20 6d 69 70 73 69 | 6e 73 74 72 2e 6e 77 20 |le mipsi|nstr.nw |
|00000430| 2d 52 73 69 67 6e 61 74 | 75 72 65 7d 2e 24 24 0d |-Rsignat|ure}.$$.|
|00000440| 3c 3c 73 69 67 6e 61 74 | 75 72 65 3e 3e 3d 0d 73 |<<signat|ure>>=.s|
|00000450| 69 67 6e 61 74 75 72 65 | 20 4d 49 50 53 43 4f 44 |ignature| MIPSCOD|
|00000460| 45 52 20 3d 20 73 69 67 | 0d 0d 28 2a 20 41 73 73 |ER = sig|..(* Ass|
|00000470| 65 6d 62 6c 65 72 20 66 | 6f 72 20 74 68 65 20 4d |embler f|or the M|
|00000480| 49 50 53 20 63 68 69 70 | 20 2a 29 0d 0d 65 71 74 |IPS chip| *)..eqt|
|00000490| 79 70 65 20 4c 61 62 65 | 6c 0d 64 61 74 61 74 79 |ype Labe|l.dataty|
|000004a0| 70 65 20 52 65 67 69 73 | 74 65 72 20 3d 20 52 65 |pe Regis|ter = Re|
|000004b0| 67 20 6f 66 20 69 6e 74 | 0d 20 20 20 20 28 2a 20 |g of int|. (* |
|000004c0| 52 65 67 69 73 74 65 72 | 73 20 31 20 61 6e 64 20 |Register|s 1 and |
|000004d0| 33 31 20 61 72 65 20 72 | 65 73 65 72 76 65 64 20 |31 are r|eserved |
|000004e0| 66 6f 72 20 75 73 65 20 | 62 79 20 74 68 69 73 20 |for use |by this |
|000004f0| 61 73 73 65 6d 62 6c 65 | 72 20 2a 29 0d 64 61 74 |assemble|r *).dat|
|00000500| 61 74 79 70 65 20 45 41 | 20 3d 20 44 69 72 65 63 |atype EA| = Direc|
|00000510| 74 20 6f 66 20 52 65 67 | 69 73 74 65 72 20 7c 20 |t of Reg|ister | |
|00000520| 49 6d 6d 65 64 20 6f 66 | 20 69 6e 74 20 7c 20 49 |Immed of| int | I|
|00000530| 6d 6d 65 64 6c 61 62 20 | 6f 66 20 4c 61 62 65 6c |mmedlab |of Label|
|00000540| 0d 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |. | |
|00000550| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000560| 20 28 2a 20 65 66 66 65 | 63 74 69 76 65 20 61 64 | (* effe|ctive ad|
|00000570| 64 72 65 73 73 20 2a 29 | 0d 0d 73 74 72 75 63 74 |dress *)|..struct|
|00000580| 75 72 65 20 4d 20 3a 20 | 73 69 67 0d 0d 20 20 20 |ure M : |sig.. |
|00000590| 20 28 2a 20 45 6d 69 74 | 20 76 61 72 69 6f 75 73 | (* Emit| various|
|000005a0| 20 63 6f 6e 73 74 61 6e | 74 73 20 69 6e 74 6f 20 | constan|ts into |
|000005b0| 74 68 65 20 63 6f 64 65 | 20 2a 29 0d 0d 20 20 20 |the code| *).. |
|000005c0| 20 76 61 6c 20 65 6d 69 | 74 73 74 72 69 6e 67 20 | val emi|tstring |
|000005d0| 3a 20 73 74 72 69 6e 67 | 20 2d 3e 20 75 6e 69 74 |: string| -> unit|
|000005e0| 20 20 20 20 20 28 2a 20 | 70 75 74 20 61 20 6c 69 | (* |put a li|
|000005f0| 74 65 72 61 6c 20 73 74 | 72 69 6e 67 20 69 6e 74 |teral st|ring int|
|00000600| 6f 20 74 68 65 0d 20 20 | 20 20 20 20 20 20 20 20 |o the. | |
|00000610| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000620| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000630| 20 63 6f 64 65 20 28 6e | 75 6c 6c 2d 74 65 72 6d | code (n|ull-term|
|00000640| 69 6e 61 74 65 64 3f 29 | 20 61 6e 64 0d 20 20 20 |inated?)| and. |
|00000650| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000660| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000670| 20 20 20 20 20 20 20 20 | 65 78 74 65 6e 64 20 77 | |extend w|
|00000680| 69 74 68 20 6e 75 6c 6c | 73 20 74 6f 20 34 2d 62 |ith null|s to 4-b|
|00000690| 79 74 65 20 0d 20 20 20 | 20 20 20 20 20 20 20 20 |yte . | |
|000006a0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000006b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000006c0| 62 6f 75 6e 64 61 72 79 | 2e 20 4a 75 73 74 20 63 |boundary|. Just c|
|000006d0| 68 61 72 73 2c 20 6e 6f | 20 0d 20 20 20 20 20 20 |hars, no| . |
|000006e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000006f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000700| 20 20 20 20 20 64 65 73 | 63 72 69 70 74 6f 72 20 | des|criptor |
|00000710| 6f 72 20 6c 65 6e 67 74 | 68 20 2a 29 0d 20 20 20 |or lengt|h *). |
|00000720| 20 65 78 63 65 70 74 69 | 6f 6e 20 42 61 64 52 65 | excepti|on BadRe|
|00000730| 61 6c 20 6f 66 20 73 74 | 72 69 6e 67 0d 20 20 20 |al of st|ring. |
|00000740| 20 76 61 6c 20 6c 6f 77 | 5f 6f 72 64 65 72 5f 6f | val low|_order_o|
|00000750| 66 66 73 65 74 20 3a 20 | 69 6e 74 09 09 28 2a 20 |ffset : |int..(* |
|00000760| 64 6f 65 73 20 74 68 65 | 20 6c 6f 77 2d 6f 72 64 |does the| low-ord|
|00000770| 65 72 20 77 6f 72 64 20 | 6f 66 20 61 20 0d 09 09 |er word |of a ...|
|00000780| 09 09 09 20 20 20 66 6c | 6f 61 74 69 6e 67 20 70 |... fl|oating p|
|00000790| 6f 69 6e 74 20 6c 69 74 | 65 72 61 6c 20 63 6f 6d |oint lit|eral com|
|000007a0| 65 0d 09 09 09 09 09 20 | 20 20 66 69 72 73 74 20 |e...... | first |
|000007b0| 28 30 29 20 6f 72 20 73 | 65 63 6f 6e 64 20 28 31 |(0) or s|econd (1|
|000007c0| 29 20 2a 29 0d 20 20 20 | 20 76 61 6c 20 72 65 61 |) *). | val rea|
|000007d0| 6c 63 6f 6e 73 74 20 3a | 20 73 74 72 69 6e 67 20 |lconst :| string |
|000007e0| 2d 3e 20 75 6e 69 74 20 | 20 20 20 20 20 28 2a 20 |-> unit | (* |
|000007f0| 65 6d 69 74 20 61 20 66 | 6c 6f 61 74 69 6e 67 20 |emit a f|loating |
|00000800| 70 74 20 6c 69 74 65 72 | 61 6c 20 2a 29 0d 20 20 |pt liter|al *). |
|00000810| 20 20 76 61 6c 20 65 6d | 69 74 6c 6f 6e 67 20 3a | val em|itlong :|
|00000820| 20 69 6e 74 20 2d 3e 20 | 75 6e 69 74 20 20 20 20 | int -> |unit |
|00000830| 20 20 20 20 20 20 28 2a | 20 65 6d 69 74 20 61 20 | (*| emit a |
|00000840| 34 2d 62 79 74 65 20 69 | 6e 74 65 67 65 72 20 6c |4-byte i|nteger l|
|00000850| 69 74 65 72 61 6c 20 2a | 29 0d 0d 0d 20 20 20 20 |iteral *|)... |
|00000860| 28 2a 20 4c 61 62 65 6c | 20 62 69 6e 64 69 6e 67 |(* Label| binding|
|00000870| 73 20 61 6e 64 20 65 6d | 69 73 73 69 6f 6e 73 20 |s and em|issions |
|00000880| 2a 29 0d 0d 20 20 20 20 | 76 61 6c 20 6e 65 77 6c |*).. |val newl|
|00000890| 61 62 65 6c 20 3a 20 75 | 6e 69 74 20 2d 3e 20 4c |abel : u|nit -> L|
|000008a0| 61 62 65 6c 20 20 20 20 | 20 20 20 20 28 2a 20 6e |abel | (* n|
|000008b0| 65 77 2c 20 75 6e 62 6f | 75 6e 64 20 6c 61 62 65 |ew, unbo|und labe|
|000008c0| 6c 20 2a 29 0d 20 20 20 | 20 76 61 6c 20 64 65 66 |l *). | val def|
|000008d0| 69 6e 65 20 3a 20 4c 61 | 62 65 6c 20 2d 3e 20 75 |ine : La|bel -> u|
|000008e0| 6e 69 74 20 20 20 20 20 | 20 20 20 20 20 28 2a 20 |nit | (* |
|000008f0| 63 61 75 73 65 20 74 68 | 65 20 6c 61 62 65 6c 20 |cause th|e label |
|00000900| 74 6f 20 62 65 20 62 6f | 75 6e 64 20 74 6f 0d 20 |to be bo|und to. |
|00000910| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000920| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000930| 20 20 20 20 20 20 20 20 | 20 20 74 68 65 20 63 6f | | the co|
|00000940| 64 65 20 61 62 6f 75 74 | 20 74 6f 20 62 65 20 67 |de about| to be g|
|00000950| 65 6e 65 72 61 74 65 64 | 20 2a 29 0d 20 20 20 20 |enerated| *). |
|00000960| 76 61 6c 20 65 6d 69 74 | 6c 61 62 20 3a 20 69 6e |val emit|lab : in|
|00000970| 74 20 2a 20 4c 61 62 65 | 6c 20 2d 3e 20 75 6e 69 |t * Labe|l -> uni|
|00000980| 74 20 20 20 28 2a 20 4c | 33 3a 20 65 6d 69 74 6c |t (* L|3: emitl|
|00000990| 61 62 28 6b 2c 4c 32 29 | 20 69 73 20 65 71 75 69 |ab(k,L2)| is equi|
|000009a0| 76 61 6c 65 6e 74 20 74 | 6f 0d 20 20 20 20 20 20 |valent t|o. |
|000009b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000009c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000009d0| 20 20 20 20 20 4c 33 3a | 20 65 6d 69 74 6c 6f 6e | L3:| emitlon|
|000009e0| 67 28 6b 2b 4c 32 2d 4c | 33 29 20 2a 29 0d 0d 20 |g(k+L2-L|3) *).. |
|000009f0| 20 20 20 28 2a 20 43 6f | 6e 74 72 6f 6c 20 66 6c | (* Co|ntrol fl|
|00000a00| 6f 77 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 73 20 |ow instr|uctions |
|00000a10| 2a 29 0d 0d 20 20 20 20 | 76 61 6c 20 73 6c 74 20 |*).. |val slt |
|00000a20| 3a 20 52 65 67 69 73 74 | 65 72 20 2a 20 45 41 20 |: Regist|er * EA |
|00000a30| 2a 20 52 65 67 69 73 74 | 65 72 20 2d 3e 20 75 6e |* Regist|er -> un|
|00000a40| 69 74 0d 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |it. | |
|00000a50| 20 20 20 28 2a 20 28 6f | 70 65 72 61 6e 64 31 2c | (* (o|perand1,|
|00000a60| 20 6f 70 65 72 61 6e 64 | 32 2c 20 72 65 73 75 6c | operand|2, resul|
|00000a70| 74 29 20 2a 29 0d 20 20 | 20 20 20 20 20 20 20 20 |t) *). | |
|00000a80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000a90| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 28 2a | | (*|
|00000aa0| 20 73 65 74 20 6c 65 73 | 73 20 74 68 61 6e 20 66 | set les|s than f|
|00000ab0| 61 6d 69 6c 79 20 2a 29 | 0d 20 20 20 20 76 61 6c |amily *)|. val|
|00000ac0| 20 62 65 71 20 3a 20 62 | 6f 6f 6c 20 2a 20 52 65 | beq : b|ool * Re|
|00000ad0| 67 69 73 74 65 72 20 2a | 20 52 65 67 69 73 74 65 |gister *| Registe|
|00000ae0| 72 20 2a 20 4c 61 62 65 | 6c 20 2d 3e 20 75 6e 69 |r * Labe|l -> uni|
|00000af0| 74 0d 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |t. | |
|00000b00| 20 20 28 2a 20 28 62 65 | 71 20 6f 72 20 62 6e 65 | (* (be|q or bne|
|00000b10| 2c 20 6f 70 65 72 61 6e | 64 31 2c 20 6f 70 65 72 |, operan|d1, oper|
|00000b20| 61 6e 64 32 2c 20 62 72 | 61 6e 63 68 20 61 64 64 |and2, br|anch add|
|00000b30| 72 65 73 73 29 20 2a 29 | 0d 20 20 20 20 20 20 20 |ress) *)|. |
|00000b40| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000b50| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000b60| 20 28 2a 20 62 72 61 6e | 63 68 20 65 71 75 61 6c | (* bran|ch equal|
|00000b70| 2f 6e 6f 74 20 65 71 75 | 61 6c 20 66 61 6d 69 6c |/not equ|al famil|
|00000b80| 79 20 2a 29 0d 20 20 20 | 20 0d 20 20 20 20 76 61 |y *). | . va|
|00000b90| 6c 20 6a 75 6d 70 20 3a | 20 52 65 67 69 73 74 65 |l jump :| Registe|
|00000ba0| 72 20 2d 3e 20 75 6e 69 | 74 20 20 20 20 20 20 20 |r -> uni|t |
|00000bb0| 20 20 28 2a 20 6a 75 6d | 70 20 72 65 67 69 73 74 | (* jum|p regist|
|00000bc0| 65 72 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 20 2a |er instr|uction *|
|00000bd0| 29 0d 0d 20 20 20 20 76 | 61 6c 20 73 6c 74 5f 64 |).. v|al slt_d|
|00000be0| 6f 75 62 6c 65 20 3a 20 | 52 65 67 69 73 74 65 72 |ouble : |Register|
|00000bf0| 20 2a 20 52 65 67 69 73 | 74 65 72 20 2d 3e 20 75 | * Regis|ter -> u|
|00000c00| 6e 69 74 0d 09 09 09 09 | 09 28 2a 20 66 6c 6f 61 |nit.....|.(* floa|
|00000c10| 74 69 6e 67 20 70 74 20 | 73 65 74 20 6c 65 73 73 |ting pt |set less|
|00000c20| 20 74 68 61 6e 20 2a 29 | 0d 20 20 20 20 76 61 6c | than *)|. val|
|00000c30| 20 73 65 71 5f 64 6f 75 | 62 6c 65 20 3a 20 52 65 | seq_dou|ble : Re|
|00000c40| 67 69 73 74 65 72 20 2a | 20 52 65 67 69 73 74 65 |gister *| Registe|
|00000c50| 72 20 2d 3e 20 75 6e 69 | 74 0d 09 09 09 09 09 28 |r -> uni|t......(|
|00000c60| 2a 20 66 6c 6f 61 74 69 | 6e 67 20 70 74 20 73 65 |* floati|ng pt se|
|00000c70| 74 20 65 71 75 61 6c 20 | 2a 29 0d 20 20 20 20 76 |t equal |*). v|
|00000c80| 61 6c 20 62 63 6f 70 31 | 20 3a 20 62 6f 6f 6c 20 |al bcop1| : bool |
|00000c90| 2a 20 4c 61 62 65 6c 20 | 2d 3e 20 75 6e 69 74 20 |* Label |-> unit |
|00000ca0| 20 20 20 28 2a 20 66 6c | 6f 61 74 69 6e 67 20 70 | (* fl|oating p|
|00000cb0| 74 20 63 6f 6e 64 69 74 | 69 6f 6e 61 6c 20 62 72 |t condit|ional br|
|00000cc0| 61 6e 63 68 20 2a 29 0d | 0d 0d 20 20 20 20 28 2a |anch *).|.. (*|
|00000cd0| 20 41 72 69 74 68 6d 65 | 74 69 63 20 69 6e 73 74 | Arithme|tic inst|
|00000ce0| 72 75 63 74 69 6f 6e 73 | 20 2a 29 0d 20 20 20 20 |ructions| *). |
|00000cf0| 20 20 20 20 20 20 20 20 | 28 2a 20 61 72 67 75 6d | |(* argum|
|00000d00| 65 6e 74 73 20 61 72 65 | 20 28 6f 70 65 72 61 6e |ents are| (operan|
|00000d10| 64 31 2c 20 6f 70 65 72 | 61 6e 64 32 2c 20 72 65 |d1, oper|and2, re|
|00000d20| 73 75 6c 74 29 20 2a 29 | 0d 0d 20 20 20 20 76 61 |sult) *)|.. va|
|00000d30| 6c 20 61 64 64 20 3a 20 | 52 65 67 69 73 74 65 72 |l add : |Register|
|00000d40| 20 2a 20 45 41 20 2a 20 | 52 65 67 69 73 74 65 72 | * EA * |Register|
|00000d50| 20 2d 3e 20 75 6e 69 74 | 0d 20 20 20 20 76 61 6c | -> unit|. val|
|00000d60| 20 61 6e 64 27 20 3a 20 | 52 65 67 69 73 74 65 72 | and' : |Register|
|00000d70| 20 2a 20 45 41 20 2a 20 | 52 65 67 69 73 74 65 72 | * EA * |Register|
|00000d80| 20 2d 3e 20 75 6e 69 74 | 0d 20 20 20 20 76 61 6c | -> unit|. val|
|00000d90| 20 6f 72 20 3a 20 52 65 | 67 69 73 74 65 72 20 2a | or : Re|gister *|
|00000da0| 20 45 41 20 2a 20 52 65 | 67 69 73 74 65 72 20 2d | EA * Re|gister -|
|00000db0| 3e 20 75 6e 69 74 0d 20 | 20 20 20 76 61 6c 20 78 |> unit. | val x|
|00000dc0| 6f 72 20 3a 20 52 65 67 | 69 73 74 65 72 20 2a 20 |or : Reg|ister * |
|00000dd0| 45 41 20 2a 20 52 65 67 | 69 73 74 65 72 20 2d 3e |EA * Reg|ister ->|
|00000de0| 20 75 6e 69 74 0d 20 20 | 20 20 76 61 6c 20 73 75 | unit. | val su|
|00000df0| 62 20 3a 20 52 65 67 69 | 73 74 65 72 20 2a 20 52 |b : Regi|ster * R|
|00000e00| 65 67 69 73 74 65 72 20 | 2a 20 52 65 67 69 73 74 |egister |* Regist|
|00000e10| 65 72 20 2d 3e 20 75 6e | 69 74 0d 20 20 20 20 76 |er -> un|it. v|
|00000e20| 61 6c 20 64 69 76 20 3a | 20 52 65 67 69 73 74 65 |al div :| Registe|
|00000e30| 72 20 2a 20 52 65 67 69 | 73 74 65 72 20 2a 20 52 |r * Regi|ster * R|
|00000e40| 65 67 69 73 74 65 72 20 | 2d 3e 20 75 6e 69 74 0d |egister |-> unit.|
|00000e50| 09 09 09 09 09 28 2a 20 | 66 69 72 73 74 20 61 72 |.....(* |first ar|
|00000e60| 67 20 69 73 20 73 6f 6d | 65 20 72 65 67 69 73 74 |g is som|e regist|
|00000e70| 65 72 0d 09 09 09 09 09 | 20 20 20 67 75 61 72 61 |er......| guara|
|00000e80| 6e 74 65 65 64 20 74 6f | 20 6f 76 65 72 66 6c 6f |nteed to| overflo|
|00000e90| 77 20 77 68 65 6e 0d 09 | 09 09 09 09 20 20 20 61 |w when..|.... a|
|00000ea0| 64 64 65 64 20 74 6f 20 | 69 74 73 65 6c 66 2e 20 |dded to |itself. |
|00000eb0| 20 55 73 65 64 20 74 6f | 0d 09 09 09 09 09 20 20 | Used to|...... |
|00000ec0| 20 64 65 74 65 63 74 20 | 64 69 76 69 64 65 20 62 | detect |divide b|
|00000ed0| 79 20 7a 65 72 6f 2e 20 | 2a 29 0d 20 20 20 20 76 |y zero. |*). v|
|00000ee0| 61 6c 20 6d 75 6c 74 20 | 3a 20 52 65 67 69 73 74 |al mult |: Regist|
|00000ef0| 65 72 20 2a 20 52 65 67 | 69 73 74 65 72 20 2a 20 |er * Reg|ister * |
|00000f00| 52 65 67 69 73 74 65 72 | 20 2d 3e 20 75 6e 69 74 |Register| -> unit|
|00000f10| 0d 20 20 20 20 76 61 6c | 20 6d 66 68 69 20 3a 20 |. val| mfhi : |
|00000f20| 52 65 67 69 73 74 65 72 | 20 2d 3e 20 75 6e 69 74 |Register| -> unit|
|00000f30| 09 09 28 2a 20 68 69 67 | 68 20 77 6f 72 64 20 6f |..(* hig|h word o|
|00000f40| 66 20 36 34 2d 62 69 74 | 20 6d 75 6c 74 69 70 6c |f 64-bit| multipl|
|00000f50| 79 20 2a 29 0d 20 20 20 | 20 0d 20 20 20 20 28 2a |y *). | . (*|
|00000f60| 20 46 6c 6f 61 74 69 6e | 67 20 70 6f 69 6e 74 20 | Floatin|g point |
|00000f70| 61 72 69 74 68 6d 65 74 | 69 63 20 2a 29 0d 0d 20 |arithmet|ic *).. |
|00000f80| 20 20 20 76 61 6c 20 6e | 65 67 5f 64 6f 75 62 6c | val n|eg_doubl|
|00000f90| 65 20 3a 20 52 65 67 69 | 73 74 65 72 20 2a 20 52 |e : Regi|ster * R|
|00000fa0| 65 67 69 73 74 65 72 20 | 2d 3e 20 75 6e 69 74 0d |egister |-> unit.|
|00000fb0| 20 20 20 20 76 61 6c 20 | 6d 75 6c 5f 64 6f 75 62 | val |mul_doub|
|00000fc0| 6c 65 20 3a 20 52 65 67 | 69 73 74 65 72 20 2a 20 |le : Reg|ister * |
|00000fd0| 52 65 67 69 73 74 65 72 | 20 2a 20 52 65 67 69 73 |Register| * Regis|
|00000fe0| 74 65 72 20 2d 3e 20 75 | 6e 69 74 0d 20 20 20 20 |ter -> u|nit. |
|00000ff0| 76 61 6c 20 64 69 76 5f | 64 6f 75 62 6c 65 20 3a |val div_|double :|
|00001000| 20 52 65 67 69 73 74 65 | 72 20 2a 20 52 65 67 69 | Registe|r * Regi|
|00001010| 73 74 65 72 20 2a 20 52 | 65 67 69 73 74 65 72 20 |ster * R|egister |
|00001020| 2d 3e 20 75 6e 69 74 0d | 20 20 20 20 76 61 6c 20 |-> unit.| val |
|00001030| 61 64 64 5f 64 6f 75 62 | 6c 65 20 3a 20 52 65 67 |add_doub|le : Reg|
|00001040| 69 73 74 65 72 20 2a 20 | 52 65 67 69 73 74 65 72 |ister * |Register|
|00001050| 20 2a 20 52 65 67 69 73 | 74 65 72 20 2d 3e 20 75 | * Regis|ter -> u|
|00001060| 6e 69 74 0d 20 20 20 20 | 76 61 6c 20 73 75 62 5f |nit. |val sub_|
|00001070| 64 6f 75 62 6c 65 20 3a | 20 52 65 67 69 73 74 65 |double :| Registe|
|00001080| 72 20 2a 20 52 65 67 69 | 73 74 65 72 20 2a 20 52 |r * Regi|ster * R|
|00001090| 65 67 69 73 74 65 72 20 | 2d 3e 20 75 6e 69 74 0d |egister |-> unit.|
|000010a0| 0d 20 20 20 20 28 2a 20 | 4d 6f 76 65 20 70 73 65 |. (* |Move pse|
|000010b0| 75 64 6f 2d 69 6e 73 74 | 72 75 63 74 69 6f 6e 20 |udo-inst|ruction |
|000010c0| 3a 20 20 6d 6f 76 65 28 | 73 72 63 2c 64 65 73 74 |: move(|src,dest|
|000010d0| 29 20 2a 29 0d 0d 20 20 | 20 20 76 61 6c 20 6d 6f |) *).. | val mo|
|000010e0| 76 65 20 3a 20 45 41 20 | 2a 20 52 65 67 69 73 74 |ve : EA |* Regist|
|000010f0| 65 72 20 2d 3e 20 75 6e | 69 74 0d 0d 20 20 20 20 |er -> un|it.. |
|00001100| 28 2a 20 4c 6f 61 64 20 | 61 6e 64 20 73 74 6f 72 |(* Load |and stor|
|00001110| 65 20 69 6e 73 74 72 75 | 63 74 69 6f 6e 73 20 2a |e instru|ctions *|
|00001120| 29 0d 20 20 20 20 20 20 | 20 20 20 20 20 20 28 2a |). | (*|
|00001130| 20 61 72 67 75 6d 65 6e | 74 73 20 61 72 65 20 28 | argumen|ts are (|
|00001140| 64 65 73 74 69 6e 61 74 | 69 6f 6e 2c 20 73 6f 75 |destinat|ion, sou|
|00001150| 72 63 65 20 61 64 64 72 | 65 73 73 2c 20 6f 66 66 |rce addr|ess, off|
|00001160| 73 65 74 29 20 2a 29 0d | 20 0d 20 20 20 20 76 61 |set) *).| . va|
|00001170| 6c 20 6c 62 75 20 20 3a | 20 52 65 67 69 73 74 65 |l lbu :| Registe|
|00001180| 72 20 2a 20 45 41 20 2a | 20 69 6e 74 20 2d 3e 20 |r * EA *| int -> |
|00001190| 75 6e 69 74 20 28 2a 20 | 62 79 74 65 73 20 2a 29 |unit (* |bytes *)|
|000011a0| 0d 20 20 20 20 76 61 6c | 20 73 62 20 20 3a 20 52 |. val| sb : R|
|000011b0| 65 67 69 73 74 65 72 20 | 2a 20 45 41 20 2a 20 69 |egister |* EA * i|
|000011c0| 6e 74 20 2d 3e 20 75 6e | 69 74 0d 20 20 20 20 76 |nt -> un|it. v|
|000011d0| 61 6c 20 6c 77 20 20 3a | 20 52 65 67 69 73 74 65 |al lw :| Registe|
|000011e0| 72 20 2a 20 45 41 20 2a | 20 69 6e 74 20 2d 3e 20 |r * EA *| int -> |
|000011f0| 75 6e 69 74 20 20 28 2a | 20 77 6f 72 64 73 20 2a |unit (*| words *|
|00001200| 29 0d 20 20 20 20 76 61 | 6c 20 73 77 20 20 3a 20 |). va|l sw : |
|00001210| 52 65 67 69 73 74 65 72 | 20 2a 20 45 41 20 2a 20 |Register| * EA * |
|00001220| 69 6e 74 20 2d 3e 20 75 | 6e 69 74 0d 20 20 20 20 |int -> u|nit. |
|00001230| 76 61 6c 20 6c 77 63 31 | 3a 20 52 65 67 69 73 74 |val lwc1|: Regist|
|00001240| 65 72 20 2a 20 45 41 20 | 2a 20 69 6e 74 20 2d 3e |er * EA |* int ->|
|00001250| 20 75 6e 69 74 20 20 28 | 2a 20 66 6c 6f 61 74 69 | unit (|* floati|
|00001260| 6e 67 20 70 6f 69 6e 74 | 20 63 6f 70 72 6f 63 65 |ng point| coproce|
|00001270| 73 73 6f 72 20 2a 29 0d | 20 20 20 20 76 61 6c 20 |ssor *).| val |
|00001280| 73 77 63 31 3a 20 52 65 | 67 69 73 74 65 72 20 2a |swc1: Re|gister *|
|00001290| 20 45 41 20 2a 20 69 6e | 74 20 2d 3e 20 75 6e 69 | EA * in|t -> uni|
|000012a0| 74 0d 20 20 20 20 76 61 | 6c 20 6c 75 69 20 3a 20 |t. va|l lui : |
|000012b0| 52 65 67 69 73 74 65 72 | 20 2a 20 69 6e 74 20 2d |Register| * int -|
|000012c0| 3e 20 75 6e 69 74 0d 0d | 20 20 20 20 28 2a 20 53 |> unit..| (* S|
|000012d0| 68 69 66 74 20 69 6e 73 | 74 72 75 63 74 69 6f 6e |hift ins|truction|
|000012e0| 73 20 2a 29 0d 20 20 20 | 20 20 20 20 20 20 20 20 |s *). | |
|000012f0| 20 28 2a 20 61 72 67 75 | 6d 65 6e 74 73 20 61 72 | (* argu|ments ar|
|00001300| 65 20 28 73 68 61 6d 74 | 2c 20 6f 70 65 72 61 6e |e (shamt|, operan|
|00001310| 64 2c 20 72 65 73 75 6c | 74 29 20 2a 29 0d 20 20 |d, resul|t) *). |
|00001320| 20 20 20 20 20 20 20 20 | 20 20 28 2a 20 73 68 61 | | (* sha|
|00001330| 6d 74 20 61 73 20 49 6d | 6d 65 64 6c 61 62 20 5f |mt as Im|medlab _|
|00001340| 20 69 73 20 73 65 6e 73 | 65 6c 65 73 73 20 2a 29 | is sens|eless *)|
|00001350| 0d 0d 20 20 20 20 76 61 | 6c 20 73 6c 6c 20 3a 20 |.. va|l sll : |
|00001360| 45 41 20 2a 20 52 65 67 | 69 73 74 65 72 20 2a 20 |EA * Reg|ister * |
|00001370| 52 65 67 69 73 74 65 72 | 20 2d 3e 20 75 6e 69 74 |Register| -> unit|
|00001380| 0d 20 20 20 20 76 61 6c | 20 73 72 61 20 3a 20 45 |. val| sra : E|
|00001390| 41 20 2a 20 52 65 67 69 | 73 74 65 72 20 2a 20 52 |A * Regi|ster * R|
|000013a0| 65 67 69 73 74 65 72 20 | 2d 3e 20 75 6e 69 74 0d |egister |-> unit.|
|000013b0| 20 20 20 20 0d 0d 20 20 | 20 20 28 2a 20 4d 69 73 | .. | (* Mis|
|000013c0| 63 65 6c 6c 61 6e 79 20 | 2a 29 0d 0d 20 20 20 20 |cellany |*).. |
|000013d0| 76 61 6c 20 61 6c 69 67 | 6e 20 3a 20 75 6e 69 74 |val alig|n : unit|
|000013e0| 20 2d 3e 20 75 6e 69 74 | 20 20 20 20 20 20 20 20 | -> unit| |
|000013f0| 20 20 20 20 28 2a 20 63 | 61 75 73 65 20 6e 65 78 | (* c|ause nex|
|00001400| 74 20 64 61 74 61 20 74 | 6f 20 62 65 20 65 6d 69 |t data t|o be emi|
|00001410| 74 74 65 64 20 6f 6e 0d | 20 20 20 20 20 20 20 20 |tted on.| |
|00001420| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001430| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001440| 20 20 20 61 20 34 2d 62 | 79 74 65 20 62 6f 75 6e | a 4-b|yte boun|
|00001450| 64 61 72 79 20 2a 29 0d | 20 20 20 20 76 61 6c 20 |dary *).| val |
|00001460| 6d 61 72 6b 20 3a 20 75 | 6e 69 74 20 2d 3e 20 75 |mark : u|nit -> u|
|00001470| 6e 69 74 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |nit | |
|00001480| 28 2a 20 65 6d 69 74 20 | 61 20 62 61 63 6b 20 70 |(* emit |a back p|
|00001490| 6f 69 6e 74 65 72 2c 20 | 0d 20 20 20 20 20 20 20 |ointer, |. |
|000014a0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000014b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000014c0| 20 20 20 20 61 6c 73 6f | 20 63 61 6c 6c 65 64 20 | also| called |
|000014d0| 6d 61 72 6b 20 2a 29 0d | 0d 20 20 20 20 76 61 6c |mark *).|. val|
|000014e0| 20 63 6f 6d 6d 65 6e 74 | 20 3a 20 73 74 72 69 6e | comment| : strin|
|000014f0| 67 20 2d 3e 20 75 6e 69 | 74 0d 0d 20 20 65 6e 64 |g -> uni|t.. end|
|00001500| 20 28 2a 20 73 69 67 6e | 61 74 75 72 65 20 6f 66 | (* sign|ature of|
|00001510| 20 73 74 72 75 63 74 75 | 72 65 20 4d 20 2a 29 0d | structu|re M *).|
|00001520| 0d 20 20 76 61 6c 20 63 | 6f 64 65 67 65 6e 20 3a |. val c|odegen :|
|00001530| 20 75 6e 69 74 2d 3e 75 | 6e 69 74 0d 0d 20 20 76 | unit->u|nit.. v|
|00001540| 61 6c 20 63 6f 64 65 73 | 74 61 74 73 20 3a 20 6f |al codes|tats : o|
|00001550| 75 74 73 74 72 65 61 6d | 20 2d 3e 20 75 6e 69 74 |utstream| -> unit|
|00001560| 09 28 2a 20 77 72 69 74 | 65 20 73 74 61 74 69 73 |.(* writ|e statis|
|00001570| 74 69 63 73 20 6f 6e 20 | 73 74 72 65 61 6d 20 2a |tics on |stream *|
|00001580| 29 0d 0d 65 6e 64 20 28 | 2a 20 73 69 67 6e 61 74 |)..end (|* signat|
|00001590| 75 72 65 20 4d 49 50 53 | 43 4f 44 45 52 20 2a 29 |ure MIPS|CODER *)|
|000015a0| 0d 40 20 54 68 65 20 62 | 61 73 69 63 20 73 74 72 |.@ The b|asic str|
|000015b0| 61 74 65 67 79 20 6f 66 | 20 74 68 65 20 69 6d 70 |ategy of| the imp|
|000015c0| 6c 65 6d 65 6e 74 61 74 | 69 6f 6e 20 69 73 20 74 |lementat|ion is t|
|000015d0| 6f 20 68 6f 6c 64 20 6f | 6e 2c 20 76 69 61 20 74 |o hold o|n, via t|
|000015e0| 68 65 20 5b 5b 6b 65 70 | 74 5d 5d 0d 70 6f 69 6e |he [[kep|t]].poin|
|000015f0| 74 65 72 2c 20 74 6f 20 | 74 68 65 20 6c 69 73 74 |ter, to |the list|
|00001600| 20 6f 66 20 69 6e 73 74 | 72 75 63 74 69 6f 6e 73 | of inst|ructions|
|00001610| 20 67 65 6e 65 72 61 74 | 65 64 20 73 6f 20 66 61 | generat|ed so fa|
|00001620| 72 2e 0d 57 65 20 75 73 | 65 20 5b 5b 69 6e 73 74 |r..We us|e [[inst|
|00001630| 72 5d 5d 20 66 6f 72 20 | 74 68 65 20 74 79 70 65 |r]] for |the type|
|00001640| 20 6f 66 20 61 6e 20 69 | 6e 73 74 72 75 63 74 69 | of an i|nstructi|
|00001650| 6f 6e 2c 20 73 6f 0d 5b | 5b 6b 65 70 74 5d 5d 20 |on, so.[|[kept]] |
|00001660| 68 61 73 20 74 79 70 65 | 20 5b 5b 69 6e 73 74 72 |has type| [[instr|
|00001670| 20 6c 69 73 74 20 72 65 | 66 5d 5d 2e 0d 0d 54 68 | list re|f]]...Th|
|00001680| 65 20 69 6e 73 74 72 75 | 63 74 69 6f 6e 73 20 77 |e instru|ctions w|
|00001690| 69 6c 6c 20 62 65 20 65 | 78 65 63 75 74 65 64 20 |ill be e|xecuted |
|000016a0| 69 6e 20 74 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |in the f|ollowing|
|000016b0| 20 6f 72 64 65 72 3a 20 | 74 68 65 20 0d 69 6e 73 | order: |the .ins|
|000016c0| 74 72 75 63 74 69 6f 6e | 20 61 74 20 74 68 65 20 |truction| at the |
|000016d0| 68 65 61 64 20 6f 66 20 | 74 68 65 20 5b 5b 21 6b |head of |the [[!k|
|000016e0| 65 70 74 5d 5d 20 69 73 | 20 65 78 65 63 75 74 65 |ept]] is| execute|
|000016f0| 64 20 6c 61 73 74 2e 0d | 54 68 69 73 20 65 6e 61 |d last..|This ena|
|00001700| 62 6c 65 73 20 75 73 20 | 74 6f 20 61 63 63 65 70 |bles us |to accep|
|00001710| 74 20 63 61 6c 6c 73 20 | 69 6e 20 74 68 65 20 6f |t calls |in the o|
|00001720| 72 64 65 72 20 6f 66 20 | 65 78 65 63 75 74 69 6f |rder of |executio|
|00001730| 6e 20 62 75 74 0d 61 64 | 64 20 74 68 65 20 6e 65 |n but.ad|d the ne|
|00001740| 77 20 69 6e 73 74 72 75 | 63 74 69 6f 6e 28 73 29 |w instru|ction(s)|
|00001750| 20 74 6f 20 74 68 65 20 | 6c 69 73 74 20 69 6e 20 | to the |list in |
|00001760| 63 6f 6e 73 74 61 6e 74 | 20 74 69 6d 65 2e 0d 0d |constant| time...|
|00001770| 0d 40 0d 57 65 20 73 74 | 72 75 63 74 75 72 65 20 |.@.We st|ructure |
|00001780| 74 68 65 20 69 6e 73 74 | 72 75 63 74 69 6f 6e 20 |the inst|ruction |
|00001790| 73 74 72 65 61 6d 20 61 | 20 6c 69 74 74 6c 65 20 |stream a| little |
|000017a0| 62 69 74 20 62 79 20 66 | 61 63 74 6f 72 69 6e 67 |bit by f|actoring|
|000017b0| 0d 6f 75 74 20 74 68 65 | 20 64 69 66 66 65 72 65 |.out the| differe|
|000017c0| 6e 74 20 6c 6f 61 64 20 | 61 6e 64 20 73 74 6f 72 |nt load |and stor|
|000017d0| 65 20 69 6e 73 74 72 75 | 63 74 69 6f 6e 73 20 74 |e instru|ctions t|
|000017e0| 68 61 74 20 63 61 6e 0d | 6f 63 63 75 72 3a 20 77 |hat can.|occur: w|
|000017f0| 65 20 68 61 76 65 20 6c | 6f 61 64 20 62 79 74 65 |e have l|oad byte|
|00001800| 2c 20 6c 6f 61 64 20 77 | 6f 72 64 2c 20 61 6e 64 |, load w|ord, and|
|00001810| 20 6c 6f 61 64 20 74 6f | 20 63 6f 70 72 6f 63 65 | load to| coproce|
|00001820| 73 73 6f 72 20 28 66 6c | 6f 61 74 69 6e 67 20 70 |ssor (fl|oating p|
|00001830| 6f 69 6e 74 29 2e 0d 3c | 3c 74 79 70 65 73 20 61 |oint)..<|<types a|
|00001840| 75 78 69 6c 69 61 72 79 | 20 74 6f 20 5b 5b 69 6e |uxiliary| to [[in|
|00001850| 73 74 72 5d 5d 3e 3e 3d | 0d 64 61 74 61 74 79 70 |str]]>>=|.datatyp|
|00001860| 65 20 73 69 7a 65 20 3d | 20 42 79 74 65 20 7c 20 |e size =| Byte | |
|00001870| 57 6f 72 64 20 7c 20 46 | 6c 6f 61 74 69 6e 67 0d |Word | F|loating.|
|00001880| 40 0d 48 65 72 65 20 61 | 72 65 20 74 68 65 20 69 |@.Here a|re the i|
|00001890| 6e 73 74 72 75 63 74 69 | 6f 6e 73 20 74 68 61 74 |nstructi|ons that|
|000018a0| 20 65 78 69 73 74 2e 0d | 57 65 20 6c 69 73 74 20 | exist..|We list |
|000018b0| 74 68 65 6d 20 69 6e 20 | 6d 6f 72 65 20 6f 72 20 |them in |more or |
|000018c0| 6c 65 73 73 20 74 68 65 | 20 6f 72 64 65 72 20 6f |less the| order o|
|000018d0| 66 20 74 68 65 20 4d 49 | 50 53 43 4f 44 45 52 20 |f the MI|PSCODER |
|000018e0| 73 69 67 6e 61 74 75 72 | 65 2e 0d 3c 3c 64 65 66 |signatur|e..<<def|
|000018f0| 69 6e 69 74 69 6f 6e 20 | 6f 66 20 5b 5b 69 6e 73 |inition |of [[ins|
|00001900| 74 72 5d 5d 3e 3e 3d 0d | 3c 3c 74 79 70 65 73 20 |tr]]>>=.|<<types |
|00001910| 61 75 78 69 6c 69 61 72 | 79 20 74 6f 20 5b 5b 69 |auxiliar|y to [[i|
|00001920| 6e 73 74 72 5d 5d 3e 3e | 0d 0d 64 61 74 61 74 79 |nstr]]>>|..dataty|
|00001930| 70 65 20 69 6e 73 74 72 | 20 3d 20 0d 20 20 20 20 |pe instr| = . |
|00001940| 53 54 52 49 4e 47 43 4f | 4e 53 54 20 6f 66 20 73 |STRINGCO|NST of s|
|00001950| 74 72 69 6e 67 20 20 20 | 20 20 20 20 20 20 20 20 |tring | |
|00001960| 20 20 20 20 28 2a 20 63 | 6f 6e 73 74 61 6e 74 73 | (* c|onstants|
|00001970| 20 2a 29 0d 20 20 7c 20 | 45 4d 49 54 4c 4f 4e 47 | *). | |EMITLONG|
|00001980| 20 6f 66 20 69 6e 74 0d | 0d 20 20 7c 20 44 45 46 | of int.|. | DEF|
|00001990| 49 4e 45 20 6f 66 20 4c | 61 62 65 6c 20 20 20 20 |INE of L|abel |
|000019a0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000019b0| 20 28 2a 20 6c 61 62 65 | 6c 73 20 2a 29 0d 20 20 | (* labe|ls *). |
|000019c0| 7c 20 45 4d 49 54 4c 41 | 42 20 6f 66 20 69 6e 74 || EMITLA|B of int|
|000019d0| 20 2a 20 4c 61 62 65 6c | 0d 0d 20 20 7c 20 53 4c | * Label|.. | SL|
|000019e0| 54 20 6f 66 20 52 65 67 | 69 73 74 65 72 20 2a 20 |T of Reg|ister * |
|000019f0| 45 41 20 2a 20 52 65 67 | 69 73 74 65 72 20 20 20 |EA * Reg|ister |
|00001a00| 20 20 28 2a 20 63 6f 6e | 74 72 6f 6c 20 66 6c 6f | (* con|trol flo|
|00001a10| 77 20 2a 29 0d 20 20 7c | 20 42 45 51 20 6f 66 20 |w *). || BEQ of |
|00001a20| 62 6f 6f 6c 20 2a 20 52 | 65 67 69 73 74 65 72 20 |bool * R|egister |
|00001a30| 2a 20 52 65 67 69 73 74 | 65 72 20 2a 20 4c 61 62 |* Regist|er * Lab|
|00001a40| 65 6c 0d 20 20 7c 20 4a | 55 4d 50 20 6f 66 20 52 |el. | J|UMP of R|
|00001a50| 65 67 69 73 74 65 72 20 | 0d 20 20 7c 20 53 4c 54 |egister |. | SLT|
|00001a60| 5f 44 20 6f 66 20 52 65 | 67 69 73 74 65 72 20 2a |_D of Re|gister *|
|00001a70| 20 52 65 67 69 73 74 65 | 72 0d 20 20 7c 20 53 45 | Registe|r. | SE|
|00001a80| 51 5f 44 20 6f 66 20 52 | 65 67 69 73 74 65 72 20 |Q_D of R|egister |
|00001a90| 2a 20 52 65 67 69 73 74 | 65 72 0d 20 20 7c 20 42 |* Regist|er. | B|
|00001aa0| 43 4f 50 31 20 6f 66 20 | 62 6f 6f 6c 20 2a 20 4c |COP1 of |bool * L|
|00001ab0| 61 62 65 6c 0d 0d 20 20 | 7c 20 4e 4f 50 20 28 2a |abel.. || NOP (*|
|00001ac0| 20 6e 6f 2d 6f 70 20 66 | 6f 72 20 64 65 6c 61 79 | no-op f|or delay|
|00001ad0| 20 73 6c 6f 74 20 2a 29 | 0d 0d 20 20 7c 20 41 44 | slot *)|.. | AD|
|00001ae0| 44 20 6f 66 20 52 65 67 | 69 73 74 65 72 20 2a 20 |D of Reg|ister * |
|00001af0| 45 41 20 2a 20 52 65 67 | 69 73 74 65 72 20 20 20 |EA * Reg|ister |
|00001b00| 20 20 28 2a 20 61 72 69 | 74 68 6d 65 74 69 63 20 | (* ari|thmetic |
|00001b10| 2a 29 0d 20 20 7c 20 41 | 4e 44 20 6f 66 20 52 65 |*). | A|ND of Re|
|00001b20| 67 69 73 74 65 72 20 2a | 20 45 41 20 2a 20 52 65 |gister *| EA * Re|
|00001b30| 67 69 73 74 65 72 0d 20 | 20 7c 20 4f 52 20 20 6f |gister. | | OR o|
|00001b40| 66 20 52 65 67 69 73 74 | 65 72 20 2a 20 45 41 20 |f Regist|er * EA |
|00001b50| 2a 20 52 65 67 69 73 74 | 65 72 0d 20 20 7c 20 58 |* Regist|er. | X|
|00001b60| 4f 52 20 6f 66 20 52 65 | 67 69 73 74 65 72 20 2a |OR of Re|gister *|
|00001b70| 20 45 41 20 2a 20 52 65 | 67 69 73 74 65 72 0d 20 | EA * Re|gister. |
|00001b80| 20 7c 20 53 55 42 20 6f | 66 20 52 65 67 69 73 74 | | SUB o|f Regist|
|00001b90| 65 72 20 2a 20 52 65 67 | 69 73 74 65 72 20 2a 20 |er * Reg|ister * |
|00001ba0| 52 65 67 69 73 74 65 72 | 0d 20 20 7c 20 4d 55 4c |Register|. | MUL|
|00001bb0| 54 20 6f 66 20 52 65 67 | 69 73 74 65 72 20 2a 20 |T of Reg|ister * |
|00001bc0| 52 65 67 69 73 74 65 72 | 0d 20 20 7c 20 44 49 56 |Register|. | DIV|
|00001bd0| 20 6f 66 20 52 65 67 69 | 73 74 65 72 20 2a 20 52 | of Regi|ster * R|
|00001be0| 65 67 69 73 74 65 72 0d | 20 20 7c 20 4d 46 4c 4f |egister.| | MFLO|
|00001bf0| 20 6f 66 20 52 65 67 69 | 73 74 65 72 20 20 20 20 | of Regi|ster |
|00001c00| 28 2a 20 6d 66 6c 6f 20 | 69 6e 73 74 72 75 63 74 |(* mflo |instruct|
|00001c10| 69 6f 6e 20 75 73 65 64 | 20 77 69 74 68 0d 20 20 |ion used| with. |
|00001c20| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001c30| 20 20 20 20 20 20 20 20 | 20 36 34 2d 62 69 74 20 | | 64-bit |
|00001c40| 6d 75 6c 74 69 70 6c 79 | 20 61 6e 64 20 64 69 76 |multiply| and div|
|00001c50| 69 64 65 20 2a 29 0d 20 | 20 7c 20 4d 46 48 49 20 |ide *). | | MFHI |
|00001c60| 6f 66 20 52 65 67 69 73 | 74 65 72 0d 0d 20 20 7c |of Regis|ter.. ||
|00001c70| 20 4e 45 47 5f 44 20 6f | 66 20 52 65 67 69 73 74 | NEG_D o|f Regist|
|00001c80| 65 72 20 2a 20 52 65 67 | 69 73 74 65 72 0d 20 20 |er * Reg|ister. |
|00001c90| 7c 20 4d 55 4c 5f 44 20 | 6f 66 20 52 65 67 69 73 || MUL_D |of Regis|
|00001ca0| 74 65 72 20 2a 20 52 65 | 67 69 73 74 65 72 20 2a |ter * Re|gister *|
|00001cb0| 20 52 65 67 69 73 74 65 | 72 0d 20 20 7c 20 44 49 | Registe|r. | DI|
|00001cc0| 56 5f 44 20 6f 66 20 52 | 65 67 69 73 74 65 72 20 |V_D of R|egister |
|00001cd0| 2a 20 52 65 67 69 73 74 | 65 72 20 2a 20 52 65 67 |* Regist|er * Reg|
|00001ce0| 69 73 74 65 72 0d 20 20 | 7c 20 41 44 44 5f 44 20 |ister. || ADD_D |
|00001cf0| 6f 66 20 52 65 67 69 73 | 74 65 72 20 2a 20 52 65 |of Regis|ter * Re|
|00001d00| 67 69 73 74 65 72 20 2a | 20 52 65 67 69 73 74 65 |gister *| Registe|
|00001d10| 72 0d 20 20 7c 20 53 55 | 42 5f 44 20 6f 66 20 52 |r. | SU|B_D of R|
|00001d20| 65 67 69 73 74 65 72 20 | 2a 20 52 65 67 69 73 74 |egister |* Regist|
|00001d30| 65 72 20 2a 20 52 65 67 | 69 73 74 65 72 0d 0d 20 |er * Reg|ister.. |
|00001d40| 20 7c 20 4d 4f 56 45 20 | 6f 66 20 45 41 20 2a 20 | | MOVE |of EA * |
|00001d50| 52 65 67 69 73 74 65 72 | 20 20 20 20 28 2a 20 70 |Register| (* p|
|00001d60| 75 74 20 73 6f 6d 65 74 | 68 69 6e 67 20 69 6e 74 |ut somet|hing int|
|00001d70| 6f 20 61 20 72 65 67 69 | 73 74 65 72 20 2a 29 0d |o a regi|ster *).|
|00001d80| 20 20 7c 20 4c 44 49 5f | 33 32 20 6f 66 20 69 6e | | LDI_|32 of in|
|00001d90| 74 20 2a 20 52 65 67 69 | 73 74 65 72 20 28 2a 20 |t * Regi|ster (* |
|00001da0| 6c 6f 61 64 20 69 6e 20 | 61 20 62 69 67 20 69 6d |load in |a big im|
|00001db0| 6d 65 64 69 61 74 65 20 | 63 6f 6e 73 74 61 6e 74 |mediate |constant|
|00001dc0| 20 28 3e 31 36 20 62 69 | 74 73 29 20 2a 29 0d 20 | (>16 bi|ts) *). |
|00001dd0| 20 7c 20 4c 55 49 20 6f | 66 20 52 65 67 69 73 74 | | LUI o|f Regist|
|00001de0| 65 72 20 2a 20 69 6e 74 | 20 20 20 20 28 2a 20 4d |er * int| (* M|
|00001df0| 69 70 73 20 6c 75 69 20 | 69 6e 73 74 72 75 63 74 |ips lui |instruct|
|00001e00| 69 6f 6e 20 2a 29 0d 0d | 20 20 7c 20 4c 4f 41 44 |ion *)..| | LOAD|
|00001e10| 20 6f 66 20 73 69 7a 65 | 20 2a 20 52 65 67 69 73 | of size| * Regis|
|00001e20| 74 65 72 20 2a 20 45 41 | 20 2a 20 69 6e 74 20 20 |ter * EA| * int |
|00001e30| 28 2a 20 6c 6f 61 64 20 | 61 6e 64 20 73 74 6f 72 |(* load |and stor|
|00001e40| 65 20 2a 29 0d 20 20 7c | 20 53 54 4f 52 45 20 20 |e *). || STORE |
|00001e50| 6f 66 20 73 69 7a 65 20 | 2a 20 52 65 67 69 73 74 |of size |* Regist|
|00001e60| 65 72 20 2a 20 45 41 20 | 2a 20 69 6e 74 0d 0d 20 |er * EA |* int.. |
|00001e70| 20 7c 20 53 4c 4c 20 6f | 66 20 45 41 20 2a 20 52 | | SLL o|f EA * R|
|00001e80| 65 67 69 73 74 65 72 20 | 2a 20 52 65 67 69 73 74 |egister |* Regist|
|00001e90| 65 72 20 20 20 20 20 28 | 2a 20 73 68 69 66 74 20 |er (|* shift |
|00001ea0| 2a 29 0d 20 20 7c 20 53 | 52 41 20 6f 66 20 45 41 |*). | S|RA of EA|
|00001eb0| 20 2a 20 52 65 67 69 73 | 74 65 72 20 2a 20 52 65 | * Regis|ter * Re|
|00001ec0| 67 69 73 74 65 72 0d 0d | 20 20 7c 20 43 4f 4d 4d |gister..| | COMM|
|00001ed0| 45 4e 54 20 6f 66 20 73 | 74 72 69 6e 67 20 20 20 |ENT of s|tring |
|00001ee0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001ef0| 28 2a 20 67 65 6e 65 72 | 61 74 65 73 20 6e 6f 74 |(* gener|ates not|
|00001f00| 68 69 6e 67 20 2a 29 0d | 20 20 7c 20 4d 41 52 4b |hing *).| | MARK|
|00001f10| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001f20| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001f30| 28 2a 20 61 20 62 61 63 | 6b 70 6f 69 6e 74 65 72 |(* a bac|kpointer|
|00001f40| 20 2a 29 0d 0d 20 20 7c | 20 42 52 45 41 4b 20 6f | *).. || BREAK o|
|00001f50| 66 20 69 6e 74 09 09 09 | 28 2a 20 62 72 65 61 6b |f int...|(* break|
|00001f60| 20 69 6e 73 74 72 75 63 | 74 69 6f 6e 20 2a 29 0d | instruc|tion *).|
|00001f70| 40 0d 48 65 72 65 20 69 | 73 20 74 68 65 20 63 6f |@.Here i|s the co|
|00001f80| 64 65 20 74 68 61 74 20 | 68 61 6e 64 6c 65 73 20 |de that |handles |
|00001f90| 74 68 65 20 67 65 6e 65 | 72 61 74 65 64 20 73 74 |the gene|rated st|
|00001fa0| 72 65 61 6d 2c 20 5b 5b | 6b 65 70 74 5d 5d 2e 0d |ream, [[|kept]]..|
|00001fb0| 49 74 20 62 65 67 69 6e | 73 20 6c 69 66 65 20 61 |It begin|s life a|
|00001fc0| 73 20 5b 5b 6e 69 6c 5d | 5d 20 61 6e 64 20 72 65 |s [[nil]|] and re|
|00001fd0| 74 75 72 6e 73 20 74 6f | 20 5b 5b 6e 69 6c 5d 5d |turns to| [[nil]]|
|00001fe0| 20 65 76 65 72 79 20 74 | 69 6d 65 20 63 6f 64 65 | every t|ime code|
|00001ff0| 20 69 73 0d 67 65 6e 65 | 72 61 74 65 64 2e 0d 54 | is.gene|rated..T|
|00002000| 68 65 20 66 75 6e 63 74 | 69 6f 6e 20 5b 5b 6b 65 |he funct|ion [[ke|
|00002010| 65 70 5d 5d 20 69 73 20 | 61 20 63 6f 6e 76 65 6e |ep]] is |a conven|
|00002020| 69 65 6e 74 20 77 61 79 | 20 6f 66 20 61 64 64 69 |ient way| of addi|
|00002030| 6e 67 20 61 20 73 69 6e | 67 6c 65 20 5b 5b 69 6e |ng a sin|gle [[in|
|00002040| 73 74 72 5d 5d 20 74 6f | 0d 74 68 65 20 6c 69 73 |str]] to|.the lis|
|00002050| 74 3b 20 69 74 27 73 20 | 76 65 72 79 20 74 65 72 |t; it's |very ter|
|00002060| 73 65 2e 0d 53 6f 6d 65 | 74 69 6d 65 73 20 77 65 |se..Some|times we|
|00002070| 20 68 61 76 65 20 74 6f | 20 61 64 64 20 6d 75 6c | have to| add mul|
|00002080| 74 69 70 6c 65 20 5b 5b | 69 6e 73 74 72 5d 5d 73 |tiple [[|instr]]s|
|00002090| 3b 20 74 68 65 6e 20 77 | 65 20 75 73 65 20 5b 5b |; then w|e use [[|
|000020a0| 6b 65 65 70 6c 69 73 74 | 5d 5d 2e 0d 57 65 20 61 |keeplist|]]..We a|
|000020b0| 6c 73 6f 20 64 65 66 69 | 6e 65 20 61 20 66 75 6e |lso defi|ne a fun|
|000020c0| 63 74 69 6f 6e 20 5b 5b | 64 65 6c 61 79 5d 5d 20 |ction [[|delay]] |
|000020d0| 74 68 61 74 20 69 73 20 | 6a 75 73 74 20 6c 69 6b |that is |just lik|
|000020e0| 65 20 61 20 5b 5b 6b 65 | 65 70 5d 5d 20 62 75 74 |e a [[ke|ep]] but|
|000020f0| 0d 69 74 20 61 64 64 73 | 20 61 20 4e 4f 50 20 69 |.it adds| a NOP i|
|00002100| 6e 20 74 68 65 20 64 65 | 6c 61 79 20 73 6c 6f 74 |n the de|lay slot|
|00002110| 2e 0d 3c 3c 69 6e 73 74 | 72 75 63 74 69 6f 6e 20 |..<<inst|ruction |
|00002120| 73 74 72 65 61 6d 20 61 | 6e 64 20 69 74 73 20 66 |stream a|nd its f|
|00002130| 75 6e 63 74 69 6f 6e 73 | 3e 3e 3d 0d 20 20 76 61 |unctions|>>=. va|
|00002140| 6c 20 6b 65 70 74 20 3d | 20 72 65 66 20 6e 69 6c |l kept =| ref nil|
|00002150| 20 3a 20 69 6e 73 74 72 | 20 6c 69 73 74 20 72 65 | : instr| list re|
|00002160| 66 0d 20 20 66 75 6e 20 | 6b 65 65 70 20 66 20 61 |f. fun |keep f a|
|00002170| 20 3d 20 6b 65 70 74 20 | 3a 3d 20 66 20 61 20 3a | = kept |:= f a :|
|00002180| 3a 20 21 6b 65 70 74 0d | 20 20 66 75 6e 20 64 65 |: !kept.| fun de|
|00002190| 6c 61 79 20 66 20 61 20 | 3d 20 6b 65 70 74 20 3a |lay f a |= kept :|
|000021a0| 3d 20 4e 4f 50 20 3a 3a | 20 66 20 61 20 3a 3a 20 |= NOP ::| f a :: |
|000021b0| 21 6b 65 70 74 0d 20 20 | 66 75 6e 20 6b 65 65 70 |!kept. |fun keep|
|000021c0| 6c 69 73 74 20 6c 20 3d | 20 6b 65 70 74 20 3a 3d |list l =| kept :=|
|000021d0| 20 6c 20 40 20 21 6b 65 | 70 74 0d 3c 3c 72 65 69 | l @ !ke|pt.<<rei|
|000021e0| 6e 69 74 69 61 6c 69 7a | 65 20 5b 5b 6b 65 70 74 |nitializ|e [[kept|
|000021f0| 5d 5d 3e 3e 3d 0d 20 20 | 6b 65 70 74 20 3a 3d 20 |]]>>=. |kept := |
|00002200| 6e 69 6c 0d 40 0d 5c 73 | 75 62 73 65 63 74 69 6f |nil.@.\s|ubsectio|
|00002210| 6e 7b 45 78 70 6f 72 74 | 69 6e 67 20 66 75 6e 63 |n{Export|ing func|
|00002220| 74 69 6f 6e 73 20 66 6f | 72 20 7b 5c 74 74 20 4d |tions fo|r {\tt M|
|00002230| 49 50 53 43 4f 44 45 52 | 7d 7d 0d 57 65 20 6e 6f |IPSCODER|}}.We no|
|00002240| 77 20 6b 6e 6f 77 20 65 | 6e 6f 75 67 68 20 74 6f |w know e|nough to|
|00002250| 20 69 6d 70 6c 65 6d 65 | 6e 74 20 6d 6f 73 74 20 | impleme|nt most |
|00002260| 6f 66 20 74 68 65 20 66 | 75 6e 63 74 69 6f 6e 73 |of the f|unctions|
|00002270| 20 63 61 6c 6c 65 64 20 | 66 6f 72 20 69 6e 0d 5b | called |for in.[|
|00002280| 5b 4d 49 50 53 43 4f 44 | 45 52 5d 5d 2e 0d 57 65 |[MIPSCOD|ER]]..We|
|00002290| 20 73 74 69 6c 6c 20 68 | 61 76 65 6e 27 74 20 64 | still h|aven't d|
|000022a0| 65 63 69 64 65 64 20 6f | 6e 20 61 6e 20 69 6d 70 |ecided o|n an imp|
|000022b0| 6c 65 6d 65 6e 74 61 74 | 69 6f 6e 20 6f 66 20 6c |lementat|ion of l|
|000022c0| 61 62 65 6c 73 2c 0d 61 | 6e 64 20 74 68 65 72 65 |abels,.a|nd there|
|000022d0| 20 69 73 20 6f 6e 65 20 | 73 75 62 74 6c 65 74 79 | is one |subtlety|
|000022e0| 20 69 6e 20 6d 75 6c 74 | 69 70 6c 69 63 61 74 69 | in mult|iplicati|
|000022f0| 6f 6e 20 61 6e 64 20 64 | 69 76 69 73 69 6f 6e 2c |on and d|ivision,|
|00002300| 0d 62 75 74 20 74 68 65 | 20 72 65 73 74 20 69 73 |.but the| rest is|
|00002310| 20 73 65 74 2e 0d 3c 3c | 5b 5b 4d 49 50 53 43 4f | set..<<|[[MIPSCO|
|00002320| 44 45 52 5d 5d 20 66 75 | 6e 63 74 69 6f 6e 73 3e |DER]] fu|nctions>|
|00002330| 3e 3d 0d 20 20 76 61 6c | 20 65 6d 69 74 73 74 72 |>=. val| emitstr|
|00002340| 69 6e 67 20 3d 20 6b 65 | 65 70 20 53 54 52 49 4e |ing = ke|ep STRIN|
|00002350| 47 43 4f 4e 53 54 20 20 | 20 20 20 28 2a 20 6c 69 |GCONST | (* li|
|00002360| 74 65 72 61 6c 73 20 2a | 29 0d 20 20 65 78 63 65 |terals *|). exce|
|00002370| 70 74 69 6f 6e 20 42 61 | 64 52 65 61 6c 20 3d 20 |ption Ba|dReal = |
|00002380| 49 45 45 45 52 65 61 6c | 2e 42 61 64 52 65 61 6c |IEEEReal|.BadReal|
|00002390| 0d 20 20 76 61 6c 20 6c | 6f 77 5f 6f 72 64 65 72 |. val l|ow_order|
|000023a0| 5f 6f 66 66 73 65 74 20 | 3d 20 45 6d 69 74 74 65 |_offset |= Emitte|
|000023b0| 72 2e 6c 6f 77 5f 6f 72 | 64 65 72 5f 6f 66 66 73 |r.low_or|der_offs|
|000023c0| 65 74 0d 20 20 76 61 6c | 20 72 65 61 6c 63 6f 6e |et. val| realcon|
|000023d0| 73 74 20 3d 20 6b 65 65 | 70 20 28 53 54 52 49 4e |st = kee|p (STRIN|
|000023e0| 47 43 4f 4e 53 54 20 6f | 20 6f 72 64 65 72 5f 72 |GCONST o| order_r|
|000023f0| 65 61 6c 20 6f 20 49 45 | 45 45 52 65 61 6c 2e 72 |eal o IE|EEReal.r|
|00002400| 65 61 6c 63 6f 6e 73 74 | 29 0d 20 20 76 61 6c 20 |ealconst|). val |
|00002410| 65 6d 69 74 6c 6f 6e 67 | 20 3d 20 6b 65 65 70 20 |emitlong| = keep |
|00002420| 45 4d 49 54 4c 4f 4e 47 | 0d 0d 20 20 3c 3c 6c 61 |EMITLONG|.. <<la|
|00002430| 62 65 6c 20 66 75 6e 63 | 74 69 6f 6e 73 3e 3e 20 |bel func|tions>> |
|00002440| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002450| 20 20 28 2a 20 6c 61 62 | 65 6c 73 20 2a 29 0d 0d | (* lab|els *)..|
|00002460| 20 20 76 61 6c 20 73 6c | 74 20 3d 20 6b 65 65 70 | val sl|t = keep|
|00002470| 20 53 4c 54 20 20 20 20 | 20 20 20 20 20 20 20 20 | SLT | |
|00002480| 20 20 20 20 20 20 20 20 | 28 2a 20 63 6f 6e 74 72 | |(* contr|
|00002490| 6f 6c 20 66 6c 6f 77 20 | 2a 29 0d 20 20 76 61 6c |ol flow |*). val|
|000024a0| 20 62 65 71 20 3d 20 64 | 65 6c 61 79 20 42 45 51 | beq = d|elay BEQ|
|000024b0| 0d 20 20 76 61 6c 20 6a | 75 6d 70 20 3d 20 64 65 |. val j|ump = de|
|000024c0| 6c 61 79 20 4a 55 4d 50 | 0d 20 20 76 61 6c 20 73 |lay JUMP|. val s|
|000024d0| 6c 74 5f 64 6f 75 62 6c | 65 20 3d 20 64 65 6c 61 |lt_doubl|e = dela|
|000024e0| 79 20 53 4c 54 5f 44 0d | 20 20 76 61 6c 20 73 65 |y SLT_D.| val se|
|000024f0| 71 5f 64 6f 75 62 6c 65 | 20 3d 20 64 65 6c 61 79 |q_double| = delay|
|00002500| 20 53 45 51 5f 44 0d 20 | 20 76 61 6c 20 62 63 6f | SEQ_D. | val bco|
|00002510| 70 31 20 3d 20 64 65 6c | 61 79 20 42 43 4f 50 31 |p1 = del|ay BCOP1|
|00002520| 0d 0d 20 20 76 61 6c 20 | 61 64 64 20 3d 20 6b 65 |.. val |add = ke|
|00002530| 65 70 20 41 44 44 20 20 | 20 20 20 20 20 20 20 20 |ep ADD | |
|00002540| 20 20 20 20 20 20 20 20 | 20 20 28 2a 20 61 72 69 | | (* ari|
|00002550| 74 68 6d 65 74 69 63 20 | 2a 29 0d 20 20 76 61 6c |thmetic |*). val|
|00002560| 20 61 6e 64 27 20 3d 20 | 6b 65 65 70 20 41 4e 44 | and' = |keep AND|
|00002570| 0d 20 20 76 61 6c 20 6f | 72 20 3d 20 6b 65 65 70 |. val o|r = keep|
|00002580| 20 4f 52 0d 20 20 76 61 | 6c 20 78 6f 72 20 3d 20 | OR. va|l xor = |
|00002590| 6b 65 65 70 20 58 4f 52 | 0d 20 20 76 61 6c 20 6f |keep XOR|. val o|
|000025a0| 70 20 73 75 62 20 3d 20 | 6b 65 65 70 20 53 55 42 |p sub = |keep SUB|
|000025b0| 0d 20 20 3c 3c 6d 75 6c | 74 69 70 6c 69 63 61 74 |. <<mul|tiplicat|
|000025c0| 69 6f 6e 20 61 6e 64 20 | 64 69 76 69 73 69 6f 6e |ion and |division|
|000025d0| 20 66 75 6e 63 74 69 6f | 6e 73 3e 3e 0d 0d 20 20 | functio|ns>>.. |
|000025e0| 76 61 6c 20 6e 65 67 5f | 64 6f 75 62 6c 65 20 3d |val neg_|double =|
|000025f0| 20 6b 65 65 70 20 4e 45 | 47 5f 44 0d 20 20 76 61 | keep NE|G_D. va|
|00002600| 6c 20 6d 75 6c 5f 64 6f | 75 62 6c 65 20 3d 20 6b |l mul_do|uble = k|
|00002610| 65 65 70 20 4d 55 4c 5f | 44 0d 20 20 76 61 6c 20 |eep MUL_|D. val |
|00002620| 64 69 76 5f 64 6f 75 62 | 6c 65 20 3d 20 6b 65 65 |div_doub|le = kee|
|00002630| 70 20 44 49 56 5f 44 0d | 20 20 76 61 6c 20 61 64 |p DIV_D.| val ad|
|00002640| 64 5f 64 6f 75 62 6c 65 | 20 3d 20 6b 65 65 70 20 |d_double| = keep |
|00002650| 41 44 44 5f 44 0d 20 20 | 76 61 6c 20 73 75 62 5f |ADD_D. |val sub_|
|00002660| 64 6f 75 62 6c 65 20 3d | 20 6b 65 65 70 20 53 55 |double =| keep SU|
|00002670| 42 5f 44 0d 0d 20 20 76 | 61 6c 20 6d 6f 76 65 20 |B_D.. v|al move |
|00002680| 3d 20 6b 65 65 70 20 4d | 4f 56 45 0d 0d 20 20 66 |= keep M|OVE.. f|
|00002690| 75 6e 20 6c 62 75 20 28 | 61 2c 62 2c 63 29 20 3d |un lbu (|a,b,c) =|
|000026a0| 20 64 65 6c 61 79 20 4c | 4f 41 44 20 28 42 79 74 | delay L|OAD (Byt|
|000026b0| 65 2c 61 2c 62 2c 63 29 | 20 28 2a 20 6c 6f 61 64 |e,a,b,c)| (* load|
|000026c0| 20 61 6e 64 20 73 74 6f | 72 65 20 2a 29 0d 20 20 | and sto|re *). |
|000026d0| 66 75 6e 20 6c 77 20 28 | 61 2c 62 2c 63 29 20 20 |fun lw (|a,b,c) |
|000026e0| 3d 20 64 65 6c 61 79 20 | 4c 4f 41 44 20 28 57 6f |= delay |LOAD (Wo|
|000026f0| 72 64 2c 61 2c 62 2c 63 | 29 0d 20 20 66 75 6e 20 |rd,a,b,c|). fun |
|00002700| 6c 77 63 31 20 28 61 2c | 62 2c 63 29 20 20 3d 20 |lwc1 (a,|b,c) = |
|00002710| 64 65 6c 61 79 20 4c 4f | 41 44 20 28 46 6c 6f 61 |delay LO|AD (Floa|
|00002720| 74 69 6e 67 2c 61 2c 62 | 2c 63 29 0d 20 20 66 75 |ting,a,b|,c). fu|
|00002730| 6e 20 73 62 20 28 61 2c | 62 2c 63 29 20 20 3d 20 |n sb (a,|b,c) = |
|00002740| 6b 65 65 70 20 53 54 4f | 52 45 20 28 42 79 74 65 |keep STO|RE (Byte|
|00002750| 2c 61 2c 62 2c 63 29 0d | 20 20 66 75 6e 20 73 77 |,a,b,c).| fun sw|
|00002760| 20 28 61 2c 62 2c 63 29 | 20 20 3d 20 6b 65 65 70 | (a,b,c)| = keep|
|00002770| 20 53 54 4f 52 45 20 28 | 57 6f 72 64 2c 61 2c 62 | STORE (|Word,a,b|
|00002780| 2c 63 29 0d 20 20 66 75 | 6e 20 73 77 63 31 20 28 |,c). fu|n swc1 (|
|00002790| 61 2c 62 2c 63 29 20 20 | 3d 20 64 65 6c 61 79 20 |a,b,c) |= delay |
|000027a0| 53 54 4f 52 45 20 28 46 | 6c 6f 61 74 69 6e 67 2c |STORE (F|loating,|
|000027b0| 61 2c 62 2c 63 29 0d 20 | 20 76 61 6c 20 6c 75 69 |a,b,c). | val lui|
|000027c0| 20 3d 20 6b 65 65 70 20 | 4c 55 49 0d 0d 20 20 76 | = keep |LUI.. v|
|000027d0| 61 6c 20 73 6c 6c 20 3d | 20 6b 65 65 70 20 53 4c |al sll =| keep SL|
|000027e0| 4c 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |L | |
|000027f0| 20 20 20 20 20 28 2a 20 | 73 68 69 66 74 20 2a 29 | (* |shift *)|
|00002800| 0d 20 20 76 61 6c 20 73 | 72 61 20 3d 20 6b 65 65 |. val s|ra = kee|
|00002810| 70 20 53 52 41 0d 0d 20 | 20 66 75 6e 20 61 6c 69 |p SRA.. | fun ali|
|00002820| 67 6e 28 29 20 3d 20 28 | 29 20 20 20 20 20 20 20 |gn() = (|) |
|00002830| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 28 | | (|
|00002840| 2a 20 6e 65 76 65 72 20 | 6e 65 65 64 20 74 6f 20 |* never |need to |
|00002850| 61 6c 69 67 6e 20 6f 6e | 20 4d 49 50 53 20 2a 29 |align on| MIPS *)|
|00002860| 0d 20 20 76 61 6c 20 6d | 61 72 6b 20 3d 20 6b 65 |. val m|ark = ke|
|00002870| 65 70 20 28 66 6e 20 28 | 29 20 3d 3e 20 4d 41 52 |ep (fn (|) => MAR|
|00002880| 4b 29 0d 20 20 76 61 6c | 20 63 6f 6d 6d 65 6e 74 |K). val| comment|
|00002890| 20 3d 20 6b 65 65 70 20 | 43 4f 4d 4d 45 4e 54 0d | = keep |COMMENT.|
|000028a0| 40 0d 4d 75 6c 74 69 70 | 6c 69 63 61 74 69 6f 6e |@.Multip|lication|
|000028b0| 20 68 61 73 20 61 20 6d | 69 6e 6f 72 20 63 6f 6d | has a m|inor com|
|000028c0| 70 6c 69 63 61 74 69 6f | 6e 3b 20 74 68 65 0d 72 |plicatio|n; the.r|
|000028d0| 65 73 75 6c 74 20 68 61 | 73 20 74 6f 20 62 65 20 |esult ha|s to be |
|000028e0| 66 65 74 63 68 65 64 20 | 66 72 6f 6d 20 74 68 65 |fetched |from the|
|000028f0| 20 4c 4f 20 72 65 67 69 | 73 74 65 72 2e 0d 3c 3c | LO regi|ster..<<|
|00002900| 6d 75 6c 74 69 70 6c 69 | 63 61 74 69 6f 6e 20 61 |multipli|cation a|
|00002910| 6e 64 20 64 69 76 69 73 | 69 6f 6e 20 66 75 6e 63 |nd divis|ion func|
|00002920| 74 69 6f 6e 73 3e 3e 3d | 0d 66 75 6e 20 6d 75 6c |tions>>=|.fun mul|
|00002930| 74 20 28 6f 70 31 2c 20 | 6f 70 32 2c 20 72 65 73 |t (op1, |op2, res|
|00002940| 75 6c 74 29 20 3d 20 6b | 65 65 70 6c 69 73 74 20 |ult) = k|eeplist |
|00002950| 5b 4d 46 4c 4f 20 72 65 | 73 75 6c 74 2c 20 4d 55 |[MFLO re|sult, MU|
|00002960| 4c 54 20 28 6f 70 31 2c | 20 6f 70 32 29 5d 0d 76 |LT (op1,| op2)].v|
|00002970| 61 6c 20 6d 66 68 69 20 | 3d 20 6b 65 65 70 20 4d |al mfhi |= keep M|
|00002980| 46 48 49 0d 40 0d 44 69 | 76 69 73 69 6f 6e 20 68 |FHI.@.Di|vision h|
|00002990| 61 73 20 61 20 6d 61 6a | 6f 72 20 63 6f 6d 70 6c |as a maj|or compl|
|000029a0| 69 63 61 74 69 6f 6e 3b | 20 49 20 6d 75 73 74 20 |ication;| I must |
|000029b0| 74 65 73 74 20 66 6f 72 | 20 64 69 76 69 64 65 20 |test for| divide |
|000029c0| 62 79 20 7a 65 72 6f 20 | 73 69 6e 63 65 0d 74 68 |by zero |since.th|
|000029d0| 65 20 68 61 72 64 77 61 | 72 65 20 64 6f 65 73 20 |e hardwa|re does |
|000029e0| 6e 6f 74 2e 0d 49 66 20 | 74 68 65 20 64 69 76 69 |not..If |the divi|
|000029f0| 73 6f 72 20 69 73 20 7a | 65 72 6f 2c 20 49 20 63 |sor is z|ero, I c|
|00002a00| 61 75 73 65 20 61 6e 20 | 6f 76 65 72 66 6c 6f 77 |ause an |overflow|
|00002a10| 20 65 78 63 65 70 74 69 | 6f 6e 20 62 79 0d 61 64 | excepti|on by.ad|
|00002a20| 64 69 6e 67 20 5b 5b 6c | 69 6d 69 74 72 65 67 5d |ding [[l|imitreg]|
|00002a30| 5d 20 74 6f 20 69 74 73 | 65 6c 66 2e 0d 3c 3c 6d |] to its|elf..<<m|
|00002a40| 75 6c 74 69 70 6c 69 63 | 61 74 69 6f 6e 20 61 6e |ultiplic|ation an|
|00002a50| 64 20 64 69 76 69 73 69 | 6f 6e 20 66 75 6e 63 74 |d divisi|on funct|
|00002a60| 69 6f 6e 73 3e 3e 3d 0d | 66 75 6e 20 6f 70 20 64 |ions>>=.|fun op d|
|00002a70| 69 76 20 28 6f 70 31 2c | 20 6f 70 32 2c 20 72 65 |iv (op1,| op2, re|
|00002a80| 73 75 6c 74 29 20 3d 0d | 20 20 6c 65 74 20 76 61 |sult) =.| let va|
|00002a90| 6c 20 6e 65 78 74 20 3d | 20 6e 65 77 6c 61 62 65 |l next =| newlabe|
|00002aa0| 6c 28 29 0d 20 20 69 6e | 20 20 6b 65 65 70 6c 69 |l(). in| keepli|
|00002ab0| 73 74 20 5b 0d 20 20 20 | 20 20 20 20 20 4d 46 4c |st [. | MFL|
|00002ac0| 4f 20 72 65 73 75 6c 74 | 2c 09 09 09 20 20 09 28 |O result|,... .(|
|00002ad0| 2a 20 67 65 74 20 74 68 | 65 20 72 65 73 75 6c 74 |* get th|e result|
|00002ae0| 20 2a 29 0d 20 20 20 20 | 20 20 20 20 44 45 46 49 | *). | DEFI|
|00002af0| 4e 45 20 6e 65 78 74 2c | 09 09 09 20 20 09 28 2a |NE next,|... .(*|
|00002b00| 20 73 6b 69 70 20 74 6f | 20 68 65 72 65 20 69 66 | skip to| here if|
|00002b10| 20 6e 6f 6e 7a 65 72 6f | 20 2a 29 0d 09 42 52 45 | nonzero| *)..BRE|
|00002b20| 41 4b 20 37 2c 09 09 09 | 09 28 2a 20 73 69 67 6e |AK 7,...|.(* sign|
|00002b30| 61 6c 73 20 7a 65 72 6f | 64 69 76 69 64 65 20 2a |als zero|divide *|
|00002b40| 29 0d 20 20 20 20 20 20 | 20 20 44 49 56 20 28 6f |). | DIV (o|
|00002b50| 70 31 2c 20 6f 70 32 29 | 2c 09 09 09 20 20 09 28 |p1, op2)|,... .(|
|00002b60| 2a 20 64 69 76 69 64 65 | 20 69 6e 20 64 65 6c 61 |* divide| in dela|
|00002b70| 79 20 73 6c 6f 74 20 2a | 29 0d 20 20 20 20 20 20 |y slot *|). |
|00002b80| 20 20 42 45 51 20 28 66 | 61 6c 73 65 2c 20 52 65 | BEQ (f|alse, Re|
|00002b90| 67 20 30 2c 20 6f 70 32 | 2c 20 6e 65 78 74 29 09 |g 0, op2|, next).|
|00002ba0| 20 09 28 2a 20 73 6b 69 | 70 20 69 66 20 64 69 76 | .(* ski|p if div|
|00002bb0| 69 73 6f 72 20 6e 6f 6e | 7a 65 72 6f 20 2a 29 0d |isor non|zero *).|
|00002bc0| 20 20 20 20 20 20 5d 0d | 20 20 65 6e 64 0d 40 20 | ].| end.@ |
|00002bd0| 0d 46 6f 72 20 6e 6f 77 | 2c 20 6c 61 62 65 6c 73 |.For now|, labels|
|00002be0| 20 61 72 65 20 6a 75 73 | 74 20 70 6f 69 6e 74 65 | are jus|t pointe|
|00002bf0| 72 73 20 74 6f 20 69 6e | 74 65 67 65 72 73 2e 0d |rs to in|tegers..|
|00002c00| 44 75 72 69 6e 67 20 63 | 6f 64 65 20 67 65 6e 65 |During c|ode gene|
|00002c10| 72 61 74 69 6f 6e 2c 20 | 74 68 6f 73 65 20 69 6e |ration, |those in|
|00002c20| 74 65 67 65 72 73 20 77 | 69 6c 6c 20 62 65 20 73 |tegers w|ill be s|
|00002c30| 65 74 20 74 6f 20 70 6f | 73 69 74 69 6f 6e 73 0d |et to po|sitions.|
|00002c40| 69 6e 20 74 68 65 20 69 | 6e 73 74 72 75 63 74 69 |in the i|nstructi|
|00002c50| 6f 6e 20 73 74 72 65 61 | 6d 2c 20 61 6e 64 20 74 |on strea|m, and t|
|00002c60| 68 65 6e 20 74 68 65 79 | 27 6c 6c 20 62 65 20 75 |hen they|'ll be u|
|00002c70| 73 65 66 75 6c 20 61 73 | 20 61 64 64 72 65 73 73 |seful as| address|
|00002c80| 65 73 0d 72 65 6c 61 74 | 69 76 65 20 74 6f 20 74 |es.relat|ive to t|
|00002c90| 68 65 20 70 72 6f 67 72 | 61 6d 20 63 6f 75 6e 74 |he progr|am count|
|00002ca0| 65 72 20 70 6f 69 6e 74 | 65 72 20 28 74 6f 20 62 |er point|er (to b|
|00002cb0| 65 20 68 65 6c 64 20 69 | 6e 20 5b 5b 52 65 67 20 |e held i|n [[Reg |
|00002cc0| 70 63 72 65 67 5d 5d 29 | 2e 0d 3c 3c 64 65 66 69 |pcreg]])|..<<defi|
|00002cd0| 6e 69 74 69 6f 6e 20 6f | 66 20 5b 5b 4c 61 62 65 |nition o|f [[Labe|
|00002ce0| 6c 5d 5d 3e 3e 3d 0d 20 | 20 74 79 70 65 20 4c 61 |l]]>>=. | type La|
|00002cf0| 62 65 6c 20 3d 20 69 6e | 74 20 72 65 66 0d 3c 3c |bel = in|t ref.<<|
|00002d00| 6c 61 62 65 6c 20 66 75 | 6e 63 74 69 6f 6e 73 3e |label fu|nctions>|
|00002d10| 3e 3d 0d 20 20 66 75 6e | 20 6e 65 77 6c 61 62 65 |>=. fun| newlabe|
|00002d20| 6c 20 28 29 20 3d 20 72 | 65 66 20 30 0d 20 20 76 |l () = r|ef 0. v|
|00002d30| 61 6c 20 64 65 66 69 6e | 65 20 3d 20 6b 65 65 70 |al defin|e = keep|
|00002d40| 20 44 45 46 49 4e 45 0d | 20 20 76 61 6c 20 65 6d | DEFINE.| val em|
|00002d50| 69 74 6c 61 62 20 3d 20 | 6b 65 65 70 20 45 4d 49 |itlab = |keep EMI|
|00002d60| 54 4c 41 42 0d 40 0d 48 | 65 72 65 27 73 20 74 68 |TLAB.@.H|ere's th|
|00002d70| 65 20 6f 76 65 72 61 6c | 6c 20 70 6c 61 6e 20 6f |e overal|l plan o|
|00002d80| 66 20 74 68 69 73 20 73 | 74 72 75 63 74 75 72 65 |f this s|tructure|
|00002d90| 3a 0d 3c 3c 2a 3e 3e 3d | 0d 66 75 6e 63 74 6f 72 |:.<<*>>=|.functor|
|00002da0| 20 4d 69 70 73 43 6f 64 | 65 72 28 45 6d 69 74 74 | MipsCod|er(Emitt|
|00002db0| 65 72 3a 20 45 4d 49 54 | 54 45 52 29 20 3a 20 4d |er: EMIT|TER) : M|
|00002dc0| 49 50 53 43 4f 44 45 52 | 20 3d 20 73 74 72 75 63 |IPSCODER| = struc|
|00002dd0| 74 0d 0d 20 20 6f 70 65 | 6e 20 45 6d 69 74 74 65 |t.. ope|n Emitte|
|00002de0| 72 0d 20 20 3c 3c 64 65 | 66 69 6e 69 74 69 6f 6e |r. <<de|finition|
|00002df0| 20 6f 66 20 5b 5b 4c 61 | 62 65 6c 5d 5d 3e 3e 0d | of [[La|bel]]>>.|
|00002e00| 0d 20 20 64 61 74 61 74 | 79 70 65 20 52 65 67 69 |. datat|ype Regi|
|00002e10| 73 74 65 72 20 3d 20 52 | 65 67 20 6f 66 20 69 6e |ster = R|eg of in|
|00002e20| 74 0d 0d 20 20 64 61 74 | 61 74 79 70 65 20 45 41 |t.. dat|atype EA|
|00002e30| 20 3d 20 44 69 72 65 63 | 74 20 6f 66 20 52 65 67 | = Direc|t of Reg|
|00002e40| 69 73 74 65 72 0d 20 20 | 20 20 20 20 20 20 20 20 |ister. | |
|00002e50| 20 20 20 20 7c 20 49 6d | 6d 65 64 20 6f 66 20 69 | | Im|med of i|
|00002e60| 6e 74 0d 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |nt. | |
|00002e70| 20 7c 20 49 6d 6d 65 64 | 6c 61 62 20 6f 66 20 4c | | Immed|lab of L|
|00002e80| 61 62 65 6c 0d 0d 20 20 | 3c 3c 64 65 66 69 6e 69 |abel.. |<<defini|
|00002e90| 74 69 6f 6e 20 6f 66 20 | 5b 5b 69 6e 73 74 72 5d |tion of |[[instr]|
|00002ea0| 5d 3e 3e 0d 0d 20 20 3c | 3c 69 6e 73 74 72 75 63 |]>>.. <|<instruc|
|00002eb0| 74 69 6f 6e 20 73 74 72 | 65 61 6d 20 61 6e 64 20 |tion str|eam and |
|00002ec0| 69 74 73 20 66 75 6e 63 | 74 69 6f 6e 73 3e 3e 0d |its func|tions>>.|
|00002ed0| 20 20 0d 20 20 73 74 72 | 75 63 74 75 72 65 20 4d | . str|ucture M|
|00002ee0| 20 3d 20 73 74 72 75 63 | 74 0d 20 20 20 20 3c 3c | = struc|t. <<|
|00002ef0| 5b 5b 4d 49 50 53 43 4f | 44 45 52 5d 5d 20 66 75 |[[MIPSCO|DER]] fu|
|00002f00| 6e 63 74 69 6f 6e 73 3e | 3e 0d 20 20 65 6e 64 0d |nctions>|>. end.|
|00002f10| 0d 20 20 6f 70 65 6e 20 | 4d 0d 0d 20 20 3c 3c 66 |. open |M.. <<f|
|00002f20| 75 6e 63 74 69 6f 6e 73 | 20 74 68 61 74 20 61 73 |unctions| that as|
|00002f30| 73 65 6d 62 6c 65 20 5b | 5b 69 6e 73 74 72 5d 5d |semble [|[instr]]|
|00002f40| 73 20 69 6e 74 6f 20 63 | 6f 64 65 3e 3e 0d 0d 20 |s into c|ode>>.. |
|00002f50| 20 3c 3c 73 74 61 74 69 | 73 74 69 63 73 3e 3e 0d | <<stati|stics>>.|
|00002f60| 0d 65 6e 64 20 28 2a 20 | 4d 69 70 73 49 6e 73 74 |.end (* |MipsInst|
|00002f70| 72 20 2a 29 0d 40 20 5c | 73 75 62 73 65 63 74 69 |r *).@ \|subsecti|
|00002f80| 6f 6e 7b 53 69 7a 65 73 | 20 6f 66 20 7b 5c 74 74 |on{Sizes| of {\tt|
|00002f90| 20 69 6e 73 74 72 7d 73 | 7d 0d 4e 6f 77 20 6c 65 | instr}s|}.Now le|
|00002fa0| 74 27 73 20 63 6f 6e 73 | 69 64 65 72 20 74 68 65 |t's cons|ider the|
|00002fb0| 20 63 6f 72 72 65 73 70 | 6f 6e 64 65 6e 63 65 20 | corresp|ondence |
|00002fc0| 62 65 74 77 65 65 6e 20 | 6f 75 72 20 5b 5b 69 6e |between |our [[in|
|00002fd0| 73 74 72 5d 5d 20 74 79 | 70 65 20 61 6e 64 20 74 |str]] ty|pe and t|
|00002fe0| 68 65 0d 61 63 74 75 61 | 6c 20 4d 49 50 53 20 69 |he.actua|l MIPS i|
|00002ff0| 6e 73 74 72 75 63 74 69 | 6f 6e 73 20 77 65 20 69 |nstructi|ons we i|
|00003000| 6e 74 65 6e 64 20 74 6f | 20 65 6d 69 74 2e 0d 4f |ntend to| emit..O|
|00003010| 6e 65 20 69 6d 70 6f 72 | 74 61 6e 74 20 70 72 6f |ne impor|tant pro|
|00003020| 62 6c 65 6d 20 74 6f 20 | 73 6f 6c 76 65 20 69 73 |blem to |solve is|
|00003030| 20 66 69 67 75 72 69 6e | 67 20 6f 75 74 20 68 6f | figurin|g out ho|
|00003040| 77 20 62 69 67 20 74 68 | 69 6e 67 73 20 61 72 65 |w big th|ings are|
|00003050| 2c 20 0d 73 6f 20 74 68 | 61 74 20 77 65 20 6b 6e |, .so th|at we kn|
|00003060| 6f 77 20 77 68 61 74 20 | 61 64 64 72 65 73 73 65 |ow what |addresse|
|00003070| 73 20 74 6f 20 67 65 6e | 65 72 61 74 65 20 66 6f |s to gen|erate fo|
|00003080| 72 20 74 68 65 20 76 61 | 72 69 6f 75 73 20 6c 61 |r the va|rious la|
|00003090| 62 65 6c 73 2e 0d 57 65 | 20 77 69 6c 6c 20 61 6c |bels..We| will al|
|000030a0| 73 6f 20 77 61 6e 74 20 | 74 6f 20 6b 6e 6f 77 20 |so want |to know |
|000030b0| 77 68 61 74 20 61 64 64 | 72 65 73 73 20 69 73 20 |what add|ress is |
|000030c0| 63 75 72 72 65 6e 74 6c | 79 20 73 74 6f 72 65 64 |currentl|y stored|
|000030d0| 20 69 6e 20 74 68 65 20 | 70 72 6f 67 72 61 6d 0d | in the |program.|
|000030e0| 63 6f 75 6e 74 65 72 20 | 72 65 67 73 69 74 65 72 |counter |regsiter|
|000030f0| 20 28 5b 5b 70 63 72 65 | 67 5d 5d 29 2c 0d 62 65 | ([[pcre|g]]),.be|
|00003100| 63 61 75 73 65 20 77 65 | 27 6c 6c 20 6e 65 65 64 |cause we|'ll need|
|00003110| 20 74 6f 20 6b 6e 6f 77 | 20 77 68 65 6e 20 73 6f | to know| when so|
|00003120| 6d 65 74 68 69 6e 67 20 | 69 73 20 63 6c 6f 73 65 |mething |is close|
|00003130| 20 0d 65 6e 6f 75 67 68 | 20 74 68 61 74 20 77 65 | .enough| that we|
|00003140| 20 63 61 6e 20 75 73 65 | 20 61 20 73 69 78 74 65 | can use| a sixte|
|00003150| 65 6e 2d 62 69 74 20 61 | 64 64 72 65 73 73 20 72 |en-bit a|ddress r|
|00003160| 65 6c 61 74 69 76 65 20 | 74 6f 20 74 68 61 74 20 |elative |to that |
|00003170| 72 65 67 69 73 74 65 72 | 2e 0d 54 68 65 20 6b 69 |register|..The ki|
|00003180| 6e 64 20 6f 66 20 61 64 | 64 72 65 73 73 20 77 65 |nd of ad|dress we|
|00003190| 20 63 61 6e 20 75 73 65 | 20 77 69 6c 6c 20 64 65 | can use| will de|
|000031a0| 74 65 72 6d 69 6e 65 20 | 68 6f 77 20 62 69 67 20 |termine |how big |
|000031b0| 74 68 69 6e 67 73 20 61 | 72 65 2e 0d 0d 57 65 27 |things a|re...We'|
|000031c0| 6c 6c 20 72 65 61 72 72 | 61 6e 67 65 20 74 68 65 |ll rearr|ange the|
|000031d0| 20 63 6f 64 65 20 73 6f | 20 74 68 61 74 20 77 65 | code so| that we|
|000031e0| 20 68 61 76 65 20 61 20 | 6c 69 73 74 20 6f 66 20 | have a |list of |
|000031f0| 5b 5b 72 65 66 20 69 6e | 74 20 2a 20 69 6e 73 74 |[[ref in|t * inst|
|00003200| 72 5d 5d 20 70 61 69 72 | 73 2c 0d 77 68 65 72 65 |r]] pair|s,.where|
|00003210| 20 74 68 65 20 5b 5b 72 | 65 66 20 69 6e 74 5d 5d | the [[r|ef int]]|
|00003220| 20 73 74 6f 72 65 73 20 | 74 68 65 20 70 6f 73 69 | stores |the posi|
|00003230| 74 69 6f 6e 20 69 6e 20 | 74 68 65 20 6c 69 73 74 |tion in |the list|
|00003240| 2e 20 0d 28 50 6f 73 69 | 74 69 6f 6e 73 20 73 74 |. .(Posi|tions st|
|00003250| 61 72 74 20 61 74 20 7a | 65 72 6f 2e 29 0d 53 69 |art at z|ero.).Si|
|00003260| 6e 63 65 20 69 6e 20 74 | 68 65 20 4d 49 50 53 20 |nce in t|he MIPS |
|00003270| 61 6c 6c 20 69 6e 73 74 | 72 75 63 74 69 6f 6e 73 |all inst|ructions|
|00003280| 20 61 72 65 20 74 68 65 | 20 73 61 6d 65 20 73 69 | are the| same si|
|00003290| 7a 65 2c 20 77 65 20 6d | 65 61 73 75 72 65 0d 70 |ze, we m|easure.p|
|000032a0| 6f 73 69 74 69 6f 6e 20 | 61 73 20 6e 75 6d 62 65 |osition |as numbe|
|000032b0| 72 20 6f 66 20 69 6e 73 | 74 72 75 63 74 69 6f 6e |r of ins|truction|
|000032c0| 73 2e 0d 57 68 69 6c 65 | 20 77 65 27 72 65 20 61 |s..While| we're a|
|000032d0| 74 20 69 74 2c 20 77 65 | 20 72 65 76 65 72 73 65 |t it, we| reverse|
|000032e0| 20 74 68 65 20 6c 69 73 | 74 20 73 6f 20 74 68 61 | the lis|t so tha|
|000032f0| 74 20 74 68 65 20 68 65 | 61 64 20 77 69 6c 6c 20 |t the he|ad will |
|00003300| 65 78 65 63 75 74 65 20 | 66 69 72 73 74 2c 0d 74 |execute |first,.t|
|00003310| 68 65 6e 20 74 68 65 20 | 72 65 73 74 20 6f 66 20 |hen the |rest of |
|00003320| 74 68 65 20 6c 69 73 74 | 2e 0d 0d 57 65 20 62 65 |the list|...We be|
|00003330| 67 69 6e 20 77 69 74 68 | 20 65 61 63 68 20 70 6f |gin with| each po|
|00003340| 73 69 74 69 6f 6e 20 73 | 65 74 20 74 6f 20 7a 65 |sition s|et to ze|
|00003350| 72 6f 2c 20 61 6e 64 20 | 6d 61 6b 65 20 61 20 70 |ro, and |make a p|
|00003360| 61 73 73 20 6f 76 65 72 | 20 74 68 65 20 6c 69 73 |ass over| the lis|
|00003370| 74 20 0d 74 72 79 69 6e | 67 20 74 6f 20 73 65 74 |t .tryin|g to set|
|00003380| 20 74 68 65 20 76 61 6c | 75 65 20 6f 66 20 65 61 | the val|ue of ea|
|00003390| 63 68 20 70 6f 73 69 74 | 69 6f 6e 2e 20 0d 57 65 |ch posit|ion. .We|
|000033a0| 20 64 6f 20 74 68 69 73 | 20 62 79 20 65 73 74 69 | do this| by esti|
|000033b0| 6d 61 74 69 6e 67 20 74 | 68 65 20 73 69 7a 65 20 |mating t|he size |
|000033c0| 6f 66 20 28 6e 75 6d 62 | 65 72 20 6f 66 20 4d 49 |of (numb|er of MI|
|000033d0| 50 53 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 73 20 |PS instr|uctions |
|000033e0| 0d 67 65 6e 65 72 61 74 | 65 64 20 66 6f 72 29 20 |.generat|ed for) |
|000033f0| 65 61 63 68 20 5b 5b 69 | 6e 73 74 72 5d 5d 2e 0d |each [[i|nstr]]..|
|00003400| 53 69 6e 63 65 20 74 68 | 65 72 65 20 61 72 65 20 |Since th|ere are |
|00003410| 66 6f 72 77 61 72 64 20 | 72 65 66 65 72 65 6e 63 |forward |referenc|
|00003420| 65 73 2c 20 77 65 20 6d | 61 79 20 6e 6f 74 20 68 |es, we m|ay not h|
|00003430| 61 76 65 20 61 6c 6c 20 | 74 68 65 20 64 69 73 74 |ave all |the dist|
|00003440| 61 6e 63 65 73 20 72 69 | 67 68 74 0d 74 68 65 20 |ances ri|ght.the |
|00003450| 66 69 72 73 74 20 74 69 | 6d 65 2c 20 73 6f 20 77 |first ti|me, so w|
|00003460| 65 20 68 61 76 65 20 74 | 6f 20 6d 61 6b 65 20 61 |e have t|o make a|
|00003470| 20 73 65 63 6f 6e 64 20 | 70 61 73 73 2e 0d 42 75 | second |pass..Bu|
|00003480| 74 20 64 75 72 69 6e 67 | 20 74 68 69 73 20 73 65 |t during| this se|
|00003490| 63 6f 6e 64 20 70 61 73 | 73 20 77 65 20 63 6f 75 |cond pas|s we cou|
|000034a0| 6c 64 20 66 69 6e 64 20 | 74 68 61 74 20 73 6f 6d |ld find |that som|
|000034b0| 65 74 68 69 6e 67 20 69 | 73 20 66 75 72 74 68 65 |ething i|s furthe|
|000034c0| 72 0d 61 77 61 79 20 74 | 68 61 6e 20 77 65 20 74 |r.away t|han we t|
|000034d0| 68 6f 75 67 68 74 2c 20 | 61 6e 64 20 77 65 20 68 |hought, |and we h|
|000034e0| 61 76 65 20 74 6f 20 73 | 77 69 74 63 68 20 66 72 |ave to s|witch fr|
|000034f0| 6f 6d 20 75 73 69 6e 67 | 20 61 20 70 63 2d 72 65 |om using| a pc-re|
|00003500| 6c 61 74 69 76 65 20 6d | 6f 64 65 20 74 6f 0d 73 |lative m|ode to.s|
|00003510| 6f 6d 65 74 68 69 6e 67 | 20 65 6c 73 65 20 28 6f |omething| else (o|
|00003520| 72 20 6d 61 79 62 65 20 | 67 72 61 62 20 74 68 65 |r maybe |grab the|
|00003530| 20 6e 65 77 20 70 63 3f | 29 2c 20 77 68 69 63 68 | new pc?|), which|
|00003540| 20 63 68 61 6e 67 65 73 | 20 74 68 65 20 73 69 7a | changes| the siz|
|00003550| 65 20 61 67 61 69 6e 2c | 0d 61 6e 64 20 6d 6f 76 |e again,|.and mov|
|00003560| 65 73 20 74 68 69 6e 67 | 73 20 65 76 65 6e 20 66 |es thing|s even f|
|00003570| 75 72 74 68 65 72 20 61 | 77 61 79 2e 0d 42 65 63 |urther a|way..Bec|
|00003580| 61 75 73 65 20 77 65 20 | 63 61 6e 27 74 20 63 6f |ause we |can't co|
|00003590| 6e 74 72 6f 6c 20 74 68 | 69 73 20 70 72 6f 63 65 |ntrol th|is proce|
|000035a0| 73 73 2c 20 77 65 20 6a | 75 73 74 20 6b 65 65 70 |ss, we j|ust keep|
|000035b0| 20 6d 61 6b 69 6e 67 20 | 70 61 73 73 65 73 20 6f | making |passes o|
|000035c0| 76 65 72 20 74 68 65 0d | 6c 69 73 74 20 75 6e 74 |ver the.|list unt|
|000035d0| 69 6c 20 74 68 65 20 70 | 72 6f 63 65 73 73 20 71 |il the p|rocess q|
|000035e0| 75 69 65 73 63 65 73 20 | 28 77 65 20 67 65 74 20 |uiesces |(we get |
|000035f0| 74 68 65 20 73 61 6d 65 | 20 73 69 7a 65 20 74 77 |the same| size tw|
|00003600| 69 63 65 29 2e 0d 0d 49 | 6e 20 6f 72 64 65 72 20 |ice)...I|n order |
|00003610| 74 6f 20 67 75 61 72 61 | 6e 74 65 65 20 74 65 72 |to guara|ntee ter|
|00003620| 6d 69 6e 61 74 69 6f 6e | 2c 20 77 65 20 68 61 76 |mination|, we hav|
|00003630| 65 20 74 6f 20 6d 61 6b | 65 20 73 75 72 65 20 6c |e to mak|e sure l|
|00003640| 61 74 65 72 20 70 61 73 | 73 65 73 20 6f 6e 6c 79 |ater pas|ses only|
|00003650| 20 0d 69 6e 63 72 65 61 | 73 65 20 74 68 65 20 73 | .increa|se the s|
|00003660| 69 7a 65 73 20 6f 66 20 | 74 68 69 6e 67 73 2e 0d |izes of |things..|
|00003670| 54 68 69 73 20 69 73 20 | 73 75 66 66 69 63 69 65 |This is |sufficie|
|00003680| 6e 74 20 73 69 6e 63 65 | 20 74 68 65 72 65 20 69 |nt since| there i|
|00003690| 73 20 61 20 6d 61 78 69 | 6d 75 6d 20 6e 75 6d 62 |s a maxi|mum numb|
|000036a0| 65 72 20 6f 66 20 4d 49 | 50 53 20 69 6e 73 74 72 |er of MI|PS instr|
|000036b0| 75 63 74 69 6f 6e 73 0d | 77 65 20 63 61 6e 20 67 |uctions.|we can g|
|000036c0| 65 6e 65 72 61 74 65 20 | 66 6f 72 20 65 61 63 68 |enerate |for each|
|000036d0| 20 5b 5b 69 6e 73 74 72 | 5d 5d 2e 0d 0d 0d 57 68 | [[instr|]]....Wh|
|000036e0| 69 6c 65 20 77 65 27 72 | 65 20 61 74 20 69 74 2c |ile we'r|e at it,|
|000036f0| 20 77 65 20 6d 69 67 68 | 74 20 77 61 6e 74 20 74 | we migh|t want t|
|00003700| 6f 20 63 6f 6d 70 6c 69 | 63 61 74 65 20 74 68 69 |o compli|cate thi|
|00003710| 6e 67 73 20 62 79 20 6d | 61 6b 69 6e 67 20 74 68 |ngs by m|aking th|
|00003720| 65 20 66 75 6e 63 74 69 | 6f 6e 0d 74 68 61 74 20 |e functi|on.that |
|00003730| 64 6f 65 73 20 74 68 65 | 20 70 61 73 73 65 73 20 |does the| passes |
|00003740| 61 6c 73 6f 20 65 6d 69 | 74 20 63 6f 64 65 2e 0d |also emi|t code..|
|00003750| 46 6f 72 20 61 20 73 69 | 6e 67 6c 65 20 70 61 73 |For a si|ngle pas|
|00003760| 73 20 77 65 20 68 61 6e | 64 20 61 6e 20 6f 70 74 |s we han|d an opt|
|00003770| 69 6f 6e 61 6c 20 74 72 | 69 70 6c 65 20 6f 66 20 |ional tr|iple of |
|00003780| 65 6d 69 74 74 65 72 73 | 2c 20 74 68 65 20 69 6e |emitters|, the in|
|00003790| 69 74 69 61 6c 20 70 6f | 73 69 74 69 6f 6e 2c 0d |itial po|sition,.|
|000037a0| 61 6e 20 5b 5b 69 6e 74 | 20 6f 70 74 69 6f 6e 5d |an [[int| option]|
|000037b0| 5d 20 66 6f 72 20 74 68 | 65 20 70 72 6f 67 72 61 |] for th|e progra|
|000037c0| 6d 20 63 6f 75 6e 74 65 | 72 20 70 6f 69 6e 74 65 |m counte|r pointe|
|000037d0| 72 20 28 69 66 20 6b 6e | 6f 77 6e 29 2c 20 61 6e |r (if kn|own), an|
|000037e0| 64 20 74 68 65 0d 69 6e | 73 74 72 75 63 74 69 6f |d the.in|structio|
|000037f0| 6e 73 2e 0d 0d 0d 0d 49 | 27 6d 20 6e 6f 74 20 73 |ns.....I|'m not s|
|00003800| 75 72 65 20 77 68 61 74 | 20 65 78 70 6c 61 69 6e |ure what| explain|
|00003810| 73 20 74 68 65 20 75 73 | 65 20 6f 66 20 74 68 65 |s the us|e of the|
|00003820| 20 5b 5b 72 65 66 20 69 | 6e 74 5d 5d 20 74 6f 20 | [[ref i|nt]] to |
|00003830| 74 72 61 63 6b 20 74 68 | 65 20 70 6f 73 69 74 69 |track th|e positi|
|00003840| 6f 6e 2c 0d 69 6e 73 74 | 65 61 64 20 6f 66 20 6a |on,.inst|ead of j|
|00003850| 75 73 74 20 61 6e 20 5b | 5b 69 6e 74 5d 5d 2d 2d |ust an [|[int]]--|
|00003860| 2d 69 74 20 6d 69 67 68 | 74 20 62 65 20 61 20 64 |-it migh|t be a d|
|00003870| 65 73 69 72 65 20 74 6f | 20 61 76 6f 69 64 20 74 |esire to| avoid t|
|00003880| 68 65 0d 6f 76 65 72 68 | 65 61 64 20 6f 66 20 63 |he.overh|ead of c|
|00003890| 72 65 61 74 69 6e 67 20 | 61 20 62 75 6e 63 68 20 |reating |a bunch |
|000038a0| 6f 66 20 6e 65 77 20 6f | 62 6a 65 63 74 73 2c 20 |of new o|bjects, |
|000038b0| 6f 72 20 69 74 20 6d 69 | 67 68 74 20 62 65 20 72 |or it mi|ght be r|
|000038c0| 65 61 6c 6c 79 20 68 61 | 72 64 0d 74 6f 20 64 6f |eally ha|rd.to do|
|000038d0| 20 74 68 65 20 70 61 73 | 73 65 73 20 63 68 65 61 | the pas|ses chea|
|000038e0| 70 6c 79 2e 0d 49 74 20 | 73 68 6f 75 6c 64 20 74 |ply..It |should t|
|000038f0| 68 69 6e 6b 20 61 20 76 | 61 72 69 61 74 69 6f 6e |hink a v|ariation|
|00003900| 20 6f 6e 20 5b 5b 6d 61 | 70 5d 5d 20 77 6f 75 6c | on [[ma|p]] woul|
|00003910| 64 20 64 6f 20 74 68 65 | 20 6a 6f 62 2c 20 62 75 |d do the| job, bu|
|00003920| 74 20 6d 61 79 62 65 20 | 49 27 6d 0d 6d 69 73 73 |t maybe |I'm.miss|
|00003930| 69 6e 67 20 73 6f 6d 65 | 74 68 69 6e 67 2e 0d 0d |ing some|thing...|
|00003940| 40 0d 5b 5b 65 6d 69 74 | 20 3a 20 69 6e 74 20 2a |@.[[emit| : int *|
|00003950| 20 69 6e 74 20 2d 3e 20 | 75 6e 69 74 5d 5d 20 65 | int -> |unit]] e|
|00003960| 6d 69 74 73 20 6f 6e 65 | 20 69 6e 73 74 72 75 63 |mits one| instruc|
|00003970| 74 69 6f 6e 2c 20 0d 61 | 6e 64 20 5b 5b 65 6d 69 |tion, .a|nd [[emi|
|00003980| 74 5f 73 74 72 69 6e 67 | 20 3a 20 69 6e 74 20 2d |t_string| : int -|
|00003990| 3e 20 73 74 72 69 6e 67 | 20 2d 3e 20 75 6e 69 74 |> string| -> unit|
|000039a0| 5d 5d 20 65 6d 69 74 73 | 20 61 20 73 74 72 69 6e |]] emits| a strin|
|000039b0| 67 20 63 6f 6e 73 74 61 | 6e 74 2e 0d 5b 5b 65 6d |g consta|nt..[[em|
|000039c0| 69 74 5f 73 74 72 69 6e | 67 5d 5d 20 63 6f 75 6c |it_strin|g]] coul|
|000039d0| 64 20 62 65 20 73 70 65 | 63 69 66 69 65 64 20 61 |d be spe|cified a|
|000039e0| 73 20 61 20 66 75 6e 63 | 74 69 6f 6e 20 6f 66 20 |s a func|tion of |
|000039f0| 5b 5b 65 6d 69 74 5d 5d | 2c 0d 62 75 74 20 74 68 |[[emit]]|,.but th|
|00003a00| 65 20 6e 61 74 75 72 65 | 20 6f 66 20 74 68 65 20 |e nature| of the |
|00003a10| 66 75 6e 63 74 69 6f 6e | 20 77 6f 75 6c 64 20 64 |function| would d|
|00003a20| 65 70 65 6e 64 20 6f 6e | 20 77 68 65 74 68 65 72 |epend on| whether|
|00003a30| 20 74 68 65 20 74 61 72 | 67 65 74 0d 6d 61 63 68 | the tar|get.mach|
|00003a40| 69 6e 65 20 77 61 73 20 | 6c 69 74 74 6c 65 2d 65 |ine was |little-e|
|00003a50| 6e 64 69 61 6e 20 6f 72 | 20 62 69 67 2d 65 6e 64 |ndian or| big-end|
|00003a60| 69 61 6e 2c 20 61 6e 64 | 20 77 65 20 64 6f 6e 27 |ian, and| we don'|
|00003a70| 74 20 77 61 6e 74 20 74 | 6f 20 68 61 76 65 0d 74 |t want t|o have.t|
|00003a80| 68 61 74 20 64 65 70 65 | 6e 64 65 6e 63 79 20 62 |hat depe|ndency b|
|00003a90| 75 69 6c 74 20 69 6e 2e | 0d 0d 20 5b 5b 69 6e 73 |uilt in.|.. [[ins|
|00003aa0| 74 72 73 5d 5d 20 69 73 | 20 74 68 65 0d 6c 69 73 |trs]] is| the.lis|
|00003ab0| 74 20 6f 66 20 69 6e 73 | 74 72 75 63 74 69 6f 6e |t of ins|truction|
|00003ac0| 73 20 28 69 6e 20 65 78 | 65 63 75 74 65 2d 68 65 |s (in ex|ecute-he|
|00003ad0| 61 64 2d 6c 61 73 74 20 | 6f 72 64 65 72 29 2e 0d |ad-last |order)..|
|00003ae0| 0d 54 68 65 20 73 65 63 | 6f 6e 64 20 61 72 67 75 |.The sec|ond argu|
|00003af0| 6d 65 6e 74 20 74 6f 20 | 5b 5b 70 61 73 73 5d 5d |ment to |[[pass]]|
|00003b00| 20 69 6e 64 69 63 61 74 | 65 73 20 66 6f 72 20 77 | indicat|es for w|
|00003b10| 68 61 74 20 69 6e 73 74 | 72 75 63 74 69 6f 6e 73 |hat inst|ructions|
|00003b20| 20 63 6f 64 65 0d 69 73 | 20 74 6f 20 62 65 20 67 | code.is| to be g|
|00003b30| 65 6e 65 72 61 74 65 64 | 2e 0d 49 74 20 69 73 20 |enerated|..It is |
|00003b40| 61 20 72 65 63 6f 72 64 | 20 28 70 6f 73 69 74 69 |a record| (positi|
|00003b50| 6f 6e 20 6f 66 20 6e 65 | 78 74 20 69 6e 73 74 72 |on of ne|xt instr|
|00003b60| 75 63 74 69 6f 6e 2c 20 | 70 72 6f 67 72 61 6d 20 |uction, |program |
|00003b70| 63 6f 75 6e 74 65 72 20 | 70 6f 69 6e 74 65 72 20 |counter |pointer |
|00003b80| 69 66 20 61 6e 79 2c 0d | 72 65 6d 61 69 6e 69 6e |if any,.|remainin|
|00003b90| 67 20 69 6e 73 74 72 75 | 63 74 69 6f 6e 73 20 74 |g instru|ctions t|
|00003ba0| 6f 20 67 65 6e 65 72 61 | 74 65 20 5b 77 69 74 68 |o genera|te [with|
|00003bb0| 20 70 6f 73 69 74 69 6f | 6e 73 5d 29 2e 0d 0d 5c | positio|ns])...\|
|00003bc0| 69 6e 64 65 6e 74 20 5b | 5b 70 72 65 70 61 72 65 |indent [|[prepare|
|00003bd0| 5d 5d 20 70 72 6f 64 75 | 63 65 73 20 74 77 6f 20 |]] produ|ces two |
|00003be0| 72 65 73 75 6c 74 73 3a | 20 74 68 65 20 69 6e 73 |results:| the ins|
|00003bf0| 74 72 75 63 74 69 6f 6e | 20 73 74 72 65 61 6d 20 |truction| stream |
|00003c00| 77 69 74 68 0d 73 69 7a | 65 20 70 6f 69 6e 74 65 |with.siz|e pointe|
|00003c10| 72 73 20 61 64 64 65 64 | 2c 20 61 6e 64 20 74 68 |rs added|, and th|
|00003c20| 65 20 74 6f 74 61 6c 20 | 73 69 7a 65 20 6f 66 20 |e total |size of |
|00003c30| 63 6f 64 65 20 74 6f 20 | 62 65 20 67 65 6e 65 72 |code to |be gener|
|00003c40| 61 74 65 64 2e 0d 57 65 | 20 61 64 64 20 74 68 65 |ated..We| add the|
|00003c50| 20 74 6f 74 61 6c 20 73 | 69 7a 65 20 62 65 63 61 | total s|ize beca|
|00003c60| 75 73 65 20 74 68 61 74 | 20 69 73 20 74 68 65 20 |use that| is the |
|00003c70| 6f 6e 6c 79 20 77 61 79 | 20 74 6f 20 66 69 6e 64 |only way| to find|
|00003c80| 20 74 68 65 20 6e 75 6d | 62 65 72 0d 6f 66 20 5b | the num|ber.of [|
|00003c90| 5b 62 6c 74 7a 61 6c 5d | 5d 73 2c 20 77 68 69 63 |[bltzal]|]s, whic|
|00003ca0| 68 20 61 72 65 20 69 6d | 70 6c 69 63 69 74 20 69 |h are im|plicit i|
|00003cb0| 6e 20 74 68 65 20 69 6e | 73 74 72 75 63 74 69 6f |n the in|structio|
|00003cc0| 6e 20 73 74 72 65 61 6d | 2e 0d 0d 3c 3c 61 73 73 |n stream|...<<ass|
|00003cd0| 65 6d 62 6c 65 72 3e 3e | 3d 0d 66 75 6e 20 70 72 |embler>>|=.fun pr|
|00003ce0| 65 70 61 72 65 20 69 6e | 73 74 72 73 20 3d 0d 20 |epare in|strs =. |
|00003cf0| 6c 65 74 20 66 75 6e 20 | 61 64 64 5f 70 6f 73 69 |let fun |add_posi|
|00003d00| 74 69 6f 6e 73 28 64 6f | 6e 65 2c 20 69 6e 73 74 |tions(do|ne, inst|
|00003d10| 3a 3a 72 65 73 74 29 20 | 3d 20 20 0d 20 20 20 20 |::rest) |= . |
|00003d20| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 61 64 64 | | add|
|00003d30| 5f 70 6f 73 69 74 69 6f | 6e 73 28 20 28 72 65 66 |_positio|ns( (ref|
|00003d40| 20 30 2c 20 69 6e 73 74 | 29 20 3a 3a 20 64 6f 6e | 0, inst|) :: don|
|00003d50| 65 2c 20 72 65 73 74 29 | 0d 20 20 20 20 20 20 20 |e, rest)|. |
|00003d60| 7c 20 61 64 64 5f 70 6f | 73 69 74 69 6f 6e 73 28 || add_po|sitions(|
|00003d70| 64 6f 6e 65 2c 20 6e 69 | 6c 29 20 3d 20 64 6f 6e |done, ni|l) = don|
|00003d80| 65 0d 0d 20 20 20 20 20 | 76 61 6c 20 69 6e 73 74 |e.. |val inst|
|00003d90| 72 73 27 20 3d 20 61 64 | 64 5f 70 6f 73 69 74 69 |rs' = ad|d_positi|
|00003da0| 6f 6e 73 28 6e 69 6c 2c | 20 69 6e 73 74 72 73 29 |ons(nil,| instrs)|
|00003db0| 20 28 2a 20 72 65 76 65 | 72 73 65 20 61 6e 64 20 | (* reve|rse and |
|00003dc0| 61 64 64 20 5b 5b 72 65 | 66 20 69 6e 74 5d 5d 73 |add [[re|f int]]s|
|00003dd0| 2a 29 0d 0d 20 20 20 20 | 20 66 75 6e 20 70 61 73 |*).. | fun pas|
|00003de0| 73 65 73 28 6f 6c 64 73 | 69 7a 65 29 20 3d 20 0d |ses(olds|ize) = .|
|00003df0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00003e00| 28 2a 20 6d 61 6b 65 20 | 70 61 73 73 65 73 20 77 |(* make |passes w|
|00003e10| 69 74 68 20 6e 6f 20 65 | 6d 69 73 73 69 6f 6e 20 |ith no e|mission |
|00003e20| 75 6e 74 69 6c 20 73 69 | 7a 65 20 69 73 20 73 74 |until si|ze is st|
|00003e30| 61 62 6c 65 2a 29 0d 20 | 20 20 20 20 20 20 20 6c |able*). | l|
|00003e40| 65 74 20 76 61 6c 20 73 | 69 7a 65 20 3d 20 70 61 |et val s|ize = pa|
|00003e50| 73 73 20 66 61 6c 73 65 | 20 28 30 2c 4e 4f 4e 45 |ss false| (0,NONE|
|00003e60| 2c 69 6e 73 74 72 73 27 | 29 0d 20 20 20 20 20 20 |,instrs'|). |
|00003e70| 20 20 69 6e 20 20 69 66 | 20 73 69 7a 65 3d 6f 6c | in if| size=ol|
|00003e80| 64 73 69 7a 65 20 74 68 | 65 6e 20 73 69 7a 65 0d |dsize th|en size.|
|00003e90| 20 20 20 20 20 20 20 20 | 20 20 20 20 65 6c 73 65 | | else|
|00003ea0| 20 70 61 73 73 65 73 20 | 73 69 7a 65 0d 20 20 20 | passes |size. |
|00003eb0| 20 20 20 20 20 65 6e 64 | 0d 20 20 69 6e 20 7b 73 | end|. in {s|
|00003ec0| 69 7a 65 20 3d 20 70 61 | 73 73 65 73 20 30 2c 20 |ize = pa|sses 0, |
|00003ed0| 73 74 72 65 61 6d 20 3d | 20 69 6e 73 74 72 73 27 |stream =| instrs'|
|00003ee0| 7d 0d 20 20 65 6e 64 0d | 0d 66 75 6e 20 61 73 73 |}. end.|.fun ass|
|00003ef0| 65 6d 62 6c 65 20 69 6e | 73 74 72 73 20 3d 0d 20 |emble in|strs =. |
|00003f00| 20 20 20 20 20 20 20 70 | 61 73 73 20 74 72 75 65 | p|ass true|
|00003f10| 20 28 30 2c 4e 4f 4e 45 | 2c 23 73 74 72 65 61 6d | (0,NONE|,#stream|
|00003f20| 20 28 70 72 65 70 61 72 | 65 20 69 6e 73 74 72 73 | (prepar|e instrs|
|00003f30| 29 29 0d 0d 3c 3c 66 75 | 6e 63 74 69 6f 6e 73 20 |))..<<fu|nctions |
|00003f40| 74 68 61 74 20 61 73 73 | 65 6d 62 6c 65 20 5b 5b |that ass|emble [[|
|00003f50| 69 6e 73 74 72 5d 5d 73 | 20 69 6e 74 6f 20 63 6f |instr]]s| into co|
|00003f60| 64 65 3e 3e 3d 0d 66 75 | 6e 20 67 65 74 20 28 53 |de>>=.fu|n get (S|
|00003f70| 4f 4d 45 20 78 29 20 3d | 20 78 20 0d 20 20 7c 20 |OME x) =| x . | |
|00003f80| 67 65 74 20 4e 4f 4e 45 | 20 3d 20 45 72 72 6f 72 |get NONE| = Error|
|00003f90| 4d 73 67 2e 69 6d 70 6f | 73 73 69 62 6c 65 20 22 |Msg.impo|ssible "|
|00003fa0| 6d 69 73 73 69 6e 67 20 | 70 63 70 74 72 20 69 6e |missing |pcptr in|
|00003fb0| 20 6d 69 70 73 63 6f 64 | 65 72 22 0d 0d 3c 3c 5b | mipscod|er"..<<[|
|00003fc0| 5b 70 63 70 74 72 5d 5d | 20 66 75 6e 63 74 69 6f |[pcptr]]| functio|
|00003fd0| 6e 73 3e 3e 0d 3c 3c 73 | 69 6e 67 6c 65 20 70 61 |ns>>.<<s|ingle pa|
|00003fe0| 73 73 3e 3e 0d 3c 3c 61 | 73 73 65 6d 62 6c 65 72 |ss>>.<<a|ssembler|
|00003ff0| 3e 3e 0d 0d 66 75 6e 20 | 63 6f 64 65 67 65 6e 20 |>>..fun |codegen |
|00004000| 28 29 20 3d 20 28 0d 20 | 20 20 20 61 73 73 65 6d |() = (. | assem|
|00004010| 62 6c 65 20 28 21 6b 65 | 70 74 29 3b 0d 20 20 20 |ble (!ke|pt);. |
|00004020| 20 3c 3c 72 65 69 6e 69 | 74 69 61 6c 69 7a 65 20 | <<reini|tialize |
|00004030| 5b 5b 6b 65 70 74 5d 5d | 3e 3e 0d 20 20 20 20 29 |[[kept]]|>>. )|
|00004040| 0d 40 0d 54 68 65 20 70 | 72 6f 67 72 61 6d 20 63 |.@.The p|rogram c|
|00004050| 6f 75 6e 74 65 72 20 70 | 6f 69 6e 74 65 72 20 69 |ounter p|ointer i|
|00004060| 73 20 61 20 64 65 76 69 | 63 65 20 74 68 61 74 20 |s a devi|ce that |
|00004070| 65 6e 61 62 6c 65 73 20 | 75 73 20 74 6f 20 74 6f |enables |us to to|
|00004080| 20 61 64 64 72 65 73 73 | 69 6e 67 0d 72 65 6c 61 | address|ing.rela|
|00004090| 74 69 76 65 20 74 6f 20 | 74 68 65 20 70 63 70 20 |tive to |the pcp |
|000040a0| 72 65 67 69 73 74 65 72 | 2c 20 72 65 67 69 73 74 |register|, regist|
|000040b0| 65 72 20 33 31 2e 0d 54 | 68 65 20 6e 65 65 64 20 |er 31..T|he need |
|000040c0| 66 6f 72 20 69 74 20 61 | 72 69 73 65 73 20 77 68 |for it a|rises wh|
|000040d0| 65 6e 20 77 65 20 77 61 | 6e 74 20 74 6f 20 61 63 |en we wa|nt to ac|
|000040e0| 63 65 73 73 20 61 20 64 | 61 74 61 20 65 6c 65 6d |cess a d|ata elem|
|000040f0| 65 6e 74 20 77 68 69 63 | 68 20 77 65 20 6b 6e 6f |ent whic|h we kno|
|00004100| 77 0d 6f 6e 6c 79 20 62 | 79 20 69 74 73 20 6c 61 |w.only b|y its la|
|00004110| 62 65 6c 2e 0d 54 68 65 | 20 6c 61 62 65 6c 73 20 |bel..The| labels |
|00004120| 67 69 76 65 20 75 73 20 | 61 64 64 72 65 73 73 65 |give us |addresse|
|00004130| 73 20 72 65 6c 61 74 69 | 76 65 20 74 6f 20 74 68 |s relati|ve to th|
|00004140| 65 20 62 65 67 69 6e 6e | 69 6e 67 20 6f 66 20 74 |e beginn|ing of t|
|00004150| 68 65 20 66 75 6e 63 74 | 69 6f 6e 2c 0d 62 75 74 |he funct|ion,.but|
|00004160| 20 77 65 20 63 61 6e 20 | 6f 6e 6c 79 20 75 73 65 | we can |only use|
|00004170| 20 61 64 64 72 65 73 73 | 65 73 20 72 65 6c 61 74 | address|es relat|
|00004180| 69 76 65 20 74 6f 20 73 | 6f 6d 65 20 72 65 67 69 |ive to s|ome regi|
|00004190| 73 74 65 72 2e 0d 54 68 | 65 20 61 6e 73 77 65 72 |ster..Th|e answer|
|000041a0| 20 69 73 20 74 6f 20 73 | 65 74 20 72 65 67 69 73 | is to s|et regis|
|000041b0| 74 65 72 7e 33 31 20 77 | 69 74 68 20 61 20 5b 5b |ter~31 w|ith a [[|
|000041c0| 62 6c 74 7a 61 6c 5d 5d | 20 69 6e 73 74 72 75 63 |bltzal]]| instruc|
|000041d0| 74 69 6f 6e 2c 0d 74 68 | 65 6e 20 75 73 65 20 74 |tion,.th|en use t|
|000041e0| 68 61 74 20 66 6f 72 20 | 61 64 64 72 65 73 73 69 |hat for |addressi|
|000041f0| 6e 67 2e 0d 0d 54 68 65 | 20 66 75 6e 63 74 69 6f |ng...The| functio|
|00004200| 6e 20 5b 5b 6e 65 65 64 | 73 5f 61 5f 70 63 70 74 |n [[need|s_a_pcpt|
|00004210| 72 5d 5d 20 64 65 74 65 | 72 6d 69 6e 65 73 20 77 |r]] dete|rmines w|
|00004220| 68 65 6e 20 69 74 20 69 | 73 20 6e 65 63 65 73 73 |hen it i|s necess|
|00004230| 61 72 79 0d 74 6f 20 68 | 61 76 65 20 61 20 6b 6e |ary.to h|ave a kn|
|00004240| 6f 77 6e 20 76 61 6c 75 | 65 20 69 6e 20 72 65 67 |own valu|e in reg|
|00004250| 69 73 74 65 72 7e 33 31 | 2e 0d 54 68 61 74 20 69 |ister~31|..That i|
|00004260| 73 2c 20 77 65 20 6e 65 | 65 64 20 74 68 65 20 70 |s, we ne|ed the p|
|00004270| 72 6f 67 72 61 6d 20 63 | 6f 75 6e 74 65 72 20 70 |rogram c|ounter p|
|00004280| 6f 69 6e 74 65 72 0d 5c | 62 65 67 69 6e 7b 69 74 |ointer.\|begin{it|
|00004290| 65 6d 69 7a 65 7d 0d 5c | 69 74 65 6d 20 0d 61 74 |emize}.\|item .at|
|000042a0| 20 5b 5b 4e 4f 50 5d 5d | 20 66 6f 72 20 61 20 72 | [[NOP]]| for a r|
|000042b0| 65 61 73 6f 6e 20 74 6f | 20 62 65 20 6e 61 6d 65 |eason to| be name|
|000042c0| 64 20 6c 61 74 65 72 3f | 0d 5c 69 74 65 6d 0d 61 |d later?|.\item.a|
|000042d0| 74 20 61 6e 79 20 6f 70 | 65 72 61 74 69 6f 6e 20 |t any op|eration |
|000042e0| 74 68 61 74 20 75 73 65 | 73 20 61 6e 20 65 66 66 |that use|s an eff|
|000042f0| 65 63 74 69 76 65 20 61 | 64 64 72 65 73 73 20 74 |ective a|ddress t|
|00004300| 68 61 74 20 72 65 66 65 | 72 73 20 74 6f 20 61 20 |hat refe|rs to a |
|00004310| 6c 61 62 65 6c 0d 28 73 | 69 6e 63 65 20 61 6c 6c |label.(s|ince all|
|00004320| 20 6c 61 62 65 6c 73 20 | 68 61 76 65 20 74 6f 20 | labels |have to |
|00004330| 62 65 20 72 65 6c 61 74 | 69 76 65 20 74 6f 20 74 |be relat|ive to t|
|00004340| 68 65 20 70 72 6f 67 72 | 61 6d 20 63 6f 75 6e 74 |he progr|am count|
|00004350| 65 72 29 2e 0d 5c 69 74 | 65 6d 0d 42 45 51 27 73 |er)..\it|em.BEQ's|
|00004360| 20 61 6e 64 20 42 43 4f | 50 31 27 73 20 74 6f 20 | and BCO|P1's to |
|00004370| 76 65 72 79 20 66 61 72 | 20 61 77 61 79 2c 20 0d |very far| away, .|
|00004380| 73 69 6e 63 65 20 77 65 | 20 68 61 76 65 20 74 6f |since we| have to|
|00004390| 20 63 6f 6d 70 75 74 65 | 20 74 68 65 20 61 64 64 | compute| the add|
|000043a0| 72 65 73 73 20 66 6f 72 | 20 61 20 4a 55 4d 50 20 |ress for| a JUMP |
|000043b0| 0d 6b 6e 6f 77 69 6e 67 | 20 74 68 65 20 76 61 6c |.knowing| the val|
|000043c0| 75 65 20 6f 66 20 74 68 | 65 20 70 72 6f 67 72 61 |ue of th|e progra|
|000043d0| 6d 20 63 6f 75 6e 74 65 | 72 20 70 6f 69 6e 74 65 |m counte|r pointe|
|000043e0| 72 2e 0d 5c 65 6e 64 7b | 69 74 65 6d 69 7a 65 7d |r..\end{|itemize}|
|000043f0| 0d 3c 3c 5b 5b 70 63 70 | 74 72 5d 5d 20 66 75 6e |.<<[[pcp|tr]] fun|
|00004400| 63 74 69 6f 6e 73 3e 3e | 3d 0d 66 75 6e 20 6e 65 |ctions>>|=.fun ne|
|00004410| 65 64 73 5f 61 5f 70 63 | 70 74 72 28 5f 2c 53 4c |eds_a_pc|ptr(_,SL|
|00004420| 54 28 5f 2c 49 6d 6d 65 | 64 6c 61 62 20 5f 2c 5f |T(_,Imme|dlab _,_|
|00004430| 29 29 20 3d 20 74 72 75 | 65 0d 20 20 7c 20 6e 65 |)) = tru|e. | ne|
|00004440| 65 64 73 5f 61 5f 70 63 | 70 74 72 28 5f 2c 41 44 |eds_a_pc|ptr(_,AD|
|00004450| 44 28 5f 2c 49 6d 6d 65 | 64 6c 61 62 20 5f 2c 5f |D(_,Imme|dlab _,_|
|00004460| 29 29 20 3d 20 74 72 75 | 65 0d 20 20 7c 20 6e 65 |)) = tru|e. | ne|
|00004470| 65 64 73 5f 61 5f 70 63 | 70 74 72 28 5f 2c 41 4e |eds_a_pc|ptr(_,AN|
|00004480| 44 28 5f 2c 49 6d 6d 65 | 64 6c 61 62 20 5f 2c 5f |D(_,Imme|dlab _,_|
|00004490| 29 29 20 3d 20 74 72 75 | 65 0d 20 20 7c 20 6e 65 |)) = tru|e. | ne|
|000044a0| 65 64 73 5f 61 5f 70 63 | 70 74 72 28 5f 2c 4f 52 |eds_a_pc|ptr(_,OR|
|000044b0| 28 5f 2c 49 6d 6d 65 64 | 6c 61 62 20 5f 2c 5f 29 |(_,Immed|lab _,_)|
|000044c0| 29 20 3d 20 74 72 75 65 | 0d 20 20 7c 20 6e 65 65 |) = true|. | nee|
|000044d0| 64 73 5f 61 5f 70 63 70 | 74 72 28 5f 2c 58 4f 52 |ds_a_pcp|tr(_,XOR|
|000044e0| 28 5f 2c 49 6d 6d 65 64 | 6c 61 62 20 5f 2c 5f 29 |(_,Immed|lab _,_)|
|000044f0| 29 20 3d 20 74 72 75 65 | 0d 20 20 7c 20 6e 65 65 |) = true|. | nee|
|00004500| 64 73 5f 61 5f 70 63 70 | 74 72 28 5f 2c 4d 4f 56 |ds_a_pcp|tr(_,MOV|
|00004510| 45 28 49 6d 6d 65 64 6c | 61 62 20 5f 2c 5f 29 29 |E(Immedl|ab _,_))|
|00004520| 20 3d 20 74 72 75 65 0d | 20 20 7c 20 6e 65 65 64 | = true.| | need|
|00004530| 73 5f 61 5f 70 63 70 74 | 72 28 5f 2c 4c 4f 41 44 |s_a_pcpt|r(_,LOAD|
|00004540| 28 5f 2c 5f 2c 49 6d 6d | 65 64 6c 61 62 20 5f 2c |(_,_,Imm|edlab _,|
|00004550| 5f 29 29 20 3d 20 74 72 | 75 65 0d 20 20 7c 20 6e |_)) = tr|ue. | n|
|00004560| 65 65 64 73 5f 61 5f 70 | 63 70 74 72 28 5f 2c 53 |eeds_a_p|cptr(_,S|
|00004570| 54 4f 52 45 28 5f 2c 5f | 2c 49 6d 6d 65 64 6c 61 |TORE(_,_|,Immedla|
|00004580| 62 20 5f 2c 5f 29 29 20 | 3d 20 74 72 75 65 0d 20 |b _,_)) |= true. |
|00004590| 20 7c 20 6e 65 65 64 73 | 5f 61 5f 70 63 70 74 72 | | needs|_a_pcptr|
|000045a0| 28 5f 2c 53 4c 4c 28 49 | 6d 6d 65 64 6c 61 62 20 |(_,SLL(I|mmedlab |
|000045b0| 5f 2c 5f 2c 5f 29 29 20 | 3d 20 74 72 75 65 0d 20 |_,_,_)) |= true. |
|000045c0| 20 7c 20 6e 65 65 64 73 | 5f 61 5f 70 63 70 74 72 | | needs|_a_pcptr|
|000045d0| 28 5f 2c 53 52 41 28 49 | 6d 6d 65 64 6c 61 62 20 |(_,SRA(I|mmedlab |
|000045e0| 5f 2c 5f 2c 5f 29 29 20 | 3d 20 74 72 75 65 0d 20 |_,_,_)) |= true. |
|000045f0| 20 7c 20 6e 65 65 64 73 | 5f 61 5f 70 63 70 74 72 | | needs|_a_pcptr|
|00004600| 28 31 2c 20 42 45 51 20 | 5f 29 20 3d 20 66 61 6c |(1, BEQ |_) = fal|
|00004610| 73 65 20 20 28 2a 20 73 | 6d 61 6c 6c 20 42 45 51 |se (* s|mall BEQ|
|00004620| 27 73 20 64 6f 6e 74 20 | 6e 65 65 64 20 70 63 70 |'s dont |need pcp|
|00004630| 74 72 20 2a 29 0d 20 20 | 7c 20 6e 65 65 64 73 5f |tr *). || needs_|
|00004640| 61 5f 70 63 70 74 72 28 | 5f 2c 20 42 45 51 20 5f |a_pcptr(|_, BEQ _|
|00004650| 29 20 3d 20 74 72 75 65 | 20 20 20 28 2a 20 62 75 |) = true| (* bu|
|00004660| 74 20 6c 61 72 67 65 20 | 6f 6e 65 73 20 64 6f 20 |t large |ones do |
|00004670| 2a 29 0d 20 20 7c 20 6e | 65 65 64 73 5f 61 5f 70 |*). | n|eeds_a_p|
|00004680| 63 70 74 72 28 31 2c 20 | 42 43 4f 50 31 20 5f 29 |cptr(1, |BCOP1 _)|
|00004690| 20 3d 20 66 61 6c 73 65 | 20 20 28 2a 20 73 6d 61 | = false| (* sma|
|000046a0| 6c 6c 20 42 43 4f 50 31 | 27 73 20 64 6f 6e 74 20 |ll BCOP1|'s dont |
|000046b0| 6e 65 65 64 20 70 63 70 | 74 72 20 2a 29 0d 20 20 |need pcp|tr *). |
|000046c0| 7c 20 6e 65 65 64 73 5f | 61 5f 70 63 70 74 72 28 || needs_|a_pcptr(|
|000046d0| 5f 2c 20 42 43 4f 50 31 | 20 5f 29 20 3d 20 74 72 |_, BCOP1| _) = tr|
|000046e0| 75 65 20 20 20 28 2a 20 | 62 75 74 20 6c 61 72 67 |ue (* |but larg|
|000046f0| 65 20 6f 6e 65 73 20 64 | 6f 20 2a 29 0d 20 20 7c |e ones d|o *). ||
|00004700| 20 6e 65 65 64 73 5f 61 | 5f 70 63 70 74 72 20 5f | needs_a|_pcptr _|
|00004710| 20 3d 20 66 61 6c 73 65 | 0d 40 0d 43 72 65 61 74 | = false|.@.Creat|
|00004720| 69 6e 67 20 74 68 65 20 | 70 72 6f 67 72 61 6d 20 |ing the |program |
|00004730| 63 6f 75 6e 74 65 72 20 | 70 6f 69 6e 74 65 72 20 |counter |pointer |
|00004740| 6f 6e 63 65 2c 20 77 69 | 74 68 20 61 20 5b 5b 62 |once, wi|th a [[b|
|00004750| 6c 74 7a 61 6c 5d 5d 2c | 20 69 73 20 6e 6f 74 0d |ltzal]],| is not.|
|00004760| 65 6e 6f 75 67 68 3b 20 | 77 65 20 68 61 76 65 20 |enough; |we have |
|00004770| 74 6f 20 69 6e 76 61 6c | 69 64 61 74 65 20 74 68 |to inval|idate th|
|00004780| 65 20 70 72 6f 67 72 61 | 6d 20 63 6f 75 6e 74 65 |e progra|m counte|
|00004790| 72 20 70 6f 69 6e 74 65 | 72 20 61 74 20 65 76 65 |r pointe|r at eve|
|000047a0| 72 79 0d 6c 61 62 65 6c | 2c 20 73 69 6e 63 65 20 |ry.label|, since |
|000047b0| 63 6f 6e 74 72 6f 6c 20 | 63 6f 75 6c 64 20 61 72 |control |could ar|
|000047c0| 72 69 76 65 20 61 74 20 | 74 68 65 20 6c 61 62 65 |rive at |the labe|
|000047d0| 6c 20 66 72 6f 6d 20 47 | 6f 64 20 6b 6e 6f 77 73 |l from G|od knows|
|000047e0| 20 77 68 65 72 65 2c 20 | 61 6e 64 0d 74 68 65 72 | where, |and.ther|
|000047f0| 65 66 6f 72 65 20 77 65 | 20 64 6f 6e 27 74 20 6b |efore we| don't k|
|00004800| 6e 6f 77 20 77 68 61 74 | 20 74 68 65 20 70 72 6f |now what| the pro|
|00004810| 67 72 61 6d 20 63 6f 75 | 6e 74 65 72 20 70 6f 69 |gram cou|nter poi|
|00004820| 6e 74 65 72 20 69 73 2e | 0d 0d 57 65 20 75 73 65 |nter is.|..We use|
|00004830| 20 74 68 65 20 66 75 6e | 63 74 69 6f 6e 20 5b 5b | the fun|ction [[|
|00004840| 6d 61 6b 65 70 63 70 74 | 72 5d 5d 20 74 6f 20 63 |makepcpt|r]] to c|
|00004850| 72 65 61 74 65 20 61 20 | 6e 65 77 20 70 72 6f 67 |reate a |new prog|
|00004860| 72 61 6d 20 63 6f 75 6e | 74 65 72 20 70 6f 69 6e |ram coun|ter poin|
|00004870| 74 65 72 0d 60 60 6f 6e | 20 74 68 65 20 66 6c 79 |ter.``on| the fly|
|00004880| 27 27 20 77 68 69 6c 65 | 20 67 65 6e 65 72 61 74 |'' while| generat|
|00004890| 69 6e 67 20 63 6f 64 65 | 20 66 6f 72 20 6f 74 68 |ing code| for oth|
|000048a0| 65 72 20 5b 5b 69 6e 73 | 74 72 73 5d 5d 2e 0d 28 |er [[ins|trs]]..(|
|000048b0| 49 20 63 68 6f 73 65 20 | 6e 6f 74 20 74 6f 20 63 |I chose |not to c|
|000048c0| 72 65 61 74 65 20 61 20 | 73 70 65 63 69 61 6c 20 |reate a |special |
|000048d0| 5b 5b 69 6e 73 74 72 5d | 5d 20 66 6f 72 20 5b 5b |[[instr]|] for [[|
|000048e0| 62 6c 74 7a 61 6c 5d 5d | 2c 20 77 68 69 63 68 20 |bltzal]]|, which |
|000048f0| 49 0d 63 6f 75 6c 64 20 | 68 61 76 65 20 69 6e 73 |I.could |have ins|
|00004900| 65 72 74 65 64 20 61 74 | 20 61 70 70 72 6f 70 72 |erted at| appropr|
|00004910| 69 61 74 65 20 70 6f 69 | 6e 74 73 20 69 6e 20 74 |iate poi|nts in t|
|00004920| 68 65 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 20 73 |he instr|uction s|
|00004930| 74 72 65 61 6d 2e 29 0d | 54 6f 20 74 72 79 20 61 |tream.).|To try a|
|00004940| 6e 64 20 66 69 6e 64 20 | 61 6e 20 6f 64 64 20 62 |nd find |an odd b|
|00004950| 75 67 2c 20 49 27 6d 20 | 61 64 64 69 6e 67 20 6e |ug, I'm |adding n|
|00004960| 6f 2d 6f 70 73 20 61 66 | 74 65 72 20 65 61 63 68 |o-ops af|ter each|
|00004970| 20 5b 5b 62 6c 74 7a 61 | 6c 5d 5d 2e 0d 49 20 64 | [[bltza|l]]..I d|
|00004980| 6f 6e 27 74 20 72 65 61 | 6c 6c 79 20 62 65 6c 69 |on't rea|lly beli|
|00004990| 65 76 65 20 74 68 65 79 | 27 72 65 20 6e 65 63 65 |eve they|'re nece|
|000049a0| 73 73 61 72 79 2e 0d 0d | 54 68 65 20 66 75 6e 63 |ssary...|The func|
|000049b0| 74 69 6f 6e 20 5b 5b 67 | 65 6e 5d 5d 2c 20 77 68 |tion [[g|en]], wh|
|000049c0| 69 63 68 20 67 65 6e 65 | 72 61 74 65 73 20 74 68 |ich gene|rates th|
|000049d0| 65 20 69 6e 73 74 72 75 | 63 74 69 6f 6e 73 20 28 |e instru|ctions (|
|000049e0| 6f 72 20 63 6f 6d 70 75 | 74 65 73 0d 74 68 65 69 |or compu|tes.thei|
|000049f0| 72 20 73 69 7a 65 29 2c | 20 74 61 6b 65 73 20 74 |r size),| takes t|
|00004a00| 68 72 65 65 20 61 72 67 | 75 6d 65 6e 74 73 2e 0d |hree arg|uments..|
|00004a10| 54 68 69 72 64 3a 20 74 | 68 65 20 6c 69 73 74 20 |Third: t|he list |
|00004a20| 6f 66 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 73 20 |of instr|uctions |
|00004a30| 74 6f 20 62 65 20 67 65 | 6e 65 72 61 74 65 64 20 |to be ge|nerated |
|00004a40| 28 70 61 69 72 65 64 20 | 77 69 74 68 20 70 6f 69 |(paired |with poi|
|00004a50| 6e 74 65 72 73 0d 74 6f | 20 74 68 65 69 72 20 73 |nters.to| their s|
|00004a60| 69 7a 65 73 29 3b 20 66 | 69 72 73 74 3a 20 74 68 |izes); f|irst: th|
|00004a70| 65 20 70 6f 73 69 74 69 | 6f 6e 20 28 69 6e 20 77 |e positi|on (in w|
|00004a80| 6f 72 64 73 29 20 61 74 | 20 77 68 69 63 68 20 74 |ords) at| which t|
|00004a90| 6f 20 67 65 6e 65 72 61 | 74 65 20 0d 74 68 6f 73 |o genera|te .thos|
|00004aa0| 65 20 69 6e 73 74 72 75 | 63 74 69 6f 6e 73 3b 20 |e instru|ctions; |
|00004ab0| 20 73 65 63 6f 6e 64 3a | 20 74 68 65 20 63 75 72 | second:| the cur|
|00004ac0| 72 65 6e 74 20 76 61 6c | 75 65 20 6f 66 20 74 68 |rent val|ue of th|
|00004ad0| 65 20 70 72 6f 67 72 61 | 6d 20 63 6f 75 6e 74 65 |e progra|m counte|
|00004ae0| 72 0d 70 6f 69 6e 74 65 | 72 20 28 72 65 67 69 73 |r.pointe|r (regis|
|00004af0| 74 65 72 7e 33 31 29 2c | 20 69 66 20 6b 6e 6f 77 |ter~31),| if know|
|00004b00| 6e 2e 0d 0d 54 68 65 20 | 6d 75 74 75 61 6c 20 72 |n...The |mutual r|
|00004b10| 65 63 75 72 73 69 6f 6e | 20 62 65 74 77 65 65 6e |ecursion| between|
|00004b20| 20 5b 5b 67 65 6e 5d 5d | 20 61 6e 64 20 5b 5b 6d | [[gen]]| and [[m|
|00004b30| 61 6b 65 70 63 70 74 72 | 5d 5d 20 6d 61 69 6e 74 |akepcptr|]] maint|
|00004b40| 61 69 6e 73 0d 74 68 65 | 20 70 72 6f 67 72 61 6d |ains.the| program|
|00004b50| 20 63 6f 75 6e 74 65 72 | 20 70 6f 69 6e 74 65 72 | counter| pointer|
|00004b60| 2e 0d 5b 5b 67 65 6e 5d | 5d 20 69 6e 76 61 6c 69 |..[[gen]|] invali|
|00004b70| 64 61 74 65 73 20 69 74 | 20 61 74 20 6c 61 62 65 |dates it| at labe|
|00004b80| 6c 73 2c 20 61 6e 64 20 | 63 61 6c 6c 73 20 5b 5b |ls, and |calls [[|
|00004b90| 6d 61 6b 65 70 63 70 74 | 72 5d 5d 20 74 6f 20 63 |makepcpt|r]] to c|
|00004ba0| 72 65 61 74 65 20 61 20 | 76 61 6c 69 64 0d 6f 6e |reate a |valid.on|
|00004bb0| 65 20 77 68 65 6e 20 6e | 65 63 65 73 73 61 72 79 |e when n|ecessary|
|00004bc0| 20 28 61 73 20 64 65 74 | 65 72 6d 69 6e 65 64 20 | (as det|ermined |
|00004bd0| 62 79 20 5b 5b 6e 65 65 | 64 73 5f 61 5f 70 63 70 |by [[nee|ds_a_pcp|
|00004be0| 74 72 5d 5d 29 2e 0d 3c | 3c 73 69 6e 67 6c 65 20 |tr]])..<|<single |
|00004bf0| 70 61 73 73 3e 3e 3d 0d | 66 75 6e 20 70 61 73 73 |pass>>=.|fun pass|
|00004c00| 20 65 6d 69 74 5f 6e 6f | 77 20 3d 0d 6c 65 74 20 | emit_no|w =.let |
|00004c10| 66 75 6e 20 6d 61 6b 65 | 70 63 70 74 72 28 69 2c |fun make|pcptr(i,|
|00004c20| 78 29 20 3d 20 0d 20 20 | 20 20 20 20 20 20 20 28 |x) = . | (|
|00004c30| 2a 20 6d 61 79 20 6e 65 | 65 64 20 74 6f 20 65 6d |* may ne|ed to em|
|00004c40| 69 74 20 4e 4f 50 20 66 | 6f 72 20 64 65 6c 61 79 |it NOP f|or delay|
|00004c50| 20 73 6c 6f 74 20 69 66 | 20 6e 65 78 74 20 69 6e | slot if| next in|
|00004c60| 73 74 72 20 69 73 20 62 | 72 61 6e 63 68 20 2a 29 |str is b|ranch *)|
|00004c70| 0d 20 20 6c 65 74 20 76 | 61 6c 20 73 69 7a 65 20 |. let v|al size |
|00004c80| 3d 20 63 61 73 65 20 78 | 20 6f 66 20 28 28 5f 2c |= case x| of ((_,|
|00004c90| 42 45 51 20 5f 29 3a 3a | 72 65 73 74 29 20 3d 3e |BEQ _)::|rest) =>|
|00004ca0| 20 32 20 0d 09 09 09 20 | 7c 20 28 28 5f 2c 42 43 | 2 .... || ((_,BC|
|00004cb0| 4f 50 31 20 5f 29 3a 3a | 72 65 73 74 29 20 3d 3e |OP1 _)::|rest) =>|
|00004cc0| 20 32 20 0d 09 09 09 20 | 7c 20 5f 20 3d 3e 20 31 | 2 .... || _ => 1|
|00004cd0| 0d 20 20 69 6e 20 20 69 | 66 20 65 6d 69 74 5f 6e |. in i|f emit_n|
|00004ce0| 6f 77 20 74 68 65 6e 20 | 28 65 6d 69 74 28 4f 70 |ow then |(emit(Op|
|00004cf0| 63 6f 64 65 73 2e 62 6c | 74 7a 61 6c 28 30 2c 30 |codes.bl|tzal(0,0|
|00004d00| 29 29 3b 0d 09 09 09 69 | 66 20 73 69 7a 65 3d 32 |));....i|f size=2|
|00004d10| 20 74 68 65 6e 20 65 6d | 69 74 28 4f 70 63 6f 64 | then em|it(Opcod|
|00004d20| 65 73 2e 61 64 64 28 30 | 2c 30 2c 30 29 29 20 65 |es.add(0|,0,0)) e|
|00004d30| 6c 73 65 20 28 29 29 0d | 09 09 20 20 65 6c 73 65 |lse ()).|.. else|
|00004d40| 20 28 29 3b 0d 20 20 20 | 20 20 20 67 65 6e 28 69 | ();. | gen(i|
|00004d50| 2b 73 69 7a 65 2c 20 53 | 4f 4d 45 20 28 69 2b 32 |+size, S|OME (i+2|
|00004d60| 29 2c 20 78 29 0d 20 20 | 65 6e 64 0d 61 6e 64 20 |), x). |end.and |
|00004d70| 67 65 6e 28 69 2c 5f 2c | 6e 69 6c 29 20 3d 20 69 |gen(i,_,|nil) = i|
|00004d80| 0d 20 20 7c 20 67 65 6e | 28 69 2c 20 5f 2c 20 28 |. | gen|(i, _, (|
|00004d90| 5f 2c 44 45 46 49 4e 45 | 20 6c 61 62 29 20 3a 3a |_,DEFINE| lab) ::|
|00004da0| 20 72 65 73 74 29 20 3d | 20 28 6c 61 62 20 3a 3d | rest) =| (lab :=|
|00004db0| 20 69 3b 20 67 65 6e 28 | 69 2c 4e 4f 4e 45 2c 20 | i; gen(|i,NONE, |
|00004dc0| 72 65 73 74 29 29 0d 20 | 20 20 20 20 20 20 20 20 |rest)). | |
|00004dd0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 28 | | (|
|00004de0| 2a 20 69 6e 76 61 6c 69 | 64 61 74 65 20 74 68 65 |* invali|date the|
|00004df0| 20 70 63 20 70 6f 69 6e | 74 65 72 20 61 74 20 6c | pc poin|ter at l|
|00004e00| 61 62 65 6c 73 20 2a 29 | 0d 20 20 28 2a 20 6d 61 |abels *)|. (* ma|
|00004e10| 79 20 77 61 6e 74 20 74 | 6f 20 64 6f 20 73 70 65 |y want t|o do spe|
|00004e20| 63 69 61 6c 20 66 69 64 | 64 6c 69 6e 67 20 77 69 |cial fid|dling wi|
|00004e30| 74 68 20 4e 4f 50 73 20 | 2a 29 0d 20 20 7c 20 67 |th NOPs |*). | g|
|00004e40| 65 6e 28 70 6f 73 2c 20 | 70 63 70 74 72 2c 20 78 |en(pos, |pcptr, x|
|00004e50| 20 61 73 20 28 28 73 69 | 7a 65 72 65 66 20 61 73 | as ((si|zeref as|
|00004e60| 20 72 65 66 20 73 69 7a | 65 2c 20 69 6e 73 74 29 | ref siz|e, inst)|
|00004e70| 20 3a 3a 20 72 65 73 74 | 29 29 20 3d 0d 20 20 20 | :: rest|)) =. |
|00004e80| 20 20 20 20 69 66 20 28 | 70 63 70 74 72 3d 4e 4f | if (|pcptr=NO|
|00004e90| 4e 45 20 61 6e 64 61 6c | 73 6f 20 6e 65 65 64 73 |NE andal|so needs|
|00004ea0| 5f 61 5f 70 63 70 74 72 | 28 73 69 7a 65 2c 20 69 |_a_pcptr|(size, i|
|00004eb0| 6e 73 74 29 29 20 74 68 | 65 6e 20 6d 61 6b 65 70 |nst)) th|en makep|
|00004ec0| 63 70 74 72 28 70 6f 73 | 2c 78 29 0d 20 20 20 20 |cptr(pos|,x). |
|00004ed0| 20 20 20 65 6c 73 65 20 | 69 66 20 65 6d 69 74 5f | else |if emit_|
|00004ee0| 6e 6f 77 0d 09 20 20 20 | 20 74 68 65 6e 0d 09 09 |now.. | then...|
|00004ef0| 3c 3c 65 6d 69 74 20 4d | 49 50 53 20 69 6e 73 74 |<<emit M|IPS inst|
|00004f00| 72 75 63 74 69 6f 6e 73 | 3e 3e 0d 09 20 20 20 20 |ructions|>>.. |
|00004f10| 65 6c 73 65 0d 20 20 20 | 20 20 20 20 20 20 20 20 |else. | |
|00004f20| 20 20 20 20 20 3c 3c 63 | 6f 6d 70 75 74 65 20 70 | <<c|ompute p|
|00004f30| 6f 73 69 74 69 6f 6e 73 | 3e 3e 0d 69 6e 20 20 67 |ositions|>>.in g|
|00004f40| 65 6e 0d 65 6e 64 0d 0d | 40 20 5c 73 75 62 73 65 |en.end..|@ \subse|
|00004f50| 63 74 69 6f 6e 7b 47 65 | 6e 65 72 61 74 69 6e 67 |ction{Ge|nerating|
|00004f60| 20 74 68 65 20 69 6e 73 | 74 72 75 63 74 69 6f 6e | the ins|truction|
|00004f70| 73 7d 0d 4e 6f 77 20 77 | 65 20 6e 65 65 64 20 74 |s}.Now w|e need t|
|00004f80| 6f 20 63 6f 6e 73 69 64 | 65 72 20 74 68 65 20 6e |o consid|er the n|
|00004f90| 69 74 74 79 2d 67 72 69 | 74 74 79 20 64 65 74 61 |itty-gri|tty deta|
|00004fa0| 69 6c 73 20 6f 66 20 6a | 75 73 74 20 77 68 61 74 |ils of j|ust what|
|00004fb0| 20 69 6e 73 74 72 75 63 | 74 69 6f 6e 73 0d 61 72 | instruc|tions.ar|
|00004fc0| 65 20 67 65 6e 65 72 61 | 74 65 64 20 66 6f 72 20 |e genera|ted for |
|00004fd0| 65 61 63 68 20 5b 5b 69 | 6e 73 74 72 5d 5d 2e 0d |each [[i|nstr]]..|
|00004fe0| 49 6e 20 20 65 61 72 6c | 79 20 70 61 73 73 65 73 |In earl|y passes|
|00004ff0| 2c 20 77 65 27 6c 6c 20 | 6a 75 73 74 20 6e 65 65 |, we'll |just nee|
|00005000| 64 20 74 6f 20 6b 6e 6f | 77 20 68 6f 77 20 6d 61 |d to kno|w how ma|
|00005010| 6e 79 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 73 20 |ny instr|uctions |
|00005020| 61 72 65 0d 72 65 71 75 | 69 72 65 64 20 28 61 6e |are.requ|ired (an|
|00005030| 64 20 74 68 61 74 20 6e | 75 6d 62 65 72 20 6d 61 |d that n|umber ma|
|00005040| 79 20 63 68 61 6e 67 65 | 20 66 72 6f 6d 20 70 61 |y change| from pa|
|00005050| 73 73 20 74 6f 20 70 61 | 73 73 2c 20 73 6f 20 69 |ss to pa|ss, so i|
|00005060| 74 20 6d 75 73 74 20 62 | 65 0d 72 65 63 6f 6d 70 |t must b|e.recomp|
|00005070| 75 74 65 64 29 2e 0d 49 | 6e 20 74 68 65 20 6c 61 |uted)..I|n the la|
|00005080| 73 74 20 70 61 73 73 2c | 20 74 68 65 20 73 69 7a |st pass,| the siz|
|00005090| 65 73 20 61 72 65 20 73 | 74 61 62 6c 65 20 28 62 |es are s|table (b|
|000050a0| 79 20 64 65 66 69 6e 69 | 74 69 6f 6e 29 2c 20 73 |y defini|tion), s|
|000050b0| 6f 20 77 65 20 63 61 6e | 20 6c 6f 6f 6b 0d 61 74 |o we can| look.at|
|000050c0| 20 74 68 65 20 73 69 7a | 65 73 20 74 6f 20 73 65 | the siz|es to se|
|000050d0| 65 20 77 68 61 74 20 69 | 6e 73 74 72 75 63 74 69 |e what i|nstructi|
|000050e0| 6f 6e 73 20 74 6f 20 67 | 65 6e 65 72 61 74 65 2e |ons to g|enerate.|
|000050f0| 0d 0d 57 65 27 6c 6c 20 | 63 6f 6e 73 69 64 65 72 |..We'll |consider|
|00005100| 20 74 68 65 20 5b 5b 69 | 6e 73 74 72 73 5d 5d 20 | the [[i|nstrs]] |
|00005110| 69 6e 20 67 72 6f 75 70 | 73 2c 20 62 75 74 20 66 |in group|s, but f|
|00005120| 69 72 73 74 2c 20 68 65 | 72 65 27 73 20 74 68 65 |irst, he|re's the|
|00005130| 0d 77 61 79 20 77 65 20 | 77 69 6c 6c 20 73 74 72 |.way we |will str|
|00005140| 75 63 74 75 72 65 20 74 | 68 69 6e 67 73 3a 0d 3c |ucture t|hings:.<|
|00005150| 3c 63 6f 6d 70 75 74 65 | 20 70 6f 73 69 74 69 6f |<compute| positio|
|00005160| 6e 73 3e 3e 3d 0d 6c 65 | 74 20 3c 3c 66 75 6e 63 |ns>>=.le|t <<func|
|00005170| 74 69 6f 6e 73 20 66 6f | 72 20 63 6f 6d 70 75 74 |tions fo|r comput|
|00005180| 69 6e 67 20 73 69 7a 65 | 73 3e 3e 0d 20 20 20 20 |ing size|s>>. |
|00005190| 76 61 6c 20 6e 65 77 73 | 69 7a 65 20 3d 20 63 61 |val news|ize = ca|
|000051a0| 73 65 20 69 6e 73 74 20 | 6f 66 0d 20 20 20 20 20 |se inst |of. |
|000051b0| 20 20 20 3c 3c 63 61 73 | 65 73 20 66 6f 72 20 73 | <<cas|es for s|
|000051c0| 69 7a 65 73 20 74 6f 20 | 62 65 20 63 6f 6d 70 75 |izes to |be compu|
|000051d0| 74 65 64 3e 3e 0d 69 6e | 20 20 69 66 20 6e 65 77 |ted>>.in| if new|
|000051e0| 73 69 7a 65 20 3e 20 73 | 69 7a 65 20 74 68 65 6e |size > s|ize then|
|000051f0| 20 73 69 7a 65 72 65 66 | 20 3a 3d 20 6e 65 77 73 | sizeref| := news|
|00005200| 69 7a 65 20 65 6c 73 65 | 20 28 29 3b 0d 20 20 20 |ize else| ();. |
|00005210| 20 67 65 6e 28 70 6f 73 | 2b 28 21 73 69 7a 65 72 | gen(pos|+(!sizer|
|00005220| 65 66 29 20 28 2a 20 42 | 55 47 53 20 2d 2d 20 77 |ef) (* B|UGS -- w|
|00005230| 61 73 20 70 6f 73 2b 73 | 69 7a 65 2a 29 2c 70 63 |as pos+s|ize*),pc|
|00005240| 70 74 72 2c 72 65 73 74 | 29 0d 65 6e 64 0d 3c 3c |ptr,rest|).end.<<|
|00005250| 65 6d 69 74 20 4d 49 50 | 53 20 69 6e 73 74 72 75 |emit MIP|S instru|
|00005260| 63 74 69 6f 6e 73 3e 3e | 3d 0d 6c 65 74 20 66 75 |ctions>>|=.let fu|
|00005270| 6e 20 67 65 6e 31 28 29 | 20 3d 20 67 65 6e 28 70 |n gen1()| = gen(p|
|00005280| 6f 73 2b 73 69 7a 65 2c | 70 63 70 74 72 2c 72 65 |os+size,|pcptr,re|
|00005290| 73 74 29 20 0d 20 20 20 | 20 20 20 20 20 20 20 20 |st) . | |
|000052a0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000052b0| 20 20 20 20 20 28 2a 20 | 67 65 6e 65 72 61 74 65 | (* |generate|
|000052c0| 20 74 68 65 20 72 65 73 | 74 20 6f 66 20 74 68 65 | the res|t of the|
|000052d0| 20 5b 5b 69 6e 73 74 72 | 5d 5d 73 20 2a 29 0d 20 | [[instr|]]s *). |
|000052e0| 20 20 20 6f 70 65 6e 20 | 42 69 74 73 0d 20 20 20 | open |Bits. |
|000052f0| 20 6f 70 65 6e 20 4f 70 | 63 6f 64 65 73 0d 20 20 | open Op|codes. |
|00005300| 20 20 3c 3c 64 65 63 6c | 61 72 65 20 72 65 73 65 | <<decl|are rese|
|00005310| 72 76 65 64 20 72 65 67 | 69 73 74 65 72 73 20 5b |rved reg|isters [|
|00005320| 5b 74 65 6d 70 72 65 67 | 5d 5d 20 61 6e 64 20 5b |[tempreg|]] and [|
|00005330| 5b 70 63 72 65 67 5d 5d | 3e 3e 0d 20 20 20 20 3c |[pcreg]]|>>. <|
|00005340| 3c 66 75 6e 63 74 69 6f | 6e 73 20 66 6f 72 20 65 |<functio|ns for e|
|00005350| 6d 69 74 74 69 6e 67 20 | 69 6e 73 74 72 75 63 74 |mitting |instruct|
|00005360| 69 6f 6e 73 3e 3e 0d 69 | 6e 20 20 63 61 73 65 20 |ions>>.i|n case |
|00005370| 69 6e 73 74 20 6f 66 0d | 20 20 20 20 3c 3c 63 61 |inst of.| <<ca|
|00005380| 73 65 73 20 6f 66 20 69 | 6e 73 74 72 75 63 74 69 |ses of i|nstructi|
|00005390| 6f 6e 73 20 74 6f 20 62 | 65 20 65 6d 69 74 74 65 |ons to b|e emitte|
|000053a0| 64 3e 3e 0d 65 6e 64 0d | 40 20 57 68 65 6e 20 77 |d>>.end.|@ When w|
|000053b0| 65 20 67 65 74 20 61 72 | 6f 75 6e 64 20 74 6f 20 |e get ar|ound to |
|000053c0| 67 65 6e 65 72 61 74 69 | 6e 67 20 63 6f 64 65 2c |generati|ng code,|
|000053d0| 20 77 65 20 6d 61 79 20 | 6e 65 65 64 20 74 6f 20 | we may |need to |
|000053e0| 75 73 65 20 61 20 74 65 | 6d 70 6f 72 61 72 79 0d |use a te|mporary.|
|000053f0| 72 65 67 69 73 74 65 72 | 2e 0d 46 6f 72 20 65 78 |register|..For ex|
|00005400| 61 6d 70 6c 65 2c 20 69 | 66 20 77 65 20 77 61 6e |ample, i|f we wan|
|00005410| 74 20 74 6f 20 6c 6f 61 | 64 20 69 6e 74 6f 20 61 |t to loa|d into a|
|00005420| 20 72 65 67 69 73 74 65 | 72 0d 61 6e 20 69 6d 6d | registe|r.an imm|
|00005430| 65 64 69 61 74 65 20 63 | 6f 6e 73 74 61 6e 74 20 |ediate c|onstant |
|00005440| 74 68 61 74 20 77 6f 6e | 27 74 20 66 69 74 0d 69 |that won|'t fit.i|
|00005450| 6e 74 6f 20 31 36 7e 62 | 69 74 73 2c 20 77 65 20 |nto 16~b|its, we |
|00005460| 77 69 6c 6c 20 68 61 76 | 65 20 74 6f 20 6c 6f 61 |will hav|e to loa|
|00005470| 64 20 74 68 65 20 68 69 | 67 68 2d 6f 72 64 65 72 |d the hi|gh-order|
|00005480| 20 70 61 72 74 20 6f 66 | 20 74 68 65 20 63 6f 6e | part of| the con|
|00005490| 73 74 61 6e 74 0d 77 69 | 74 68 20 5b 5b 6c 75 69 |stant.wi|th [[lui|
|000054a0| 5d 5d 2c 20 74 68 65 6e | 20 75 73 65 20 5b 5b 61 |]], then| use [[a|
|000054b0| 64 64 69 5d 5d 20 74 6f | 20 61 64 64 20 74 68 65 |ddi]] to| add the|
|000054c0| 6e 20 74 68 65 20 6c 6f | 77 2d 6f 72 64 65 72 20 |n the lo|w-order |
|000054d0| 70 61 72 74 2e 0d 54 68 | 65 20 4d 49 50 53 20 61 |part..Th|e MIPS a|
|000054e0| 73 73 65 6d 62 6c 65 72 | 20 68 61 73 20 61 20 73 |ssembler| has a s|
|000054f0| 69 6d 69 6c 61 72 20 70 | 72 6f 62 6c 65 6d 2c 20 |imilar p|roblem, |
|00005500| 61 6e 64 20 6f 6e 20 70 | 61 67 65 20 44 2d 32 20 |and on p|age D-2 |
|00005510| 6f 66 0d 74 68 65 20 4d | 49 50 53 20 62 6f 6f 6b |of.the M|IPS book|
|00005520| 20 77 65 20 6e 6f 74 69 | 63 65 20 74 68 61 74 20 | we noti|ce that |
|00005530| 72 65 67 69 73 74 65 72 | 7e 31 20 69 73 20 72 65 |register|~1 is re|
|00005540| 73 65 72 76 65 64 20 66 | 6f 72 20 74 68 65 20 75 |served f|or the u|
|00005550| 73 65 20 6f 66 20 74 68 | 65 0d 61 73 73 65 6d 62 |se of th|e.assemb|
|00005560| 6c 65 72 2e 0d 53 6f 20 | 77 65 20 64 6f 20 74 68 |ler..So |we do th|
|00005570| 65 20 73 61 6d 65 2e 0d | 0d 57 65 20 6e 65 65 64 |e same..|.We need|
|00005580| 20 74 6f 20 72 65 73 65 | 72 76 65 20 61 20 73 65 | to rese|rve a se|
|00005590| 63 6f 6e 64 20 72 65 67 | 69 73 74 65 72 20 66 6f |cond reg|ister fo|
|000055a0| 72 20 75 73 65 20 69 6e | 20 70 6f 69 6e 74 69 6e |r use in| pointin|
|000055b0| 67 20 74 6f 20 74 68 65 | 20 70 72 6f 67 72 61 6d |g to the| program|
|000055c0| 20 0d 63 6f 75 6e 74 65 | 72 2e 0d 57 65 20 77 69 | .counte|r..We wi|
|000055d0| 6c 6c 20 75 73 65 20 72 | 65 67 69 73 74 65 72 20 |ll use r|egister |
|000055e0| 33 31 20 62 65 63 61 75 | 73 65 20 74 68 65 20 5b |31 becau|se the [|
|000055f0| 5b 62 6c 74 7a 61 6c 5d | 5d 20 69 6e 73 74 72 75 |[bltzal]|] instru|
|00005600| 63 74 69 6f 6e 20 61 75 | 74 6f 6d 61 74 69 63 61 |ction au|tomatica|
|00005610| 6c 6c 79 0d 73 65 74 73 | 20 72 65 67 69 73 74 65 |lly.sets| registe|
|00005620| 72 20 33 31 20 74 6f 20 | 74 68 65 20 50 43 2e 0d |r 31 to |the PC..|
|00005630| 3c 3c 64 65 63 6c 61 72 | 65 20 72 65 73 65 72 76 |<<declar|e reserv|
|00005640| 65 64 20 72 65 67 69 73 | 74 65 72 73 20 5b 5b 74 |ed regis|ters [[t|
|00005650| 65 6d 70 72 65 67 5d 5d | 20 61 6e 64 20 5b 5b 70 |empreg]]| and [[p|
|00005660| 63 72 65 67 5d 5d 3e 3e | 3d 0d 76 61 6c 20 74 65 |creg]]>>|=.val te|
|00005670| 6d 70 72 65 67 20 3d 20 | 31 0d 76 61 6c 20 70 63 |mpreg = |1.val pc|
|00005680| 72 65 67 20 3d 20 33 31 | 0d 40 0d 42 65 66 6f 72 |reg = 31|.@.Befor|
|00005690| 65 20 73 68 6f 77 69 6e | 67 20 74 68 65 20 63 6f |e showin|g the co|
|000056a0| 64 65 20 66 6f 72 20 74 | 68 65 20 61 63 74 75 61 |de for t|he actua|
|000056b0| 6c 20 69 6e 73 74 72 75 | 63 74 69 6f 6e 73 2c 20 |l instru|ctions, |
|000056c0| 77 65 20 73 68 6f 75 6c | 64 0d 70 6f 69 6e 74 20 |we shoul|d.point |
|000056d0| 6f 75 74 20 74 68 61 74 | 0d 77 65 20 68 61 76 65 |out that|.we have|
|000056e0| 20 74 77 6f 20 64 69 66 | 66 65 72 65 6e 74 20 77 | two dif|ferent w|
|000056f0| 61 79 73 20 6f 66 20 65 | 6d 69 74 74 69 6e 67 20 |ays of e|mitting |
|00005700| 61 20 6c 6f 6e 67 20 77 | 6f 72 64 2e 0d 5b 5b 65 |a long w|ord..[[e|
|00005710| 6d 69 74 6c 6f 6e 67 5d | 5d 20 6a 75 73 74 20 73 |mitlong]|] just s|
|00005720| 70 6c 69 74 73 20 74 68 | 65 20 62 69 74 73 20 69 |plits th|e bits i|
|00005730| 6e 74 6f 20 74 77 6f 20 | 70 69 65 63 65 73 20 66 |nto two |pieces f|
|00005740| 6f 72 20 74 68 6f 73 65 | 20 63 61 73 65 73 0d 77 |or those| cases.w|
|00005750| 68 65 6e 20 69 74 27 73 | 20 64 65 73 69 72 61 62 |hen it's| desirab|
|00005760| 6c 65 20 74 6f 20 70 75 | 74 20 61 20 77 6f 72 64 |le to pu|t a word|
|00005770| 20 69 6e 74 6f 20 74 68 | 65 20 6d 65 6d 6f 72 79 | into th|e memory|
|00005780| 20 69 6d 61 67 65 2e 0d | 5b 5b 73 70 6c 69 74 5d | image..|[[split]|
|00005790| 5d 20 67 69 76 65 73 20 | 73 6f 6d 65 74 68 69 6e |] gives |somethin|
|000057a0| 67 20 74 68 61 74 20 77 | 69 6c 6c 20 6c 6f 61 64 |g that w|ill load|
|000057b0| 20 63 6f 72 72 65 63 74 | 6c 79 0d 77 68 65 6e 20 | correct|ly.when |
|000057c0| 74 68 65 20 68 69 67 68 | 2d 6f 72 64 65 72 20 70 |the high|-order p|
|000057d0| 69 65 63 65 20 69 73 20 | 6c 6f 61 64 65 64 20 69 |iece is |loaded i|
|000057e0| 6e 74 6f 20 61 20 68 69 | 67 68 2d 6f 72 64 65 72 |nto a hi|gh-order|
|000057f0| 20 68 61 6c 66 77 6f 72 | 64 0d 28 75 73 69 6e 67 | halfwor|d.(using|
|00005800| 20 5b 5b 6c 75 69 5d 5d | 29 2c 0d 61 6e 64 20 74 | [[lui]]|),.and t|
|00005810| 68 65 20 6c 6f 77 2d 6f | 72 64 65 72 20 70 69 65 |he low-o|rder pie|
|00005820| 63 65 20 69 73 20 73 69 | 67 6e 2d 65 78 74 65 6e |ce is si|gn-exten|
|00005830| 64 65 64 20 61 6e 64 20 | 74 68 65 6e 20 61 64 64 |ded and |then add|
|00005840| 65 64 20 74 6f 20 74 68 | 65 20 0d 68 69 67 68 2d |ed to th|e .high-|
|00005850| 6f 72 64 65 72 20 70 69 | 65 63 65 2e 0d 54 68 69 |order pi|ece..Thi|
|00005860| 73 20 69 73 20 74 68 65 | 20 77 61 79 20 77 65 20 |s is the| way we |
|00005870| 6c 6f 61 64 20 69 6d 6d | 65 64 69 61 74 65 20 63 |load imm|ediate c|
|00005880| 6f 6e 73 74 61 6e 74 73 | 20 6f 66 20 6d 6f 72 65 |onstants| of more|
|00005890| 20 74 68 61 6e 20 73 69 | 78 74 65 65 6e 20 62 69 | than si|xteen bi|
|000058a0| 74 73 2e 0d 49 74 20 69 | 73 20 61 6c 73 6f 20 75 |ts..It i|s also u|
|000058b0| 73 65 66 75 6c 20 66 6f | 72 20 67 65 6e 65 72 61 |seful fo|r genera|
|000058c0| 74 69 6e 67 20 6c 6f 61 | 64 20 6f 72 20 73 74 6f |ting loa|d or sto|
|000058d0| 72 65 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 73 20 |re instr|uctions |
|000058e0| 77 69 74 68 0d 6f 66 66 | 73 65 74 73 20 6f 66 20 |with.off|sets of |
|000058f0| 6d 6f 72 65 20 74 68 61 | 6e 20 73 69 78 74 65 65 |more tha|n sixtee|
|00005900| 6e 20 62 69 74 73 3a 20 | 77 65 20 5b 5b 6c 75 69 |n bits: |we [[lui|
|00005910| 5d 5d 20 74 68 65 20 5b | 5b 68 69 5d 5d 20 70 61 |]] the [|[hi]] pa|
|00005920| 72 74 20 61 6e 64 0d 61 | 64 64 20 69 74 20 74 6f |rt and.a|dd it to|
|00005930| 20 74 68 65 20 62 61 73 | 65 20 72 65 67 73 69 74 | the bas|e regsit|
|00005940| 65 72 2c 20 74 68 65 6e | 20 75 73 65 20 74 68 65 |er, then| use the|
|00005950| 20 5b 5b 6c 6f 5d 5d 20 | 70 61 72 74 20 61 73 20 | [[lo]] |part as |
|00005960| 61 6e 20 6f 66 66 73 65 | 74 2e 0d 3c 3c 66 75 6e |an offse|t..<<fun|
|00005970| 63 74 69 6f 6e 73 20 66 | 6f 72 20 65 6d 69 74 74 |ctions f|or emitt|
|00005980| 69 6e 67 20 69 6e 73 74 | 72 75 63 74 69 6f 6e 73 |ing inst|ructions|
|00005990| 3e 3e 3d 0d 66 75 6e 20 | 65 6d 69 74 6c 6f 6e 67 |>>=.fun |emitlong|
|000059a0| 20 69 20 3d 20 65 6d 69 | 74 28 72 73 68 69 66 74 | i = emi|t(rshift|
|000059b0| 28 69 2c 31 36 29 2c 20 | 61 6e 64 62 28 69 2c 36 |(i,16), |andb(i,6|
|000059c0| 35 35 33 35 29 29 0d 20 | 20 20 20 20 20 20 20 20 |5535)). | |
|000059d0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000059e0| 20 20 20 20 20 20 20 28 | 2a 20 65 6d 69 74 20 6f | (|* emit o|
|000059f0| 6e 65 20 6c 6f 6e 67 20 | 77 6f 72 64 20 28 6e 6f |ne long |word (no|
|00005a00| 20 73 69 67 6e 20 66 69 | 64 64 6c 69 6e 67 29 20 | sign fi|ddling) |
|00005a10| 2a 29 0d 66 75 6e 20 73 | 70 6c 69 74 20 69 20 3d |*).fun s|plit i =|
|00005a20| 20 6c 65 74 20 76 61 6c | 20 68 69 20 3d 20 72 73 | let val| hi = rs|
|00005a30| 68 69 66 74 28 69 2c 31 | 36 29 20 61 6e 64 20 6c |hift(i,1|6) and l|
|00005a40| 6f 20 3d 20 61 6e 64 62 | 28 69 2c 36 35 35 33 35 |o = andb|(i,65535|
|00005a50| 29 0d 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |). | |
|00005a60| 20 20 20 20 20 20 20 69 | 6e 20 69 66 20 6c 6f 3c | i|n if lo<|
|00005a70| 33 32 37 36 38 20 74 68 | 65 6e 20 28 68 69 2c 6c |32768 th|en (hi,l|
|00005a80| 6f 29 20 65 6c 73 65 20 | 28 68 69 2b 31 2c 20 6c |o) else |(hi+1, l|
|00005a90| 6f 2d 36 35 35 33 36 29 | 0d 20 20 20 20 20 20 20 |o-65536)|. |
|00005aa0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 65 6e 64 | | end|
|00005ab0| 0d 0d 40 20 57 65 20 62 | 65 67 69 6e 20 69 6d 70 |..@ We b|egin imp|
|00005ac0| 6c 65 6d 65 6e 74 69 6e | 67 20 5b 5b 69 6e 73 74 |lementin|g [[inst|
|00005ad0| 72 73 5d 5d 20 62 79 20 | 63 6f 6e 73 69 64 65 72 |rs]] by |consider|
|00005ae0| 69 6e 67 20 74 68 6f 73 | 65 20 74 68 61 74 20 65 |ing thos|e that e|
|00005af0| 6d 69 74 20 63 6f 6e 73 | 74 61 6e 74 73 2e 0d 53 |mit cons|tants..S|
|00005b00| 74 72 69 6e 67 20 63 6f | 6e 73 74 61 6e 74 73 20 |tring co|nstants |
|00005b10| 61 72 65 20 70 61 64 64 | 65 64 20 77 69 74 68 20 |are padd|ed with |
|00005b20| 6e 75 6c 6c 73 20 6f 75 | 74 20 74 6f 20 61 20 77 |nulls ou|t to a w|
|00005b30| 6f 72 64 20 62 6f 75 6e | 64 61 72 79 2e 0d 49 6e |ord boun|dary..In|
|00005b40| 74 65 67 65 72 20 63 6f | 6e 73 74 61 6e 74 73 20 |teger co|nstants |
|00005b50| 61 72 65 20 6a 75 73 74 | 20 65 6d 69 74 74 65 64 |are just| emitted|
|00005b60| 20 77 69 74 68 20 5b 5b | 65 6d 69 74 6c 6f 6e 67 | with [[|emitlong|
|00005b70| 5d 5d 2e 0d 3c 3c 63 61 | 73 65 73 20 66 6f 72 20 |]]..<<ca|ses for |
|00005b80| 73 69 7a 65 73 20 74 6f | 20 62 65 20 63 6f 6d 70 |sizes to| be comp|
|00005b90| 75 74 65 64 3e 3e 3d 0d | 20 20 53 54 52 49 4e 47 |uted>>=.| STRING|
|00005ba0| 43 4f 4e 53 54 20 73 20 | 3d 3e 20 49 6e 74 65 67 |CONST s |=> Integ|
|00005bb0| 65 72 2e 64 69 76 28 53 | 74 72 69 6e 67 2e 6c 65 |er.div(S|tring.le|
|00005bc0| 6e 67 74 68 28 73 29 2b | 33 2c 34 29 0d 7c 20 45 |ngth(s)+|3,4).| E|
|00005bd0| 4d 49 54 4c 4f 4e 47 20 | 5f 20 3d 3e 20 31 0d 3c |MITLONG |_ => 1.<|
|00005be0| 3c 63 61 73 65 73 20 6f | 66 20 69 6e 73 74 72 75 |<cases o|f instru|
|00005bf0| 63 74 69 6f 6e 73 20 74 | 6f 20 62 65 20 65 6d 69 |ctions t|o be emi|
|00005c00| 74 74 65 64 3e 3e 3d 0d | 20 20 53 54 52 49 4e 47 |tted>>=.| STRING|
|00005c10| 43 4f 4e 53 54 20 73 20 | 3d 3e 20 0d 20 20 20 20 |CONST s |=> . |
|00005c20| 20 20 20 20 6c 65 74 20 | 76 61 6c 20 73 27 20 3d | let |val s' =|
|00005c30| 20 73 20 5e 20 22 5c 30 | 30 30 5c 30 30 30 5c 30 | s ^ "\0|00\000\0|
|00005c40| 30 30 5c 30 30 30 22 0d | 20 20 20 20 20 20 20 20 |00\000".| |
|00005c50| 69 6e 20 20 67 65 6e 31 | 28 65 6d 69 74 5f 73 74 |in gen1|(emit_st|
|00005c60| 72 69 6e 67 20 28 34 2a | 73 69 7a 65 29 20 73 27 |ring (4*|size) s'|
|00005c70| 29 0d 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |). | |
|00005c80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00005c90| 20 20 20 20 20 20 20 20 | 28 2a 20 64 6f 65 73 6e | |(* doesn|
|00005ca0| 27 74 20 6b 6e 6f 77 20 | 42 69 67 20 76 73 20 4c |'t know |Big vs L|
|00005cb0| 69 74 74 6c 65 2d 45 6e | 64 69 61 6e 20 2a 29 0d |ittle-En|dian *).|
|00005cc0| 20 20 20 20 20 20 20 20 | 65 6e 64 0d 7c 20 45 4d | |end.| EM|
|00005cd0| 49 54 4c 4f 4e 47 20 69 | 20 3d 3e 20 67 65 6e 31 |ITLONG i| => gen1|
|00005ce0| 28 65 6d 69 74 6c 6f 6e | 67 20 69 29 0d 40 0d 4e |(emitlon|g i).@.N|
|00005cf0| 65 78 74 20 63 6f 6e 73 | 69 64 65 72 20 74 68 65 |ext cons|ider the|
|00005d00| 20 6c 61 62 65 6c 73 2e | 0d 41 20 5b 5b 44 45 46 | labels.|.A [[DEF|
|00005d10| 49 4e 45 5d 5d 20 73 68 | 6f 75 6c 64 20 6e 65 76 |INE]] sh|ould nev|
|00005d20| 65 72 20 72 65 61 63 68 | 20 74 68 69 73 20 66 61 |er reach| this fa|
|00005d30| 72 2c 20 61 6e 64 20 5b | 5b 45 4d 49 54 4c 41 42 |r, and [|[EMITLAB|
|00005d40| 5d 5d 20 69 73 20 61 6c | 6d 6f 73 74 20 6c 69 6b |]] is al|most lik|
|00005d50| 65 0d 61 6e 20 5b 5b 45 | 4d 49 54 4c 4f 4e 47 5d |e.an [[E|MITLONG]|
|00005d60| 5d 2e 0d 3c 3c 63 61 73 | 65 73 20 66 6f 72 20 73 |]..<<cas|es for s|
|00005d70| 69 7a 65 73 20 74 6f 20 | 62 65 20 63 6f 6d 70 75 |izes to |be compu|
|00005d80| 74 65 64 3e 3e 3d 0d 7c | 20 44 45 46 49 4e 45 20 |ted>>=.|| DEFINE |
|00005d90| 5f 20 3d 3e 20 45 72 72 | 6f 72 4d 73 67 2e 69 6d |_ => Err|orMsg.im|
|00005da0| 70 6f 73 73 69 62 6c 65 | 20 22 67 65 6e 65 72 61 |possible| "genera|
|00005db0| 74 65 20 63 6f 64 65 20 | 66 6f 72 20 44 45 46 49 |te code |for DEFI|
|00005dc0| 4e 45 20 69 6e 20 6d 69 | 70 73 63 6f 64 65 72 22 |NE in mi|pscoder"|
|00005dd0| 0d 7c 20 45 4d 49 54 4c | 41 42 20 5f 20 3d 3e 20 |.| EMITL|AB _ => |
|00005de0| 31 0d 3c 3c 63 61 73 65 | 73 20 6f 66 20 69 6e 73 |1.<<case|s of ins|
|00005df0| 74 72 75 63 74 69 6f 6e | 73 20 74 6f 20 62 65 20 |truction|s to be |
|00005e00| 65 6d 69 74 74 65 64 3e | 3e 3d 0d 7c 20 44 45 46 |emitted>|>=.| DEF|
|00005e10| 49 4e 45 20 5f 20 3d 3e | 20 67 65 6e 31 28 45 72 |INE _ =>| gen1(Er|
|00005e20| 72 6f 72 4d 73 67 2e 69 | 6d 70 6f 73 73 69 62 6c |rorMsg.i|mpossibl|
|00005e30| 65 20 22 67 65 6e 65 72 | 61 74 65 20 63 6f 64 65 |e "gener|ate code|
|00005e40| 20 66 6f 72 20 44 45 46 | 49 4e 45 20 69 6e 20 6d | for DEF|INE in m|
|00005e50| 69 70 73 63 6f 64 65 72 | 22 29 0d 7c 20 45 4d 49 |ipscoder|").| EMI|
|00005e60| 54 4c 41 42 28 69 2c 20 | 72 65 66 20 64 29 20 3d |TLAB(i, |ref d) =|
|00005e70| 3e 20 67 65 6e 31 28 65 | 6d 69 74 6c 6f 6e 67 28 |> gen1(e|mitlong(|
|00005e80| 28 64 2d 70 6f 73 29 2a | 34 2b 69 29 29 0d 40 0d |(d-pos)*|4+i)).@.|
|00005e90| 4e 6f 77 20 77 65 20 68 | 61 76 65 20 74 6f 20 73 |Now we h|ave to s|
|00005ea0| 74 61 72 74 20 77 6f 72 | 72 79 69 6e 67 20 61 62 |tart wor|rying ab|
|00005eb0| 6f 75 74 20 69 6e 73 74 | 72 75 63 74 69 6f 6e 73 |out inst|ructions|
|00005ec0| 20 77 69 74 68 20 5b 5b | 45 41 5d 5d 20 69 6e 20 | with [[|EA]] in |
|00005ed0| 74 68 65 6d 2e 0d 54 68 | 65 20 72 65 61 6c 20 64 |them..Th|e real d|
|00005ee0| 69 66 66 69 63 75 6c 74 | 79 20 74 68 65 73 65 20 |ifficult|y these |
|00005ef0| 74 68 69 6e 67 73 20 70 | 72 65 73 65 6e 74 20 69 |things p|resent i|
|00005f00| 73 20 74 68 61 74 20 74 | 68 65 79 20 6d 61 79 20 |s that t|hey may |
|00005f10| 68 61 76 65 20 61 6e 0d | 69 6d 6d 65 64 69 61 74 |have an.|immediat|
|00005f20| 65 20 6f 70 65 72 61 6e | 64 20 74 68 61 74 20 77 |e operan|d that w|
|00005f30| 6f 6e 27 74 20 66 69 74 | 20 69 6e 20 31 36 7e 62 |on't fit| in 16~b|
|00005f40| 69 74 73 2e 0d 53 6f 20 | 77 65 27 6c 6c 20 6e 65 |its..So |we'll ne|
|00005f50| 65 64 20 74 6f 20 67 65 | 74 20 74 68 69 73 20 6c |ed to ge|t this l|
|00005f60| 61 72 67 65 20 69 6d 6d | 65 64 69 61 74 65 20 6f |arge imm|ediate o|
|00005f70| 70 65 72 61 6e 64 20 69 | 6e 74 6f 20 61 20 72 65 |perand i|nto a re|
|00005f80| 67 69 73 74 65 72 2c 0d | 73 69 78 74 65 65 6e 20 |gister,.|sixteen |
|00005f90| 62 69 74 73 20 61 74 20 | 61 20 74 69 6d 65 2c 20 |bits at |a time, |
|00005fa0| 61 6e 64 20 74 68 65 6e | 20 64 6f 20 74 68 65 20 |and then| do the |
|00005fb0| 6f 70 65 72 61 74 69 6f | 6e 20 6f 6e 20 74 68 65 |operatio|n on the|
|00005fc0| 20 72 65 67 69 73 74 65 | 72 2e 0d 0d 53 69 6e 63 | registe|r...Sinc|
|00005fd0| 65 20 61 6c 6c 20 6f 66 | 20 74 68 65 20 61 72 69 |e all of| the ari|
|00005fe0| 74 68 6d 65 74 69 63 20 | 69 6e 73 74 72 75 63 74 |thmetic |instruct|
|00005ff0| 69 6f 6e 73 20 68 61 76 | 65 20 74 68 69 73 20 64 |ions hav|e this d|
|00006000| 69 66 66 69 63 75 6c 74 | 79 2c 20 61 6e 64 20 73 |ifficult|y, and s|
|00006010| 69 6e 63 65 0d 77 65 20 | 63 61 6e 20 75 73 65 20 |ince.we |can use |
|00006020| 74 68 65 6d 20 74 6f 20 | 69 6d 70 6c 65 6d 65 6e |them to |implemen|
|00006030| 74 20 74 68 65 20 6f 74 | 68 65 72 73 2c 20 77 65 |t the ot|hers, we|
|00006040| 27 6c 6c 20 73 74 61 72 | 74 20 77 69 74 68 20 74 |'ll star|t with t|
|00006050| 68 6f 73 65 20 61 6e 64 | 0d 63 61 74 63 68 20 75 |hose and|.catch u|
|00006060| 70 20 77 69 74 68 20 74 | 68 65 20 63 6f 6e 74 72 |p with t|he contr|
|00006070| 6f 6c 2d 66 6c 6f 77 20 | 69 6e 73 74 72 75 63 74 |ol-flow |instruct|
|00006080| 69 6f 6e 73 20 6c 61 74 | 65 72 2e 0d 40 20 5b 5b |ions lat|er..@ [[|
|00006090| 53 55 42 5d 5d 2c 20 5b | 5b 4d 55 4c 54 5d 5d 2c |SUB]], [|[MULT]],|
|000060a0| 20 5b 5b 44 49 56 5d 5d | 2c 20 61 6e 64 20 5b 5b | [[DIV]]|, and [[|
|000060b0| 4d 46 4c 4f 5d 5d 20 61 | 6c 6c 20 75 73 65 20 72 |MFLO]] a|ll use r|
|000060c0| 65 67 69 73 74 65 72 73 | 20 6f 6e 6c 79 2c 20 0d |egisters| only, .|
|000060d0| 73 6f 20 74 68 65 79 20 | 61 72 65 20 65 61 73 79 |so they |are easy|
|000060e0| 2e 0d 54 68 65 20 6f 74 | 68 65 72 20 61 72 69 74 |..The ot|her arit|
|000060f0| 68 6d 65 74 69 63 20 6f | 70 65 72 61 74 69 6f 6e |hmetic o|peration|
|00006100| 73 20 67 65 74 20 74 72 | 65 61 74 65 64 20 65 78 |s get tr|eated ex|
|00006110| 61 63 74 6c 79 20 74 68 | 65 20 73 61 6d 65 2c 20 |actly th|e same, |
|00006120| 73 6f 20 77 65 27 6c 6c | 0d 75 73 65 20 61 20 66 |so we'll|.use a f|
|00006130| 75 6e 63 74 69 6f 6e 20 | 74 6f 20 63 6f 6d 70 75 |unction |to compu|
|00006140| 74 65 20 74 68 65 20 73 | 69 7a 65 2e 0d 7b 5c 62 |te the s|ize..{\b|
|00006150| 66 20 6d 6f 76 65 20 74 | 68 69 73 20 74 6f 20 66 |f move t|his to f|
|00006160| 6f 6c 6c 6f 77 20 74 68 | 65 20 64 65 66 69 6e 69 |ollow th|e defini|
|00006170| 74 69 6f 6e 20 6f 66 20 | 5b 5b 61 72 69 74 68 5d |tion of |[[arith]|
|00006180| 5d 3f 7d 0d 3c 3c 63 61 | 73 65 73 20 66 6f 72 20 |]?}.<<ca|ses for |
|00006190| 73 69 7a 65 73 20 74 6f | 20 62 65 20 63 6f 6d 70 |sizes to| be comp|
|000061a0| 75 74 65 64 3e 3e 3d 0d | 7c 20 41 44 44 28 5f 2c |uted>>=.|| ADD(_,|
|000061b0| 20 65 61 2c 20 5f 29 20 | 3d 3e 20 65 61 73 69 7a | ea, _) |=> easiz|
|000061c0| 65 20 65 61 0d 7c 20 41 | 4e 44 28 5f 2c 20 65 61 |e ea.| A|ND(_, ea|
|000061d0| 2c 20 5f 29 20 3d 3e 20 | 65 61 73 69 7a 65 20 65 |, _) => |easize e|
|000061e0| 61 0d 7c 20 4f 52 20 28 | 5f 2c 20 65 61 2c 20 5f |a.| OR (|_, ea, _|
|000061f0| 29 20 3d 3e 20 65 61 73 | 69 7a 65 20 65 61 0d 7c |) => eas|ize ea.||
|00006200| 20 58 4f 52 28 5f 2c 20 | 65 61 2c 20 5f 29 20 3d | XOR(_, |ea, _) =|
|00006210| 3e 20 65 61 73 69 7a 65 | 20 65 61 0d 7c 20 53 55 |> easize| ea.| SU|
|00006220| 42 20 5f 20 3d 3e 20 31 | 0d 7c 20 44 49 56 20 28 |B _ => 1|.| DIV (|
|00006230| 5f 2c 5f 29 20 3d 3e 20 | 31 0d 7c 20 4d 55 4c 54 |_,_) => |1.| MULT|
|00006240| 20 28 5f 2c 5f 29 20 3d | 3e 20 31 20 0d 7c 20 4d | (_,_) =|> 1 .| M|
|00006250| 46 4c 4f 20 5f 20 3d 3e | 20 31 0d 7c 20 4d 46 48 |FLO _ =>| 1.| MFH|
|00006260| 49 20 5f 20 3d 3e 20 31 | 0d 40 20 52 65 67 69 73 |I _ => 1|.@ Regis|
|00006270| 74 65 72 20 6f 70 65 72 | 61 74 69 6f 6e 73 20 74 |ter oper|ations t|
|00006280| 61 6b 65 20 6f 6e 65 20 | 69 6e 73 74 72 75 63 74 |ake one |instruct|
|00006290| 69 6f 6e 2e 0d 49 6d 6d | 65 64 69 61 74 65 20 6f |ion..Imm|ediate o|
|000062a0| 70 65 72 61 74 69 6f 6e | 73 20 74 61 6b 65 20 6f |peration|s take o|
|000062b0| 6e 65 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 20 66 |ne instr|uction f|
|000062c0| 6f 72 20 31 36 7e 62 69 | 74 20 63 6f 6e 73 74 61 |or 16~bi|t consta|
|000062d0| 6e 74 73 2c 0d 61 6e 64 | 20 33 20 66 6f 72 20 6c |nts,.and| 3 for l|
|000062e0| 61 72 67 65 72 20 63 6f | 6e 73 74 61 6e 74 73 20 |arger co|nstants |
|000062f0| 28 73 69 6e 63 65 20 69 | 74 20 63 6f 73 74 73 20 |(since i|t costs |
|00006300| 74 77 6f 20 69 6e 73 74 | 72 75 63 74 69 6f 6e 73 |two inst|ructions|
|00006310| 20 74 6f 20 6c 6f 61 64 | 0d 61 20 62 69 67 20 69 | to load|.a big i|
|00006320| 6d 6d 65 64 69 61 74 65 | 20 63 6f 6e 73 74 61 6e |mmediate| constan|
|00006330| 74 20 69 6e 74 6f 20 61 | 20 72 65 67 69 73 74 65 |t into a| registe|
|00006340| 72 29 2e 0d 41 6e 20 69 | 6d 6d 65 64 69 61 74 65 |r)..An i|mmediate|
|00006350| 20 69 6e 73 74 72 75 63 | 74 69 6f 6e 20 77 69 74 | instruc|tion wit|
|00006360| 68 20 5b 5b 49 6d 6d 65 | 64 6c 61 62 20 6c 5d 5d |h [[Imme|dlab l]]|
|00006370| 20 6d 65 61 6e 73 20 74 | 68 61 74 20 74 68 65 20 | means t|hat the |
|00006380| 6f 70 65 72 61 6e 64 0d | 69 73 20 69 6e 74 65 6e |operand.|is inten|
|00006390| 64 65 64 20 74 6f 20 62 | 65 20 74 68 65 20 6d 61 |ded to b|e the ma|
|000063a0| 63 68 69 6e 65 20 61 64 | 64 72 65 73 73 20 61 73 |chine ad|dress as|
|000063b0| 73 6f 63 69 61 74 65 64 | 20 77 69 74 68 20 74 68 |sociated| with th|
|000063c0| 61 74 20 6c 61 62 65 6c | 2e 0d 54 6f 20 63 6f 6d |at label|..To com|
|000063d0| 70 75 74 65 20 74 68 61 | 74 20 61 64 64 72 65 73 |pute tha|t addres|
|000063e0| 73 2c 20 77 65 20 6e 65 | 65 64 20 74 6f 20 61 64 |s, we ne|ed to ad|
|000063f0| 64 20 0d 5b 5b 34 2a 28 | 6c 2d 70 63 70 74 72 29 |d .[[4*(|l-pcptr)|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.