⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exa9.html

📁 关于ARM汇编的非常好的教程
💻 HTML
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Example 9: Rewriting lowercase()</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 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/exa9.html               --><!--                                     --><!--  (C) Copyright 2000 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">Example 9<br>Rewriting lowercase()</font></h1>    </td>    <td align=center width=100>      <img src="arm3.gif" width=79 height=78 align = middle>    </td></table><p>&nbsp;<p>&nbsp;<p><i>It is imperative that you read <a href="opinion_04.html">this document</a> alongside thisexample... Thank you.</i><br><font color="red">And this example is <i>not</i> 32-bit friendly - refer to the APCSspecification or recompile without preserving flags and see if it works.</font><p><h2>Introduction</h2>Converting a string to lowercase is a useful function, that will be required inmany programs - things such as script parsing or interpreting...<p>In C, the traditional way is to create a routine along the lines of:<pre>void lowercase(char string[]){   int  i = 0;   while ( string[i] )   {      string[i] = tolower(string[i]);      i++;   }   return;}</pre>That isn't bad, but if you do a lot of work with strings that need converting to lower case,you can obtain benefits by converting a repetitive task, such as the lower case conversion,to assembler.<p>As far as I'm aware, only three dialects of RISC OS exist. English, German, and Welsh. Thataside, there is no exuse these days for not making your lowercase routine deal with foreignlanguages. It is simple. Very simple.<br>Like this:<pre>; R0 = Pointer to string (set on entry); R1 = Byte read from string; R2 = Pointer to lowercase table<b>lowercase</b>        STMFD    sp!, {v6, lr}        MOV      R1, R0            <i>; Preserve string pointer</i>        SWI      &amp;43040            <i>; &quot;Territory_Number&quot;</i>        SWI      &amp;43057            <i>; &quot;Territory_LowerCaseTable&quot;</i>        MOV      R2, R0            <i>; Set lowercase table pointer</i>        MOV      R0, R1            <i>; Restore string pointer</i><b>lowercase_loop</b>        LDRB     R1, [R0]          <i>; Load character from R0</i>        CMP      R1, #0            <i>; Is it a null byte?</i>        LDMEQEA  sp!, {v6, pc}^    <i>; Return if null (end of string)</i>        LDRB     R1, [R2, R1]      <i>; Convert to indexed lowercase character</i>        STRB     R1, [R0], #1      <i>; Store character, increment offset pointer</i>        B        lowercase_loop    <i>; Mulberry bushes</i></pre><p>&nbsp;<p>&nbsp;<p><h2>Putting it together</h2><h4>The C test program (c.runit):</h4><pre><font size="-1">#include &lt;stdio.h&gt;#include &lt;ctype.h&gt;#include &quot;kernel.h&quot;#include &quot;swis.h&quot;extern void lowercase(char *);void o_lowercase(char []);int <b>main</b>(void){   char s[] = &quot;<i>ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&amp;*()_-+={[}]|\\:;\&quot;\'&lt;,&gt;.?/ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&amp;*()_-+={[}]|\\:;\&quot;\'&lt;,&gt;.?/ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&amp;*()_-+={[}]|\\:;\&quot;\'&lt;,&gt;.?/ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&amp;*()_-+

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -