; *********************************************************************** ; * * ; * 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 _start ; ASCII codes .equ NUL, 0 ; NUL is used for end of string .equ LF, 10 ; Line Feed (end of line) character ; ARM Monitor software interrupts .equ SWI_WriteC, 0x0 ; Write a single character in R0 .equ SWI_Write0, 0x2 ; Write a NUL-terminated string in R0 .equ SWI_ReadC, 0x4 ; Read a single character into R0 .equ SWI_Exit, 0x11 ; Terminate the program ; External definitions (this section is optional but recommended) .extern strcopy _start: ldr r0,=str_before ; Print str_before to the console swi SWI_Write0 bl printstrs ; then print the two strings 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 swi SWI_Write0 bl printstrs ; then print the two strings (again) exit: swi SWI_Exit .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 ; at the end; you could, instead, write: ; ;srcstr: .ascii "First (source) string" ; .byte NUL .text ; Switch back to the ".text" section printstrs: ; Print the two strings out to the console ldr r0,=str_srcis swi SWI_Write0 ldr r0,=srcstr ; Print the source string swi SWI_Write0 ldr r0,=str_dstis swi SWI_Write0 ldr r0,=dststr ; Print the destination string swi SWI_Write0 ldr r0,=str_end swi SWI_Write0 mov pc,lr ; Return to the caller .data ; Back to the data section (although these ; strings could have been left in ".text") str_before: .ascii "Before copying:" ; Note: NOT ".asciz"! .byte LF, NUL ; End of line and end of string str_after: .asciz "After copying:\n" ; 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