asm.ms 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  1. .ft CW
  2. .ta 8n +8n +8n +8n +8n +8n +8n
  3. .ft
  4. .TL
  5. A Manual for the Plan 9 assembler
  6. .AU
  7. Rob Pike
  8. rob@plan9.bell-labs.com
  9. .SH
  10. Machines
  11. .PP
  12. There is an assembler for each of the MIPS, SPARC, Intel 386,
  13. Intel 960, AMD 29000, Motorola 68020 and 68000, Motorola Power PC, DEC Alpha, and Acorn ARM.
  14. The 68020 assembler,
  15. .CW 2a ,
  16. is the oldest and in many ways the prototype.
  17. The assemblers are really just variations of a single program:
  18. they share many properties such as left-to-right assignment order for
  19. instruction operands and the synthesis of macro instructions
  20. such as
  21. .CW MOVE
  22. to hide the peculiarities of the load and store structure of the machines.
  23. To keep things concrete, the first part of this manual is
  24. specifically about the 68020.
  25. At the end is a description of the differences among
  26. the other assemblers.
  27. .PP
  28. The document, ``How to Use the Plan 9 C Compiler'', by Rob Pike,
  29. is a prerequisite for this manual.
  30. .SH
  31. Registers
  32. .PP
  33. All pre-defined symbols in the assembler are upper-case.
  34. Data registers are
  35. .CW R0
  36. through
  37. .CW R7 ;
  38. address registers are
  39. .CW A0
  40. through
  41. .CW A7 ;
  42. floating-point registers are
  43. .CW F0
  44. through
  45. .CW F7 .
  46. .PP
  47. A pointer in
  48. .CW A6
  49. is used by the C compiler to point to data, enabling short addresses to
  50. be used more often.
  51. The value of
  52. .CW A6
  53. is constant and must be set during C program initialization
  54. to the address of the externally-defined symbol
  55. .CW a6base .
  56. .PP
  57. The following hardware registers are defined in the assembler; their
  58. meaning should be obvious given a 68020 manual:
  59. .CW CAAR ,
  60. .CW CACR ,
  61. .CW CCR ,
  62. .CW DFC ,
  63. .CW ISP ,
  64. .CW MSP ,
  65. .CW SFC ,
  66. .CW SR ,
  67. .CW USP ,
  68. and
  69. .CW VBR .
  70. .PP
  71. The assembler also defines several pseudo-registers that
  72. manipulate the stack:
  73. .CW FP ,
  74. .CW SP ,
  75. and
  76. .CW TOS .
  77. .CW FP
  78. is the frame pointer, so
  79. .CW 0(FP)
  80. is the first argument,
  81. .CW 4(FP)
  82. is the second, and so on.
  83. .CW SP
  84. is the local stack pointer, where automatic variables are held
  85. (SP is a pseudo-register only on the 68020);
  86. .CW 0(SP)
  87. is the first automatic, and so on as with
  88. .CW FP .
  89. Finally,
  90. .CW TOS
  91. is the top-of-stack register, used for pushing parameters to procedures,
  92. saving temporary values, and so on.
  93. .PP
  94. The assembler and loader track these pseudo-registers so
  95. the above statements are true regardless of what has been
  96. pushed on the hardware stack, pointed to by
  97. .CW A7 .
  98. The name
  99. .CW A7
  100. refers to the hardware stack pointer, but beware of mixed use of
  101. .CW A7
  102. and the above stack-related pseudo-registers, which will cause trouble.
  103. Note, too, that the
  104. .CW PEA
  105. instruction is observed by the loader to
  106. alter SP and thus will insert a corresponding pop before all returns.
  107. The assembler accepts a label-like name to be attached to
  108. .CW FP
  109. and
  110. .CW SP
  111. uses, such as
  112. .CW p+0(FP) ,
  113. to help document that
  114. .CW p
  115. is the first argument to a routine.
  116. The name goes in the symbol table but has no significance to the result
  117. of the program.
  118. .SH
  119. Referring to data
  120. .PP
  121. All external references must be made relative to some pseudo-register,
  122. either
  123. .CW PC
  124. (the virtual program counter) or
  125. .CW SB
  126. (the ``static base'' register).
  127. .CW PC
  128. counts instructions, not bytes of data.
  129. For example, to branch to the second following instruction, that is,
  130. to skip one instruction, one may write
  131. .P1
  132. BRA 2(PC)
  133. .P2
  134. Labels are also allowed, as in
  135. .P1
  136. BRA return
  137. NOP
  138. return:
  139. RTS
  140. .P2
  141. When using labels, there is no
  142. .CW (PC)
  143. annotation.
  144. .PP
  145. The pseudo-register
  146. .CW SB
  147. refers to the beginning of the address space of the program.
  148. Thus, references to global data and procedures are written as
  149. offsets to
  150. .CW SB ,
  151. as in
  152. .P1
  153. MOVL $array(SB), TOS
  154. .P2
  155. to push the address of a global array on the stack, or
  156. .P1
  157. MOVL array+4(SB), TOS
  158. .P2
  159. to push the second (4-byte) element of the array.
  160. Note the use of an offset; the complete list of addressing modes is given below.
  161. Similarly, subroutine calls must use
  162. .CW SB :
  163. .P1
  164. BSR exit(SB)
  165. .P2
  166. File-static variables have syntax
  167. .P1
  168. local<>+4(SB)
  169. .P2
  170. The
  171. .CW <>
  172. will be filled in at load time by a unique integer.
  173. .PP
  174. When a program starts, it must execute
  175. .P1
  176. MOVL $a6base(SB), A6
  177. .P2
  178. before accessing any global data.
  179. (On machines such as the MIPS and SPARC that cannot load a register
  180. in a single instruction, constants are loaded through the static base
  181. register. The loader recognizes code that initializes the static
  182. base register and treats it specially. You must be careful, however,
  183. not to load large constants on such machines when the static base
  184. register is not set up, such as early in interrupt routines.)
  185. .SH
  186. Expressions
  187. .PP
  188. Expressions are mostly what one might expect.
  189. Where an offset or a constant is expected,
  190. a primary expression with unary operators is allowed.
  191. A general C constant expression is allowed in parentheses.
  192. .PP
  193. Source files are preprocessed exactly as in the C compiler, so
  194. .CW #define
  195. and
  196. .CW #include
  197. work.
  198. .SH
  199. Addressing modes
  200. .PP
  201. The simple addressing modes are shared by all the assemblers.
  202. Here, for completeness, follows a table of all the 68020 addressing modes,
  203. since that machine has the richest set.
  204. In the table,
  205. .CW o
  206. is an offset, which if zero may be elided, and
  207. .CW d
  208. is a displacement, which is a constant between -128 and 127 inclusive.
  209. Many of the modes listed have the same name;
  210. scrutiny of the format will show what default is being applied.
  211. For instance, indexed mode with no address register supplied operates
  212. as though a zero-valued register were used.
  213. For "offset" read "displacement."
  214. For "\f(CW.s\fP" read one of
  215. .CW .L ,
  216. or
  217. .CW .W
  218. followed by
  219. .CW *1 ,
  220. .CW *2 ,
  221. .CW *4 ,
  222. or
  223. .CW *8
  224. to indicate the size and scaling of the data.
  225. .IP
  226. .TS
  227. l lfCW.
  228. data register R0
  229. address register A0
  230. floating-point register F0
  231. special names CAAR, CACR, etc.
  232. constant $con
  233. floating point constant $fcon
  234. external symbol name+o(SB)
  235. local symbol name<>+o(SB)
  236. automatic symbol name+o(SP)
  237. argument name+o(FP)
  238. address of external $name+o(SB)
  239. address of local $name<>+o(SB)
  240. indirect post-increment (A0)+
  241. indirect pre-decrement -(A0)
  242. indirect with offset o(A0)
  243. indexed with offset o()(R0.s)
  244. indexed with offset o(A0)(R0.s)
  245. external indexed name+o(SB)(R0.s)
  246. local indexed name<>+o(SB)(R0.s)
  247. automatic indexed name+o(SP)(R0.s)
  248. parameter indexed name+o(FP)(R0.s)
  249. offset indirect post-indexed d(o())(R0.s)
  250. offset indirect post-indexed d(o(A0))(R0.s)
  251. external indirect post-indexed d(name+o(SB))(R0.s)
  252. local indirect post-indexed d(name<>+o(SB))(R0.s)
  253. automatic indirect post-indexed d(name+o(SP))(R0.s)
  254. parameter indirect post-indexed d(name+o(FP))(R0.s)
  255. offset indirect pre-indexed d(o()(R0.s))
  256. offset indirect pre-indexed d(o(A0))
  257. offset indirect pre-indexed d(o(A0)(R0.s))
  258. external indirect pre-indexed d(name+o(SB))
  259. external indirect pre-indexed d(name+o(SB)(R0.s))
  260. local indirect pre-indexed d(name<>+o(SB))
  261. local indirect pre-indexed d(name<>+o(SB)(R0.s))
  262. automatic indirect pre-indexed d(name+o(SP))
  263. automatic indirect pre-indexed d(name+o(SP)(R0.s))
  264. parameter indirect pre-indexed d(name+o(FP))
  265. parameter indirect pre-indexed d(name+o(FP)(R0.s))
  266. .TE
  267. .in
  268. .SH
  269. Laying down data
  270. .PP
  271. Placing data in the instruction stream, say for interrupt vectors, is easy:
  272. the pseudo-instructions
  273. .CW LONG
  274. and
  275. .CW WORD
  276. (but not
  277. .CW BYTE )
  278. lay down the value of their single argument, of the appropriate size,
  279. as if it were an instruction:
  280. .P1
  281. LONG $12345
  282. .P2
  283. places the long 12345 (base 10)
  284. in the instruction stream.
  285. (On most machines,
  286. the only such operator is
  287. .CW WORD
  288. and it lays down 32-bit quantities.
  289. The 386 has all three:
  290. .CW LONG ,
  291. .CW WORD ,
  292. and
  293. .CW BYTE .
  294. The 960 has only one,
  295. .CW LONG .)
  296. .PP
  297. Placing information in the data section is more painful.
  298. The pseudo-instruction
  299. .CW DATA
  300. does the work, given two arguments: an address at which to place the item,
  301. including its size,
  302. and the value to place there. For example, to define a character array
  303. .CW array
  304. containing the characters
  305. .CW abc
  306. and a terminating null:
  307. .P1
  308. DATA array+0(SB)/1, $'a'
  309. DATA array+1(SB)/1, $'b'
  310. DATA array+2(SB)/1, $'c'
  311. GLOBL array(SB), $4
  312. .P2
  313. or
  314. .P1
  315. DATA array+0(SB)/4, $"abc\ez"
  316. GLOBL array(SB), $4
  317. .P2
  318. The
  319. .CW /1
  320. defines the number of bytes to define,
  321. .CW GLOBL
  322. makes the symbol global, and the
  323. .CW $4
  324. says how many bytes the symbol occupies.
  325. Uninitialized data is zeroed automatically.
  326. The character
  327. .CW \ez
  328. is equivalent to the C
  329. .CW \e0.
  330. The string in a
  331. .CW DATA
  332. statement may contain a maximum of eight bytes;
  333. build larger strings piecewise.
  334. Two pseudo-instructions,
  335. .CW DYNT
  336. and
  337. .CW INIT ,
  338. allow the (obsolete) Alef compilers to build dynamic type information during the load
  339. phase.
  340. The
  341. .CW DYNT
  342. pseudo-instruction has two forms:
  343. .P1
  344. DYNT , ALEF_SI_5+0(SB)
  345. DYNT ALEF_AS+0(SB), ALEF_SI_5+0(SB)
  346. .P2
  347. In the first form,
  348. .CW DYNT
  349. defines the symbol to be a small unique integer constant, chosen by the loader,
  350. which is some multiple of the word size. In the second form,
  351. .CW DYNT
  352. defines the second symbol in the same way,
  353. places the address of the most recently
  354. defined text symbol in the array specified by the first symbol at the
  355. index defined by the value of the second symbol,
  356. and then adjusts the size of the array accordingly.
  357. .PP
  358. The
  359. .CW INIT
  360. pseudo-instruction takes the same parameters as a
  361. .CW DATA
  362. statement. Its symbol is used as the base of an array and the
  363. data item is installed in the array at the offset specified by the most recent
  364. .CW DYNT
  365. pseudo-instruction.
  366. The size of the array is adjusted accordingly.
  367. The
  368. .CW DYNT
  369. and
  370. .CW INIT
  371. pseudo-instructions are not implemented on the 68020.
  372. .SH
  373. Defining a procedure
  374. .PP
  375. Entry points are defined by the pseudo-operation
  376. .CW TEXT ,
  377. which takes as arguments the name of the procedure (including the ubiquitous
  378. .CW (SB) )
  379. and the number of bytes of automatic storage to pre-allocate on the stack,
  380. which will usually be zero when writing assembly language programs.
  381. On machines with a link register, such as the MIPS and SPARC,
  382. the special value -4 instructs the loader to generate no PC save
  383. and restore instructions, even if the function is not a leaf.
  384. Here is a complete procedure that returns the sum
  385. of its two arguments:
  386. .P1
  387. TEXT sum(SB), $0
  388. MOVL arg1+0(FP), R0
  389. ADDL arg2+4(FP), R0
  390. RTS
  391. .P2
  392. An optional middle argument
  393. to the
  394. .CW TEXT
  395. pseudo-op is a bit field of options to the loader.
  396. Setting the 1 bit suspends profiling the function when profiling is enabled for the rest of
  397. the program.
  398. For example,
  399. .P1
  400. TEXT sum(SB), 1, $0
  401. MOVL arg1+0(FP), R0
  402. ADDL arg2+4(FP), R0
  403. RTS
  404. .P2
  405. will not be profiled; the first version above would be.
  406. Subroutines with peculiar state, such as system call routines,
  407. should not be profiled.
  408. .PP
  409. Setting the 2 bit allows multiple definitions of the same
  410. .CW TEXT
  411. symbol in a program; the loader will place only one such function in the image.
  412. It was emitted only by the Alef compilers.
  413. .PP
  414. Subroutines to be called from C should place their result in
  415. .CW R0 ,
  416. even if it is an address.
  417. Floating point values are returned in
  418. .CW F0 .
  419. Functions that return a structure to a C program
  420. receive as their first argument the address of the location to
  421. store the result;
  422. .CW R0
  423. is unused in the calling protocol for such procedures.
  424. A subroutine is responsible for saving its own registers,
  425. and therefore is free to use any registers without saving them (``caller saves'').
  426. .CW A6
  427. and
  428. .CW A7
  429. are the exceptions as described above.
  430. .SH
  431. When in doubt
  432. .PP
  433. If you get confused, try using the
  434. .CW -S
  435. option to
  436. .CW 2c
  437. and compiling a sample program.
  438. The standard output is valid input to the assembler.
  439. .SH
  440. Instructions
  441. .PP
  442. The instruction set of the assembler is not identical to that
  443. of the machine.
  444. It is chosen to match what the compiler generates, augmented
  445. slightly by specific needs of the operating system.
  446. For example,
  447. .CW 2a
  448. does not distinguish between the various forms of
  449. .CW MOVE
  450. instruction: move quick, move address, etc. Instead the context
  451. does the job. For example,
  452. .P1
  453. MOVL $1, R1
  454. MOVL A0, R2
  455. MOVW SR, R3
  456. .P2
  457. generates official
  458. .CW MOVEQ ,
  459. .CW MOVEA ,
  460. and
  461. .CW MOVESR
  462. instructions.
  463. A number of instructions do not have the syntax necessary to specify
  464. their entire capabilities. Notable examples are the bitfield
  465. instructions, the
  466. multiply and divide instructions, etc.
  467. For a complete set of generated instruction names (in
  468. .CW 2a
  469. notation, not Motorola's) see the file
  470. .CW /sys/src/cmd/2c/2.out.h .
  471. Despite its name, this file contains an enumeration of the
  472. instructions that appear in the intermediate files generated
  473. by the compiler, which correspond exactly to lines of assembly language.
  474. .PP
  475. The MC68000 assembler,
  476. .CW 1a ,
  477. is essentially the same, honoring the appropriate subset of the instructions
  478. and addressing modes.
  479. The definitions of these are, nonetheless, part of
  480. .CW 2.out.h .
  481. .SH
  482. Laying down instructions
  483. .PP
  484. The loader modifies the code produced by the assembler and compiler.
  485. It folds branches,
  486. copies short sequences of code to eliminate branches,
  487. and discards unreachable code.
  488. The first instruction of every function is assumed to be reachable.
  489. The pseudo-instruction
  490. .CW NOP ,
  491. which you may see in compiler output,
  492. means no instruction at all, rather than an instruction that does nothing.
  493. The loader discards all
  494. .CW NOP 's.
  495. .PP
  496. To generate a true
  497. .CW NOP
  498. instruction, or any other instruction not known to the assembler, use a
  499. .CW WORD
  500. pseudo-instruction.
  501. Such instructions on RISCs are not scheduled by the loader and must have
  502. their delay slots filled manually.
  503. .SH
  504. MIPS
  505. .PP
  506. The registers are only addressed by number:
  507. .CW R0
  508. through
  509. .CW R31 .
  510. .CW R29
  511. is the stack pointer;
  512. .CW R30
  513. is used as the static base pointer, the analogue of
  514. .CW A6
  515. on the 68020.
  516. Its value is the address of the global symbol
  517. .CW setR30(SB) .
  518. The register holding returned values from subroutines is
  519. .CW R1 .
  520. When a function is called, space for the first argument
  521. is reserved at
  522. .CW 0(FP)
  523. but in C (not Alef) the value is passed in
  524. .CW R1
  525. instead.
  526. .PP
  527. The loader uses
  528. .CW R28
  529. as a temporary. The system uses
  530. .CW R26
  531. and
  532. .CW R27
  533. as interrupt-time temporaries. Therefore none of these registers
  534. should be used in user code.
  535. .PP
  536. The control registers are not known to the assembler.
  537. Instead they are numbered registers
  538. .CW M0 ,
  539. .CW M1 ,
  540. etc.
  541. Use this trick to access, say,
  542. .CW STATUS :
  543. .P1
  544. #define STATUS 12
  545. MOVW M(STATUS), R1
  546. .P2
  547. .PP
  548. Floating point registers are called
  549. .CW F0
  550. through
  551. .CW F31 .
  552. By convention,
  553. .CW F24
  554. must be initialized to the value 0.0,
  555. .CW F26
  556. to 0.5,
  557. .CW F28
  558. to 1.0, and
  559. .CW F30
  560. to 2.0;
  561. this is done by the operating system.
  562. .PP
  563. The instructions and their syntax are different from those of the manufacturer's
  564. manual.
  565. There are no
  566. .CW lui
  567. and kin; instead there are
  568. .CW MOVW
  569. (move word),
  570. .CW MOVH
  571. (move halfword),
  572. and
  573. .CW MOVB
  574. (move byte) pseudo-instructions. If the operand is unsigned, the instructions
  575. are
  576. .CW MOVHU
  577. and
  578. .CW MOVBU .
  579. The order of operands is from left to right in dataflow order, just as
  580. on the 68020 but not as in MIPS documentation.
  581. This means that the
  582. .CW Bcond
  583. instructions are reversed with respect to the book; for example, a
  584. .CW va
  585. .CW BGTZ
  586. generates a MIPS
  587. .CW bltz
  588. instruction.
  589. .PP
  590. The assembler is for the R2000, R3000, and most of the R4000 and R6000 architectures.
  591. It understands the 64-bit instructions
  592. .CW MOVV ,
  593. .CW MOVVL ,
  594. .CW ADDV ,
  595. .CW ADDVU ,
  596. .CW SUBV ,
  597. .CW SUBVU ,
  598. .CW MULV ,
  599. .CW MULVU ,
  600. .CW DIVV ,
  601. .CW DIVVU ,
  602. .CW SLLV ,
  603. .CW SRLV ,
  604. and
  605. .CW SRAV .
  606. The assembler does not have any cache, load-linked, or store-conditional instructions.
  607. .PP
  608. Some assembler instructions are expanded into multiple instructions by the loader.
  609. For example the loader may convert the load of a 32 bit constant into an
  610. .CW lui
  611. followed by an
  612. .CW ori .
  613. .PP
  614. Assembler instructions should be laid out as if there
  615. were no load, branch, or floating point compare delay slots;
  616. the loader will rearrange\(em\f2schedule\f1\(emthe instructions
  617. to guarantee correctness and improve performance.
  618. The only exception is that the correct scheduling of instructions
  619. that use control registers varies from model to model of machine
  620. (and is often undocumented) so you should schedule such instructions
  621. by hand to guarantee correct behavior.
  622. The loader generates
  623. .P1
  624. NOR R0, R0, R0
  625. .P2
  626. when it needs a true no-op instruction.
  627. Use exactly this instruction when scheduling code manually;
  628. the loader recognizes it and schedules the code before it and after it independently. Also,
  629. .CW WORD
  630. pseudo-ops are scheduled like no-ops.
  631. .PP
  632. The
  633. .CW NOSCHED
  634. pseudo-op disables instruction scheduling
  635. (scheduling is enabled by default);
  636. .CW SCHED
  637. re-enables it.
  638. Branch folding, code copying, and dead code elimination are
  639. disabled for instructions that are not scheduled.
  640. .SH
  641. SPARC
  642. .PP
  643. Once you understand the Plan 9 model for the MIPS, the SPARC is familiar.
  644. Registers have numerical names only:
  645. .CW R0
  646. through
  647. .CW R31 .
  648. Forget about register windows: Plan 9 doesn't use them at all.
  649. The machine has 32 global registers, period.
  650. .CW R1
  651. [sic] is the stack pointer.
  652. .CW R2
  653. is the static base register, with value the address of
  654. .CW setSB(SB) .
  655. .CW R7
  656. is the return register and also the register holding the first
  657. argument to a C (not Alef) function, again with space reserved at
  658. .CW 0(FP) .
  659. .CW R14
  660. is the loader temporary.
  661. .PP
  662. Floating-point registers are exactly as on the MIPS.
  663. .PP
  664. The control registers are known by names such as
  665. .CW FSR .
  666. The instructions to access these registers are
  667. .CW MOVW
  668. instructions, for example
  669. .P1
  670. MOVW Y, R8
  671. .P2
  672. for the SPARC instruction
  673. .P1
  674. rdy %r8
  675. .P2
  676. .PP
  677. Move instructions are similar to those on the MIPS: pseudo-operations
  678. that turn into appropriate sequences of
  679. .CW sethi
  680. instructions, adds, etc.
  681. Instructions read from left to right. Because the arguments are
  682. flipped to
  683. .CW SUBCC ,
  684. the condition codes are not inverted as on the MIPS.
  685. .PP
  686. The syntax for the ASI stuff is, for example to move a word from ASI 2:
  687. .P1
  688. MOVW (R7, 2), R8
  689. .P2
  690. The syntax for double indexing is
  691. .P1
  692. MOVW (R7+R8), R9
  693. .P2
  694. .PP
  695. The SPARC's instruction scheduling is similar to the MIPS's.
  696. The official no-op instruction is:
  697. .P1
  698. ORN R0, R0, R0
  699. .P2
  700. .SH
  701. i960
  702. .PP
  703. Registers are numbered
  704. .CW R0
  705. through
  706. .CW R31 .
  707. Stack pointer is
  708. .CW R29 ;
  709. return register is
  710. .CW R4 ;
  711. static base is
  712. .CW R28 ;
  713. it is initialized to the address of
  714. .CW setSB(SB) .
  715. .CW R3
  716. must be zero; this should be done manually early in execution by
  717. .P1
  718. SUBO R3, R3
  719. .P2
  720. .CW R27
  721. is the loader temporary.
  722. .PP
  723. There is no support for floating point.
  724. .PP
  725. The Intel calling convention is not supported and cannot be used; use
  726. .CW BAL
  727. instead.
  728. Instructions are mostly as in the book. The major change is that
  729. .CW LOAD
  730. and
  731. .CW STORE
  732. are both called
  733. .CW MOV .
  734. The extension character for
  735. .CW MOV
  736. is as in the manual:
  737. .CW O
  738. for ordinal,
  739. .CW W
  740. for signed, etc.
  741. .SH
  742. i386
  743. .PP
  744. The assembler assumes 32-bit protected mode.
  745. The register names are
  746. .CW SP ,
  747. .CW AX ,
  748. .CW BX ,
  749. .CW CX ,
  750. .CW DX ,
  751. .CW BP ,
  752. .CW DI ,
  753. and
  754. .CW SI .
  755. The stack pointer (not a pseudo-register) is
  756. .CW SP
  757. and the return register is
  758. .CW AX .
  759. There is no physical frame pointer but, as for the MIPS,
  760. .CW FP
  761. is a pseudo-register that acts as
  762. a frame pointer.
  763. .PP
  764. Opcode names are mostly the same as those listed in the Intel manual
  765. with an
  766. .CW L ,
  767. .CW W ,
  768. or
  769. .CW B
  770. appended to identify 32-bit,
  771. 16-bit, and 8-bit operations.
  772. The exceptions are loads, stores, and conditionals.
  773. All load and store opcodes to and from general registers, special registers
  774. (such as
  775. .CW CR0,
  776. .CW CR3,
  777. .CW GDTR,
  778. .CW IDTR,
  779. .CW SS,
  780. .CW CS,
  781. .CW DS,
  782. .CW ES,
  783. .CW FS,
  784. and
  785. .CW GS )
  786. or memory are written
  787. as
  788. .P1
  789. MOV\f2x\fP src,dst
  790. .P2
  791. where
  792. .I x
  793. is
  794. .CW L ,
  795. .CW W ,
  796. or
  797. .CW B .
  798. Thus to get
  799. .CW AL
  800. use a
  801. .CW MOVB
  802. instruction. If you need to access
  803. .CW AH ,
  804. you must mention it explicitly in a
  805. .CW MOVB :
  806. .P1
  807. MOVB AH, BX
  808. .P2
  809. There are many examples of illegal moves, for example,
  810. .P1
  811. MOVB BP, DI
  812. .P2
  813. that the loader actually implements as pseudo-operations.
  814. .PP
  815. The names of conditions in all conditional instructions
  816. .CW J , (
  817. .CW SET )
  818. follow the conventions of the 68020 instead of those of the Intel
  819. assembler:
  820. .CW JOS ,
  821. .CW JOC ,
  822. .CW JCS ,
  823. .CW JCC ,
  824. .CW JEQ ,
  825. .CW JNE ,
  826. .CW JLS ,
  827. .CW JHI ,
  828. .CW JMI ,
  829. .CW JPL ,
  830. .CW JPS ,
  831. .CW JPC ,
  832. .CW JLT ,
  833. .CW JGE ,
  834. .CW JLE ,
  835. and
  836. .CW JGT
  837. instead of
  838. .CW JO ,
  839. .CW JNO ,
  840. .CW JB ,
  841. .CW JNB ,
  842. .CW JZ ,
  843. .CW JNZ ,
  844. .CW JBE ,
  845. .CW JNBE ,
  846. .CW JS ,
  847. .CW JNS ,
  848. .CW JP ,
  849. .CW JNP ,
  850. .CW JL ,
  851. .CW JNL ,
  852. .CW JLE ,
  853. and
  854. .CW JNLE .
  855. .PP
  856. The addressing modes have syntax like
  857. .CW AX ,
  858. .CW (AX) ,
  859. .CW (AX)(BX*4) ,
  860. .CW 10(AX) ,
  861. and
  862. .CW 10(AX)(BX*4) .
  863. The offsets from
  864. .CW AX
  865. can be replaced by offsets from
  866. .CW FP
  867. or
  868. .CW SB
  869. to access names, for example
  870. .CW extern+5(SB)(AX*2) .
  871. .PP
  872. Other notes: Non-relative
  873. .CW JMP
  874. and
  875. .CW CALL
  876. have a
  877. .CW *
  878. added to the syntax.
  879. Only
  880. .CW LOOP ,
  881. .CW LOOPEQ ,
  882. and
  883. .CW LOOPNE
  884. are legal loop instructions. Only
  885. .CW REP
  886. and
  887. .CW REPN
  888. are recognized repeaters. These are not prefixes, but rather
  889. stand-alone opcodes that precede the strings, for example
  890. .P1
  891. CLD; REP; MOVSL
  892. .P2
  893. Segment override prefixes in
  894. .CW MOD/RM
  895. fields are not supported.
  896. .SH
  897. Alpha
  898. .PP
  899. On the Alpha, all registers are 64 bits. The architecture handles 32-bit values
  900. by giving them a canonical format (sign extension in the case of integer registers).
  901. Registers are numbered
  902. .CW R0
  903. through
  904. .CW R31 .
  905. .CW R0
  906. holds the return value from subroutines, and also the first parameter.
  907. .CW R30
  908. is the stack pointer,
  909. .CW R29
  910. is the static base,
  911. .CW R26
  912. is the link register, and
  913. .CW R27
  914. and
  915. .CW R28
  916. are linker temporaries.
  917. .PP
  918. Floating point registers are numbered
  919. .CW F0
  920. to
  921. .CW F31 .
  922. .CW F28
  923. contains
  924. .CW 0.5 ,
  925. .CW F29
  926. contains
  927. .CW 1.0 ,
  928. and
  929. .CW F30
  930. contains
  931. .CW 2.0 .
  932. .CW F31
  933. is always
  934. .CW 0.0
  935. on the Alpha.
  936. .PP
  937. The extension character for
  938. .CW MOV
  939. follows DEC's notation:
  940. .CW B
  941. for byte (8 bits),
  942. .CW W
  943. for word (16 bits),
  944. .CW L
  945. for long (32 bits),
  946. and
  947. .CW Q
  948. for quadword (64 bits).
  949. Byte and ``word'' loads and stores may be made unsigned
  950. by appending a
  951. .CW U .
  952. .CW S
  953. and
  954. .CW T
  955. refer to IEEE floating point single precision (32 bits) and double precision (64 bits), respectively.
  956. .SH
  957. Power PC
  958. .PP
  959. The Power PC follows the Plan 9 model set by the MIPS and SPARC,
  960. not the elaborate ABIs.
  961. The 32-bit instructions of the 60x and 8xx PowerPC architectures are supported;
  962. there is no support for the older POWER instructions.
  963. Registers are
  964. .CW R0
  965. through
  966. .CW R31 .
  967. .CW R0
  968. is initialized to zero; this is done by C start up code
  969. and assumed by the compiler and loader.
  970. .CW R1
  971. is the stack pointer.
  972. .CW R2
  973. is the static base register, with value the address of
  974. .CW setSB(SB) .
  975. .CW R3
  976. is the return register and also the register holding the first
  977. argument to a C function, with space reserved at
  978. .CW 0(FP)
  979. as on the MIPS.
  980. .CW R31
  981. is the loader temporary.
  982. The external registers in Plan 9's C are allocated from
  983. .CW R30
  984. down.
  985. .PP
  986. Floating point registers are called
  987. .CW F0
  988. through
  989. .CW F31 .
  990. By convention, several registers are initialized
  991. to specific values; this is done by the operating system.
  992. .CW F27
  993. must be initialized to the value
  994. .CW 0x4330000080000000
  995. (used by float-to-int conversion),
  996. .CW F28
  997. to the value 0.0,
  998. .CW F29
  999. to 0.5,
  1000. .CW F30
  1001. to 1.0, and
  1002. .CW F31
  1003. to 2.0.
  1004. .PP
  1005. As on the MIPS and SPARC, the assembler accepts arbitrary literals
  1006. as operands to
  1007. .CW MOVW ,
  1008. and also to
  1009. .CW ADD
  1010. and others where `immediate' variants exist,
  1011. and the loader generates sequences
  1012. of
  1013. .CW addi ,
  1014. .CW addis ,
  1015. .CW oris ,
  1016. etc. as required.
  1017. The register indirect addressing modes use the same syntax as the SPARC,
  1018. including double indexing when allowed.
  1019. .PP
  1020. The instruction names are generally derived from the Motorola ones,
  1021. subject to slight transformation:
  1022. the
  1023. .CW . ' `
  1024. marking the setting of condition codes is replaced by
  1025. .CW CC ,
  1026. and when the letter
  1027. .CW o ' `
  1028. represents `OE=1' it is replaced by
  1029. .CW V .
  1030. Thus
  1031. .CW add ,
  1032. .CW addo.
  1033. and
  1034. .CW subfzeo.
  1035. become
  1036. .CW ADD ,
  1037. .CW ADDVCC
  1038. and
  1039. .CW SUBFZEVCC .
  1040. As well as the three-operand conditional branch instruction
  1041. .CW BC ,
  1042. the assembler provides pseudo-instructions for the common cases:
  1043. .CW BEQ ,
  1044. .CW BNE ,
  1045. .CW BGT ,
  1046. .CW BGE ,
  1047. .CW BLT ,
  1048. .CW BLE ,
  1049. .CW BVC ,
  1050. and
  1051. .CW BVS .
  1052. The unconditional branch instruction is
  1053. .CW BR .
  1054. Indirect branches use
  1055. .CW "(CTR)"
  1056. or
  1057. .CW "(LR)"
  1058. as target.
  1059. .PP
  1060. Load or store operations are replaced by
  1061. .CW MOV
  1062. variants in the usual way:
  1063. .CW MOVW
  1064. (move word),
  1065. .CW MOVH
  1066. (move halfword with sign extension), and
  1067. .CW MOVB
  1068. (move byte with sign extension, a pseudo-instruction),
  1069. with unsigned variants
  1070. .CW MOVHZ
  1071. and
  1072. .CW MOVBZ ,
  1073. and byte-reversing
  1074. .CW MOVWBR
  1075. and
  1076. .CW MOVHBR .
  1077. `Load or store with update' versions are
  1078. .CW MOVWU ,
  1079. .CW MOVHU ,
  1080. and
  1081. .CW MOVBZU .
  1082. Load or store multiple is
  1083. .CW MOVMW .
  1084. The exceptions are the string instructions, which are
  1085. .CW LSW
  1086. and
  1087. .CW STSW ,
  1088. and the reservation instructions
  1089. .CW lwarx
  1090. and
  1091. .CW stwcx. ,
  1092. which are
  1093. .CW LWAR
  1094. and
  1095. .CW STWCCC ,
  1096. all with operands in the usual data-flow order.
  1097. Floating-point load or store instructions are
  1098. .CW FMOVD ,
  1099. .CW FMOVDU ,
  1100. .CW FMOVS ,
  1101. and
  1102. .CW FMOVSU .
  1103. The register to register move instructions
  1104. .CW fmr
  1105. and
  1106. .CW fmr.
  1107. are written
  1108. .CW FMOVD
  1109. and
  1110. .CW FMOVDCC .
  1111. .PP
  1112. The assembler knows the commonly used special purpose registers:
  1113. .CW CR ,
  1114. .CW CTR ,
  1115. .CW DEC ,
  1116. .CW LR ,
  1117. .CW MSR ,
  1118. and
  1119. .CW XER .
  1120. The rest, which are often architecture-dependent, are referenced as
  1121. .CW SPR(n) .
  1122. The segment registers of the 60x series are similarly
  1123. .CW SEG(n) ,
  1124. but
  1125. .I n
  1126. can also be a register name, as in
  1127. .CW SEG(R3) .
  1128. Moves between special purpose registers and general purpose ones,
  1129. when allowed by the architecture,
  1130. are written as
  1131. .CW MOVW ,
  1132. replacing
  1133. .CW mfcr ,
  1134. .CW mtcr ,
  1135. .CW mfmsr ,
  1136. .CW mtmsr ,
  1137. .CW mtspr ,
  1138. .CW mfspr ,
  1139. .CW mftb ,
  1140. and many others.
  1141. .PP
  1142. The fields of the condition register
  1143. .CW CR
  1144. are referenced as
  1145. .CW CR(0)
  1146. through
  1147. .CW CR(7) .
  1148. They are used by the
  1149. .CW MOVFL
  1150. (move field) pseudo-instruction,
  1151. which produces
  1152. .CW mcrf
  1153. or
  1154. .CW mtcrf .
  1155. For example:
  1156. .P1
  1157. MOVFL CR(3), CR(0)
  1158. MOVFL R3, CR(1)
  1159. MOVFL R3, $7, CR
  1160. .P2
  1161. They are also accepted in
  1162. the conditional branch instruction, for example
  1163. .P1
  1164. BEQ CR(7), label
  1165. .P2
  1166. Fields of the
  1167. .CW FPSCR
  1168. are accessed using
  1169. .CW MOVFL
  1170. in a similar way:
  1171. .P1
  1172. MOVFL FPSCR, F0
  1173. MOVFL F0, FPSCR
  1174. MOVFL F0, $7, FPSCR
  1175. MOVFL $0, FPSCR(3)
  1176. .P2
  1177. producing
  1178. .CW mffs ,
  1179. .CW mtfsf
  1180. or
  1181. .CW mtfsfi ,
  1182. as appropriate.
  1183. .SH
  1184. ARM
  1185. .PP
  1186. The assembler provides access to
  1187. .CW R0
  1188. through
  1189. .CW R14
  1190. and the
  1191. .CW PC .
  1192. The stack pointer is
  1193. .CW R13 ,
  1194. the link register is
  1195. .CW R14 ,
  1196. and the static base register is
  1197. .CW R12 .
  1198. .CW R0
  1199. is the return register and also the register holding
  1200. the first argument to a subroutine.
  1201. The assembler supports the
  1202. .CW CPSR
  1203. and
  1204. .CW SPSR
  1205. registers.
  1206. It also knows about coprocessor registers
  1207. .CW C0
  1208. through
  1209. .CW C15 .
  1210. Floating registers are
  1211. .CW F0
  1212. through
  1213. .CW F7 ,
  1214. .CW FPSR
  1215. and
  1216. .CW FPCR .
  1217. .PP
  1218. As with the other architectures, loads and stores are called
  1219. .CW MOV ,
  1220. e.g.
  1221. .CW MOVW
  1222. for load word or store word, and
  1223. .CW MOVM
  1224. for
  1225. load or store multiple,
  1226. depending on the operands.
  1227. .PP
  1228. Addressing modes are supported by suffixes to the instructions:
  1229. .CW .IA
  1230. (increment after),
  1231. .CW .IB
  1232. (increment before),
  1233. .CW .DA
  1234. (decrement after), and
  1235. .CW .DB
  1236. (decrement before).
  1237. These can only be used with the
  1238. .CW MOV
  1239. instructions.
  1240. The move multiple instruction,
  1241. .CW MOVM ,
  1242. defines a range of registers using brackets, e.g.
  1243. .CW [R0-R12] .
  1244. The special
  1245. .CW MOVM
  1246. addressing mode bits
  1247. .CW W ,
  1248. .CW U ,
  1249. and
  1250. .CW P
  1251. are written in the same manner, for example,
  1252. .CW MOVM.DB.W .
  1253. A
  1254. .CW .S
  1255. suffix allows a
  1256. .CW MOVM
  1257. instruction to access user
  1258. .CW R13
  1259. and
  1260. .CW R14
  1261. when in another processor mode.
  1262. Shifts and rotates in addressing modes are supported by binary operators
  1263. .CW <<
  1264. (logical left shift),
  1265. .CW >>
  1266. (logical right shift),
  1267. .CW ->
  1268. (arithmetic right shift), and
  1269. .CW @>
  1270. (rotate right); for example
  1271. .CW "R7>>R2" or
  1272. .CW "R2@>2" .
  1273. The assembler does not support indexing by a shifted expression;
  1274. only names can be doubly indexed.
  1275. .PP
  1276. Any instruction can be followed by a suffix that makes the instruction conditional:
  1277. .CW .EQ ,
  1278. .CW .NE ,
  1279. and so on, as in the ARM manual, with synonyms
  1280. .CW .HS
  1281. (for
  1282. .CW .CS )
  1283. and
  1284. .CW .LO
  1285. (for
  1286. .CW .CC ), for example
  1287. .CW ADD.NE .
  1288. Arithmetic
  1289. and logical instructions
  1290. can have a
  1291. .CW .S
  1292. suffix, as ARM allows, to set condition codes.
  1293. .PP
  1294. The syntax of the
  1295. .CW MCR
  1296. and
  1297. .CW MRC
  1298. coprocessor instructions is largely as in the manual, with the usual adjustments.
  1299. The assembler directly supports only the ARM floating-point coprocessor
  1300. operations used by the compiler:
  1301. .CW CMP ,
  1302. .CW ADD ,
  1303. .CW SUB ,
  1304. .CW MUL ,
  1305. and
  1306. .CW DIV ,
  1307. all with
  1308. .CW F
  1309. or
  1310. .CW D
  1311. suffix selecting single or double precision.
  1312. Floating-point load or store become
  1313. .CW MOVF
  1314. and
  1315. .CW MOVD .
  1316. Conversion instructions are also specified by moves:
  1317. .CW MOVWD ,
  1318. .CW MOVWF ,
  1319. .CW MOVDW ,
  1320. .CW MOVWD ,
  1321. .CW MOVFD ,
  1322. and
  1323. .CW MOVDF .
  1324. .SH
  1325. AMD 29000
  1326. .PP
  1327. For details about this assembly language, which was built for the AMD 29240,
  1328. look at the sources or examine compiler output.