From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../ARM202U/EXAMPLES/EXPLASM/UTOA1.S | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/EXPLASM/UTOA1.S (limited to 'Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/EXPLASM/UTOA1.S') diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/EXPLASM/UTOA1.S b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/EXPLASM/UTOA1.S new file mode 100644 index 0000000..369773a --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/EXPLASM/UTOA1.S @@ -0,0 +1,60 @@ +; This demonstrates recursion in ARM assembler. +; this version does not perform stack checking. +; +; Converting a number to a string can be expressed using a divide-and- +; conquer algorithm: +; = "" + + AREA |utoa$$code|, CODE, READONLY + + EXPORT dtoa + EXPORT utoa + + IMPORT udiv10 + +dtoa +; converts signed word to string +; a1 = char *buffer +; a2 = signed int number +; on exit: +; a1 = char *end_of_string + + CMP a2, #0 + RSBMI a2, a2, #0; make a2 positive + MOVMI ip, #'-' + STRMIB ip, [ a1 ], #1 ; add minus sign to buffer + +; *** intentional drop-through to utoa *** + +utoa +; recursive routine to convert unsigned word to string +; on entry: +; a1 = char *buffer +; a2 = unsigned int number +; on exit: +; a1 = char *end_of_string ; character after last digit +; all other registers preserved + + STMFD sp!, {v1, v2, lr} ; save 2 variable registers and + ; the return address + + MOV v1, a1 ; keep char *buffer for later + MOV v2, a2 ; and keep the number for later + MOV a1, a2 + BL udiv10 ; on return, the quotient is in a1 + + SUB v2, v2, a1, LSL #3 ; number - 8*quoitient + SUB v2, v2, a1, LSL #1 ; - 2*quotient = remainder + + CMP a1, #0 ; quotient non-zero? + MOVNE a2, a1 ; quotient to a2... + MOV a1, v1 ; buffer pointer unconditionally to a1 + BLNE utoa ; conditional recursive call to utoa + + ADD v2, v2, #'0' ; final digit + STRB v2, [a1], #1 ; store digit at end of buffer + + LDMFD sp!, {v1, v2, pc} ; restore and return + + END + -- cgit v1.2.3