Write a program to copy text from the location pointed at by r0 to the location pointed at by r1. The copied version must be in reverse order. Assume the string you are copying is non?null (it contains at least one character) and that it is terminated.
What will be an ideal response?
A simple way is to find the end of the string and then move a character from the end of the source string to the beginning of the destination and then continue character?by?character working in opposite directions. Note that this code uses some features not available with the Keil system.
; Point to source
; Point to destination
; REPEAT
; Read char from source
; UNTIL all last char found
; REPEAT
; Copy source character to destination
; Decrement source pointer, increment destination pointer
; UNTIL all done
AREA ReverseString, CODE, READWRITE
ADR r0,Source ;r0 points to source
MOV r3,r0 ;keep a copy of the start of the source
FindEnd LDRB r2,[r0],#1 ;read a byte and update pointer
CMP r2,#0x0D ;test for end
BNE FindEnd ;continue until terminator found
;pointer to source is one past the end of the string
ADR r1,Dest ;r1 points to destination
CopyBak LDRB r2,[r0,#-1]! ;read a char using predecrementing from source
STRB r2,[r1],#1 ;store at destination with post incrementing
CMP r0,r3 ;are we back at the start?
BNE CopyBak ;if not keep going
MOV r0, #0x18 ;angel_SWIreason_ReportException
LDR r1, =0x20026 ;ADP_Stopped_ApplicationExit
SVC #0x123456 ;ARM semihosting (formerly SWI)
AREA ReverseString, DATA, READWRITE
DCD 0xFFFFFFFF ;this is just a marker to help me read the code
Source DCB "Test",0x0D
Dest DCD 1,1,1,1,1 ;fill the target with 1s to help testing
END
Computer Science & Information Technology
You might also like to view...
What does specifying the mapping /dev/sdc=none when launching an instance do?
A. Prevents /dev/sdc from creating the instance. B. Prevents /dev/sdc from deleting the instance. C. Set the value of /dev/sdc to 'zero'. D. Prevents /dev/sdc from attaching to the instance.
Computer Science & Information Technology
Footnotes are indicated in a report by a superscript number.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology