📄 notation.html
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Notation</title><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /><meta http-equiv="content-language" content="en" /><meta name="resource-type" content="document"><meta name="copyright" content="This document copyright 2001-2002 by Richard Murray. Use for non-profit and education purposes explicitly granted."><meta name="author" content="Richard Murray"><meta name="rating" content="general"></head><!-- /assembler/notation.html --><!-- --><!-- (C) Copyright 2002 Richard Murray --><!-- Designed by Richard Murray --><!-- rmurray@heyrick.co.uk --><!-- --><body bgcolor="#f0f0f0" text="#000000" link="#0022dd" vlink="#002288"><table border = "0" width="100%"> <tr> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td> <td> <h1 align="center"><font color="#800080">A quick note <br>on notation</font></h1> </td> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td></table><p> <p>I've had some feedback to say that the notation used is a little peculiar, and why don't I use<i>standard</i> notation.<br>I <b>am</b>!<p>The notation used has been used in the RISC OS world for a long long time. It is very simple,I'll give you a crash course, with the most important things first...<p> <p><h2>&</h2>The ampersand (&) is used to denote hexadecimal.<br>Thus,<pre> 0xF00D hF00D F00Dh $F00D (<i>see later comment on the use of $</i>) &F00D</pre>are all identical, but using different ways to denote base 16.<p>We shall be using the <code>&F00D</code> notion.<p> <p><h2>%</h2>The percent (%) symbol followed by a bunch of zeros and ones denotes a binary value, such as:<br><pre> %1111000000001101 ( which equals &F00D )</pre><br>In BASIC or relating to variables (such as memory blocks), % means integer variable. This canbe used with dimensioned memory blocks, and is preferable as the alternative is to use a real(floating point) variable which uses more memory and is slower. For example:<pre> my_integer% = 123 my_float = 456.78</pre><p> <p><h2><<, >>, >>></h2>These are shift operators. <code><<</code> is a left shift. <code>>></code> is aright shift. <code>>>></code> is an unsigned right shift.<br>This is not used much in assembler as it is implementation specific and can only sensibly beapplied to contant assignments (such as <code>MOV R0, value% << 4</code>). Much more usefuland sensible is the use of the barrel shifter (ASL, ASR, etc).<p>For example:<pre> %00110010 shifted left once is %01100100 %01011000 shifted right twice is %00010110</pre><p> <p><h2>!</h2>Within assembler code, the exclamation mark (or 'pling') denotes writeback. Refer to theinstruction for details.<br>In BASIC code or relating to memory blocks, this means word access. A word is 32 bits.<pre> block%!4 = 0 ; set word at block% + 4 to zero block%!8 = 12 ; set word at block% + 8 to 12</pre><p> <p><h2>?</h2>In BASIC code or relating to memory blocks, the question means byte access.<pre> block%?0 = 17 ; set byte at block% + 0 to 17 block%?1 = 7 ; set byte at block% + 1 to 8 block%?2 = 0 ; set byte at block% + 2 to 0 block%?3 = 0 ; set byte at block% + 3 to 0 myvar% = !block% ; load word at block% into myvar%</pre>You can see, here, that <code>!block%</code> is an alternative form of <code>block%!0</code>;the result loaded into myvar% (an integer) being 1809. If you do not have BASIC to try this outon (no excuse though, with Brandy available), you can work out:<pre> 17 + (7 << 8) = 1809</pre><p> <p><h2>$</h2>In BASIC code or relating to memory blocks, the dollar menas string access. In BASIC, stringsare &0D (13) terminated.<br><i>The dollar does not mean hex!</i><br>In BASIC, relating to variables, $ means a string variable.<pre> my_string$ = "This is a string!"</pre><p>Some further examples:<pre> DIM mymemory% 32 ; allocate 32 bytes of memory userid% = 123 ; set the userid variable flags% = %10101011 ; ...the flags pointer% = &1DEADBED ; ...the pointer name$ = "Rick Murray" ; ...the name spare% = 0 ; ...and finally spare mymemory%?0 = userid% ; set the first byte to the value of userid mymemory%?1 = flags% ; ...next byte to flags mymemory%!2 = pointer% ; ...next word to pointer $(mymemory%+6) = LEFT$(name$, 22) ; ...next 22 bytes to name, with bounding mymemory%!26 = spare% ; and set the final word to spare FOR outer% = 0 TO 3 FOR inner% = 0 TO 7 PRINT RIGHT$("00"+STR$~(mymemory%?(inner% + (outer% * 8))))+" "; NEXT PRINT NEXT END</pre>This is not a proper BASIC program as I've used ';' comments. Remove the comments or replacethe ';' with ":REM".<br>The output generated by the program is:<pre> 7B AB ED DB EA 1D 52 69 63 6B 20 4D 75 72 72 61 79 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00</pre>Apart from saying to watch for the word order (1DEADBED becomes ED DB EA 1D - backwards), I'llleave the rest up to you.<br>Oh, one final thing, in BASIC there is no requirement for words to be stored word aligned.However, it is best to word align things in assembler. It makes life so much easier.<p> <p><h2>Parameter options</h2>You may come across stuff like:<pre> execute do [this|that]</pre>This means your command is <code>execute</code> and your first parameter is <code>do</code>.Your second parameter can be <code>this</code> <i>or</i> <code>that</code>.<br>Sometimes it can get hairier, like:<pre> execute when [doing [something]|being [somebody|someplace]] [before|after]</pre>I'll leave you to figure out the permutations of that one...<p>This is not used in BASIC, but is used in the Programmer's Reference Manuals. They also useangle brackets to denote a <code><variable></code>, but I try to stay away from that whenwriting web pages, for obvious reasons. <tt>:-)</tt><p> <p><h2>Assumptions</h2><ul> <li>You should be familiar with BBC BASIC.<br> You don't need to be an expert, but able to follow clearly laid out programs. <br> <br> <li>You should understand the purpose of 'generic' wrappers that define code, set P%, and do the <code>FOR loop% = 0 TO 2 STEP 2</code> loop; and also know to insert them if/when the example(s) omit the wrapper code for clarity and/or space. <br> <br> <li>A knowledge of binary mathematics and an understanding of AND, NOT, etc is useful. <br> <br> <li>You will need to be able to use RISC OS, stuff like knowing what '$' in filenames means and how to save/run programs. <br> <br> <li>You'll need to be able to use an editor. This is the simple part! <tt>:-)</tt> <br> <br> <li>And, most importantly, you'll need to want to do this in the first place.<br> There is absolutely NO point trying to learn assembler if you don't feel like you have any desire to learn it!<br> Assembler is not something you can 'pick up' in a few days in order to add another something to your CV to make it 'look better'. It will require determination, for while the basics are pretty simple and there are few mnemonics to remember; the power and flexibility will trick you and surprise you for quite a while to come. And as you are going to be building things from the ground up, you will need to take care of most of the housekeeping, such as the stack...</ul><hr size = "3"><a href="index.html#01">Return to assembler index</a><hr size = "3"><address>Copyright © 2002 Richard Murray</address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -