@ *********************************************************************** @ * * @ * Copy a NUL-terminated String * @ * * @ *********************************************************************** @ Author: John Zaitseff @ Date: 9th September, 2002 @ Version: 1.4 @ This program copies a NUL-terminated string from one location to @ another. The main features of this program are the use of a separate @ module, "copy.s", for the actual copy-string function and the use of SWI @ software interrupt instructions. Please make sure that you read the @ source code to "copy.s"! .text .global main @ ASCII codes .equ NUL, 0 @ NUL is used for end of string .equ LF, 10 @ Line Feed (end of line) character @ External definitions (this section is optional but recommended) .extern strcopy main: push {lr} ldr r0,=str_before @ Print str_before to the console bl puts ldr r0,=srcstr bl puts ldr r0, =dststr bl puts ldr r0,=dststr @ R0 := address of destination string ldr r1,=srcstr @ R1 := address of source string bl strcopy @ Call the function "strcopy" (in "copy.s") ldr r0,=str_after @ Print str_after to the console bl puts @ then print the two strings (again) ldr r0,=srcstr bl puts ldr r0, =dststr bl puts pop {pc} .data @ Read/write data follows .align @ Align to a 32-bit boundary srcstr: .asciz "First (source) string" dststr: .asciz "Second (destination) string" @ The source string "srcstr" could have been placed in the ".text" @ section, as it is read-only. Note that ".asciz" places a NUL character .data @ Back to the data section (although these @ strings could have been left in ".text") str_before: .asciz "Before copying:" @ Note: NOT ".asciz"! str_after: .asciz "After copying:" @ The same, using C-style escapes str_srcis: .asciz "srcstr = \"" @ Using \" escape for double-quotes str_dstis: .asciz "\"\ndststr = \"" str_end: .asciz "\"\n\n" .end