📄 call.html
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>CALL and USR</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/call.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">CALL and USR</font></h1> </td> <td align=center width=100> <img src="arm3.gif" width=79 height=78 align = middle> </td></table><p> <p>BASIC provides two methods for running sections of code, <code>CALL</code> and <code>USR</code>.<p><h2>How to run it</h2>When you create some code, such as:<br><pre> P% = code% [ OPT l% .exit MOV PC, R14 .printit CMP R0, #0 MOVEQ PC, R14 SWI "OS_Write0" B exit ]</pre>You have defined three possible entry points:<ul> <li> code% <li> exit <li> printit</ul>Though, two of those (code% and exit) point to the same place. In more complex code, I find itpreferable to call code by label rather than simply calling the block of memory. This allows meto do stuff at the start like a branch table or data storage. Therefore, your code could besomething like:<pre> $code% = filename$+CHR$0 code%!12 = filetype% code%!16 = filelength% CALL process_file</pre>Parameters will have already been set up, so to read the filename you just <code>ADR</code> aregister, then <code>LDRB r, [pointer], #1</code> until you reach a zero byte.<p>Both <code>CALL</code> and <code>USR</code> accept register values. Whatever you set A% to H% tobe will be stored in R0 to R7.<pre> A% = 1 B% = 2 CALL somecode</pre>The function <i>somecode</i> will be entered with R0 set to 1 and R1 set to 2.<p>The principal difference, however, is that with CALL you can pass parameters...<pre> CALL mycode, name$, address$, file_handle%</pre>...and USR takes no parameters, but will return the value of R0.<pre> result% = USR(mycode)</pre><p>Unfortunately, you cannot pass paremeters AND return a value in R0 at the same time.<p> <p>For simple code, or code that could be run stand-alone (ie, not from BASIC), this is all youreally need to know.<br>However BASIC offers much much more. All of this is detailed in <a href="basbits.html">thesection on extended BASIC facilities</a>. It is worth taking a look at, as it offers access toseveral useful BASIC functions and status words.<p> <p><hr size = 3><a href="index.html#04">Return to assembler index</a><hr size = "3"><address>Copyright © 2000 Richard Murray</address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -