-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathputs_light.as
More file actions
34 lines (31 loc) · 1.24 KB
/
puts_light.as
File metadata and controls
34 lines (31 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/********************************* puts_light.as *****************************
* Author: Agner Fog
* date created: 2021-05-16
* Last modified: 2021-05-16
* Version: 1.11
* Project: ForwardCom library libc_light.li
* Description: puts: print a string to stdout, append linefeed
* This version is for CPUs with limited capabilities
* C declaration: int puts (const char * str);
*
* Copyright 2021 GNU General Public License http://www.gnu.org/licenses
******************************************************************************/
code section execute align = 4 // code section
// Print a string to stdout, append \n
_puts function public reguse=3,0
if (int64 r0 != 0) { // check for null pointer
while (true) { // loop through string
int8 r1 = [r0] // read character
if (int8 r1 == 0) {break} // end of string
int8 output(r1, r1, 10); // output character
int64 r0++ // next character
}
int8 r1 = '\n' // write newline
int8 output(r1, r1, 10);
int r0 = 0 // indicate success
return
}
int r0 = -1 // indicate error
return
_puts end
code end