📄 exa9.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> <p> <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 &43040 <i>; "Territory_Number"</i> SWI &43057 <i>; "Territory_LowerCaseTable"</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> <p> <p><h2>Putting it together</h2><h4>The C test program (c.runit):</h4><pre><font size="-1">#include <stdio.h>#include <ctype.h>#include "kernel.h"#include "swis.h"extern void lowercase(char *);void o_lowercase(char []);int <b>main</b>(void){ char s[] = "<i>ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+={[}]|\\:;\"\'<,>.?/ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+={[}]|\\:;\"\'<,>.?/ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+={[}]|\\:;\"\'<,>.?/ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -