Create a program that will copy a block of data from one location to another one
ID: 3725139 • Letter: C
Question
Create a program that will copy a block of data from one location to another one byte at a time (i.e., USING A LOOP). The program must follow these requirements: You must use all the pointers. . Stop the transfer when SBLKENDPTR is reached . The program should count the number of negative values that are transferred to the destination. The final count should be stored in a variable NUMNEG The program should also count the total number of values transferred and put this final count value in a variable TOTAL. The program must contain at least one loop using conditional branch command(s). . . How memory should look after execution!Copy from Source Block to Destination Block Source Block (SBLK): Destination Block (DBLK): SBLKPTR -> DBLKPTR 0x2000.0040 0x2000.0008 0x2000.000C 0x2000.0010 0x2000.0014 0x2000.0018 0x2000.001C 0x2000.0020 0x2000.0024 0 126 -8 63 -44 115 28 0 126 63 -44 115 28 0x2000.0044 0x2000.0048 0x2000.004C 0x2000.0050 0x2000.0054 0x2000.0058 SBLKENDPTR- NUMNEGPTR 0x2000.0000 4 TOTALPTR 0x2000.0004 7Explanation / Answer
AREA Block, CODE, READONLY ; name this block of code
num EQU 20 ; set number of words to be copied
ENTRY ; mark the first instruction called
start
LDR r0, =src ; r0 = pointer to source block
LDR r1, =dst ; r1 = pointer to destination block
MOV r2, #num ; r2 = number of words to copy
MOV sp, #0x400 ; Set up stack pointer (sp)
blockcopy
MOVS r3,r2, LSR #3 ; Number of eight word multiples
BEQ copywords ; Fewer than eight words to move?
PUSH {r4-r11} ; Save some working registers
octcopy
LDM r0!, {r4-r11} ; Load 8 words from the source
STM r1!, {r4-r11} ; and put them at the destination
SUBS r3, r3, #1 ; Decrement the counter
BNE octcopy ; ... copy more
POP {r4-r11} ; Don't require these now - restore
; originals
copywords
ANDS r2, r2, #7 ; Number of odd words to copy
BEQ stop ; No words left to copy?
wordcopy
LDR r3, [r0], #4 ; Load a word from the source and
STR r3, [r1], #4 ; store it to the destination
SUBS r2, r2, #1 ; Decrement the counter
BNE wordcopy ; ... copy more
stop
MOV r0, #0x18 ; angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC #0xFF ; ARM semihosting (formerly SWI)
AREA BlockData, DATA, READWRITE
src DCD 1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4
dst DCD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.