comm
This commit is contained in:
parent
c37a788cbd
commit
dbabb956d5
16 changed files with 1319 additions and 426 deletions
|
@ -1,28 +1,85 @@
|
|||
AREA RESET, DATA, READONLY
|
||||
EXPORT __Vectors
|
||||
__Vectors
|
||||
DCD 0x10001000
|
||||
DCD Reset_Handler
|
||||
ALIGN
|
||||
AREA mycode,CODE,READONLY
|
||||
ENTRY
|
||||
EXPORT Reset_Handler
|
||||
|
||||
Reset_Handler
|
||||
MOV R2, #5
|
||||
LDR R0, =SRC
|
||||
LDR R1, =SRC + 36
|
||||
Loop
|
||||
LDR R3, [R0]
|
||||
LDR R4, [R1]
|
||||
STR R3, [R1], #-4
|
||||
STR R4, [R0], #4
|
||||
SUBS R2, #1
|
||||
|
||||
BNE Loop
|
||||
; ========================================================================================
|
||||
; array_reversal.asm - Array Reversal Using Swap Algorithm
|
||||
; ========================================================================================
|
||||
; This program demonstrates how to reverse an array in-place using a swap algorithm.
|
||||
; The algorithm uses two pointers - one starting from the beginning and one from the end
|
||||
; of the array. Elements are swapped in each iteration, and the pointers move towards
|
||||
; the center until they meet or cross each other.
|
||||
|
||||
AREA RESET, DATA, READONLY ; Define a read-only data section for the vector table
|
||||
EXPORT __Vectors ; Export the vector table for external linking
|
||||
|
||||
__Vectors ; Start of the vector table
|
||||
DCD 0x10001000 ; Stack pointer initial value (points to top of stack)
|
||||
DCD Reset_Handler ; Address of the reset handler (program entry point)
|
||||
ALIGN ; Ensure proper alignment for the next section
|
||||
|
||||
AREA mycode,CODE,READONLY ; Define the code section as read-only
|
||||
ENTRY ; Mark the entry point of the program
|
||||
EXPORT Reset_Handler ; Export the reset handler function
|
||||
|
||||
; ========================================================================================
|
||||
; Reset_Handler - Main program execution
|
||||
; ========================================================================================
|
||||
; Algorithm Overview:
|
||||
; 1. Initialize counter R2 to half the array size (5 iterations for 10 elements)
|
||||
; 2. Set R0 to point to the start of the array (SRC)
|
||||
; 3. Set R1 to point to the end of the array (SRC + 36 bytes = last element)
|
||||
; 4. In each iteration:
|
||||
; a. Load element from start pointer (R0) into R3
|
||||
; b. Load element from end pointer (R1) into R4
|
||||
; c. Store R3 to end pointer location and decrement R1 by 4 bytes
|
||||
; d. Store R4 to start pointer location and increment R0 by 4 bytes
|
||||
; e. Decrement counter and repeat until counter reaches zero
|
||||
Reset_Handler
|
||||
; Step 1: Initialize loop counter
|
||||
; Set R2 to 5 (half of array size 10) - number of swap operations needed
|
||||
MOV R2, #5 ; R2 = 5 (loop counter for 5 swap operations)
|
||||
|
||||
; Step 2: Initialize array pointers
|
||||
; R0 points to the beginning of the array
|
||||
LDR R0, =SRC ; R0 = address of first element in SRC array
|
||||
|
||||
; R1 points to the end of the array (SRC + 36 bytes)
|
||||
; 36 = 9 * 4 bytes (offset to reach the last element from first)
|
||||
LDR R1, =SRC + 36 ; R1 = address of last element in SRC array
|
||||
|
||||
; Step 3: Main reversal loop
|
||||
Loop
|
||||
; Load the element from the start of array into R3
|
||||
LDR R3, [R0] ; R3 = element at current start position
|
||||
|
||||
; Load the element from the end of array into R4
|
||||
LDR R4, [R1] ; R4 = element at current end position
|
||||
|
||||
; Swap: Store start element (R3) to end position
|
||||
; Use post-decrement addressing: store R3 to [R1], then R1 = R1 - 4
|
||||
STR R3, [R1], #-4 ; Store R3 to end position and move pointer left
|
||||
|
||||
; Swap: Store end element (R4) to start position
|
||||
; Use post-increment addressing: store R4 to [R0], then R0 = R0 + 4
|
||||
STR R4, [R0], #4 ; Store R4 to start position and move pointer right
|
||||
|
||||
; Decrement loop counter
|
||||
SUBS R2, #1 ; R2 = R2 - 1 (set flags for branch condition)
|
||||
|
||||
; Continue loop if counter is not zero
|
||||
BNE Loop ; Branch to Loop if R2 != 0
|
||||
|
||||
; Step 4: Program termination
|
||||
; Create an infinite loop to stop program execution
|
||||
STOP
|
||||
B STOP
|
||||
AREA mydate, DATA, READWRITE
|
||||
B STOP ; Branch to STOP label (infinite loop)
|
||||
|
||||
AREA mydate, DATA, READWRITE ; Define a read-write data section
|
||||
|
||||
; ========================================================================================
|
||||
; Data Section - Source Array
|
||||
; ========================================================================================
|
||||
; SRC array contains 10 elements (40 bytes total):
|
||||
; Each element is a 32-bit word in hexadecimal format
|
||||
; Original array: [32, 12345644, 05, 98, AB, CD, 55, 32, CA, 45]
|
||||
; After reversal: [45, CA, 32, 55, CD, AB, 98, 05, 12345644, 32]
|
||||
SRC DCD 0x00000032, 0x12345644, 0x00000005, 0x00000098, 0x000000AB, 0x000000CD, 0x00000055, 0x00000032, 0x000000CA, 0x00000045
|
||||
END
|
||||
|
||||
END ; End of the assembly program
|
|
@ -1,26 +1,79 @@
|
|||
AREA RESET, DATA, READONLY
|
||||
EXPORT __Vectors
|
||||
__Vectors
|
||||
DCD 0x10001000
|
||||
DCD Reset_Handler
|
||||
ALIGN
|
||||
AREA mycode,CODE,READONLY
|
||||
ENTRY
|
||||
EXPORT Reset_Handler
|
||||
Reset_Handler
|
||||
LDR R0, =SRC
|
||||
LDR R1, =DST
|
||||
MOV R2,#10
|
||||
BACK
|
||||
LDR R3,[R0],#4;
|
||||
STR R3,[R1],#04;
|
||||
SUBS R2,#1
|
||||
BNE BACK
|
||||
; ========================================================================================
|
||||
; LOOP.asm - Efficient Array Copy Using Loop Construct
|
||||
; ========================================================================================
|
||||
; This program demonstrates an efficient way to copy data from one array to another
|
||||
; using a loop construct. This approach is much more scalable and maintainable
|
||||
; compared to individual copy operations, especially for larger arrays.
|
||||
|
||||
AREA RESET, DATA, READONLY ; Define a read-only data section for the vector table
|
||||
EXPORT __Vectors ; Export the vector table for external linking
|
||||
|
||||
__Vectors ; Start of the vector table
|
||||
DCD 0x10001000 ; Stack pointer initial value (points to top of stack)
|
||||
DCD Reset_Handler ; Address of the reset handler (program entry point)
|
||||
ALIGN ; Ensure proper alignment for the next section
|
||||
|
||||
AREA mycode,CODE,READONLY ; Define the code section as read-only
|
||||
ENTRY ; Mark the entry point of the program
|
||||
EXPORT Reset_Handler ; Export the reset handler function
|
||||
|
||||
; ========================================================================================
|
||||
; Reset_Handler - Main program execution
|
||||
; ========================================================================================
|
||||
; Algorithm Overview:
|
||||
; 1. Initialize array pointers (R0 = SRC address, R1 = DST address)
|
||||
; 2. Set loop counter R2 to the number of elements to copy (10)
|
||||
; 3. In each iteration of the loop:
|
||||
; a. Load element from SRC array using post-increment addressing
|
||||
; b. Store element to DST array using post-increment addressing
|
||||
; c. Decrement counter and check if more iterations are needed
|
||||
; 4. This approach is much more efficient than individual operations for large arrays
|
||||
Reset_Handler
|
||||
; Step 1: Initialize array pointers
|
||||
; R0 points to the beginning of the source array
|
||||
LDR R0, =SRC ; R0 = address of first element in SRC array
|
||||
|
||||
; R1 points to the beginning of the destination array
|
||||
LDR R1, =DST ; R1 = address of first element in DST array
|
||||
|
||||
; Step 2: Initialize loop counter
|
||||
; R2 holds the number of elements to copy (10 elements total)
|
||||
MOV R2,#10 ; R2 = 10 (number of elements to copy)
|
||||
|
||||
; Step 3: Main copy loop
|
||||
BACK
|
||||
; Load from SRC array and advance pointer
|
||||
; LDR R3, [R0], #4 means: R3 = [R0], then R0 = R0 + 4
|
||||
LDR R3,[R0],#4 ; Load next element from SRC and advance R0
|
||||
|
||||
; Store to DST array and advance pointer
|
||||
; STR R3, [R1], #4 means: [R1] = R3, then R1 = R1 + 4
|
||||
STR R3,[R1],#04 ; Store element to DST and advance R1
|
||||
|
||||
; Decrement loop counter and set condition flags
|
||||
SUBS R2,#1 ; R2 = R2 - 1 (set flags for branch condition)
|
||||
|
||||
; Branch back to BACK if R2 is not zero
|
||||
BNE BACK ; If R2 != 0, continue loop
|
||||
|
||||
; Step 4: Program termination
|
||||
; Create an infinite loop to stop program execution
|
||||
STOP
|
||||
B STOP
|
||||
ALIGN
|
||||
B STOP ; Branch to STOP label (infinite loop)
|
||||
|
||||
ALIGN ; Ensure proper alignment for data section
|
||||
|
||||
; ========================================================================================
|
||||
; Data Section - Source and Destination Arrays
|
||||
; ========================================================================================
|
||||
; SRC array contains 10 elements (40 bytes total):
|
||||
; Each element is a 32-bit word in hexadecimal format
|
||||
SRC DCD 0x00000032, 0x12345644, 0x00000005, 0x00000098, 0x000000AB, 0x000000CD, 0x00000055, 0x00000032, 0x000000CA, 0x00000045
|
||||
AREA mydate, DATA, READWRITE
|
||||
|
||||
AREA mydate, DATA, READWRITE ; Define a read-write data section
|
||||
|
||||
; DST array - initially contains space for one element, but will be expanded
|
||||
; during copy operations. The loop will copy all 10 elements from SRC to DST
|
||||
DST DCD 0
|
||||
END
|
||||
|
||||
END ; End of the assembly program
|
|
@ -1,27 +1,83 @@
|
|||
AREA RESET, DATA, READONLY
|
||||
EXPORT __Vectors
|
||||
__Vectors
|
||||
DCD 0x10001000
|
||||
DCD Reset_Handler
|
||||
ALIGN
|
||||
AREA mycode,CODE,READONLY
|
||||
ENTRY
|
||||
EXPORT Reset_Handler
|
||||
; ========================================================================================
|
||||
; LOOP2.asm - Array Copy Using Loop with Proper Destination Array Size
|
||||
; ========================================================================================
|
||||
; This program demonstrates the same array copy algorithm as LOOP.asm but with
|
||||
; two key improvements:
|
||||
; 1. Uses R12 as the loop counter (R12 is typically used for intra-procedure calls)
|
||||
; 2. Pre-allocates the correct size for the destination array (10 elements)
|
||||
; This version is more complete and avoids potential memory issues.
|
||||
|
||||
AREA RESET, DATA, READONLY ; Define a read-only data section for the vector table
|
||||
EXPORT __Vectors ; Export the vector table for external linking
|
||||
|
||||
__Vectors ; Start of the vector table
|
||||
DCD 0x10001000 ; Stack pointer initial value (points to top of stack)
|
||||
DCD Reset_Handler ; Address of the reset handler (program entry point)
|
||||
ALIGN ; Ensure proper alignment for the next section
|
||||
|
||||
AREA mycode,CODE,READONLY ; Define the code section as read-only
|
||||
ENTRY ; Mark the entry point of the program
|
||||
EXPORT Reset_Handler ; Export the reset handler function
|
||||
|
||||
; ========================================================================================
|
||||
; Reset_Handler - Main program execution
|
||||
; ========================================================================================
|
||||
; Algorithm Overview:
|
||||
; 1. Initialize array pointers (R0 = SRC address, R1 = DST address)
|
||||
; 2. Set loop counter R12 to the number of elements to copy (10)
|
||||
; 3. In each iteration of the loop:
|
||||
; a. Load element from SRC array using post-increment addressing
|
||||
; b. Store element to DST array using post-increment addressing
|
||||
; c. Decrement counter and check if more iterations are needed
|
||||
; 4. This version properly allocates destination array space beforehand
|
||||
Reset_Handler
|
||||
LDR R0, =SRC
|
||||
LDR R1, =DST
|
||||
MOV R12, #10
|
||||
; Step 1: Initialize array pointers
|
||||
; R0 points to the beginning of the source array
|
||||
LDR R0, =SRC ; R0 = address of first element in SRC array
|
||||
|
||||
; R1 points to the beginning of the destination array
|
||||
LDR R1, =DST ; R1 = address of first element in DST array
|
||||
|
||||
; Step 2: Initialize loop counter
|
||||
; R12 holds the number of elements to copy (10 elements total)
|
||||
; Using R12 is a common convention for loop counters in ARM assembly
|
||||
MOV R12, #10 ; R12 = 10 (number of elements to copy)
|
||||
|
||||
; Step 3: Main copy loop
|
||||
Loop
|
||||
LDR R2, [R0], #4
|
||||
STR R2, [R1], #4
|
||||
SUBS R12, R12, #1
|
||||
BNE Loop
|
||||
; Load from SRC array and advance pointer
|
||||
; LDR R2, [R0], #4 means: R2 = [R0], then R0 = R0 + 4
|
||||
LDR R2, [R0], #4 ; Load next element from SRC and advance R0
|
||||
|
||||
; Store to DST array and advance pointer
|
||||
; STR R2, [R1], #4 means: [R1] = R2, then R1 = R1 + 4
|
||||
STR R2, [R1], #4 ; Store element to DST and advance R1
|
||||
|
||||
; Decrement loop counter and set condition flags
|
||||
; SUBS R12, R12, #1 is equivalent to SUBS R12, #1
|
||||
SUBS R12, R12, #1 ; R12 = R12 - 1 (set flags for branch condition)
|
||||
|
||||
; Branch back to Loop if R12 is not zero
|
||||
BNE Loop ; If R12 != 0, continue loop
|
||||
|
||||
; Step 4: Program termination
|
||||
; Create an infinite loop to stop program execution
|
||||
STOP
|
||||
B STOP
|
||||
ALIGN
|
||||
B STOP ; Branch to STOP label (infinite loop)
|
||||
|
||||
ALIGN ; Ensure proper alignment for data section
|
||||
|
||||
; ========================================================================================
|
||||
; Data Section - Source and Destination Arrays
|
||||
; ========================================================================================
|
||||
; SRC array contains 10 elements (40 bytes total):
|
||||
; Each element is a 32-bit word in hexadecimal format
|
||||
SRC DCD 0x00000032, 0x12345644, 0x00000005, 0x00000098, 0x000000AB, 0x000000CD, 0x00000055, 0x00000032, 0x000000CA, 0x00000045
|
||||
AREA mydate, DATA, READWRITE
|
||||
|
||||
AREA mydate, DATA, READWRITE ; Define a read-write data section
|
||||
|
||||
; DST array - properly pre-allocated with 10 elements (all initialized to 0)
|
||||
; This ensures there is enough space for all copied elements
|
||||
DST DCD 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
END
|
||||
|
||||
END ; End of the assembly program
|
|
@ -1,40 +1,99 @@
|
|||
AREA RESET, DATA, READONLY
|
||||
EXPORT __Vectors
|
||||
__Vectors
|
||||
DCD 0x10001000
|
||||
DCD Reset_Handler
|
||||
ALIGN
|
||||
AREA mycode,CODE,READONLY
|
||||
ENTRY
|
||||
EXPORT Reset_Handler
|
||||
Reset_Handler
|
||||
LDR R0, =SRC
|
||||
LDR R1, =DST
|
||||
LDR R2,[R0]
|
||||
STR R2,[R1]
|
||||
LDR R3,[R0,#4]!
|
||||
STR R3,[R1,#4]!
|
||||
LDR R4,[R0,#4]!
|
||||
STR R4,[R1,#4]!
|
||||
LDR R5,[R0,#4]!
|
||||
STR R5,[R1,#4]!
|
||||
LDR R6,[R0,#4]
|
||||
STR R6,[R1,#4]
|
||||
LDR R7,[R0,#4]
|
||||
STR R7,[R1,#4]
|
||||
LDR R8,[R0,#4]
|
||||
STR R8,[R1,#4]
|
||||
LDR R9,[R0],#4
|
||||
STR R9,[R1],#4
|
||||
LDR R10,[R0],#4
|
||||
STR R10,[R1],#4
|
||||
LDR R11,[R0],#4
|
||||
STR R11,[R1],#4
|
||||
; ========================================================================================
|
||||
; MULTINDEX.asm - Mixed Addressing Modes for Array Copy Operations
|
||||
; ========================================================================================
|
||||
; This program demonstrates different addressing modes used in ARM assembly for
|
||||
; array operations. It intentionally mixes various approaches to show the
|
||||
; different ways memory can be accessed and how pointers are managed.
|
||||
|
||||
AREA RESET, DATA, READONLY ; Define a read-only data section for the vector table
|
||||
EXPORT __Vectors ; Export the vector table for external linking
|
||||
|
||||
__Vectors ; Start of the vector table
|
||||
DCD 0x10001000 ; Stack pointer initial value (points to top of stack)
|
||||
DCD Reset_Handler ; Address of the reset handler (program entry point)
|
||||
ALIGN ; Ensure proper alignment for the next section
|
||||
|
||||
AREA mycode,CODE,READONLY ; Define the code section as read-only
|
||||
ENTRY ; Mark the entry point of the program
|
||||
EXPORT Reset_Handler ; Export the reset handler function
|
||||
|
||||
; ========================================================================================
|
||||
; Reset_Handler - Main program execution
|
||||
; ========================================================================================
|
||||
; Algorithm Overview:
|
||||
; This program demonstrates various addressing modes for copying array elements:
|
||||
; 1. Basic load/store without pointer advancement
|
||||
; 2. Post-increment addressing (! symbol) - pointer advances after operation
|
||||
; 3. Pre-indexed addressing without (!) - pointer doesn't advance automatically
|
||||
; 4. Mixed approaches to show flexibility in ARM assembly programming
|
||||
Reset_Handler
|
||||
; Step 1: Initialize array pointers
|
||||
; R0 points to the beginning of the source array
|
||||
LDR R0, =SRC ; R0 = address of first element in SRC array
|
||||
|
||||
; R1 points to the beginning of the destination array
|
||||
LDR R1, =DST ; R1 = address of first element in DST array
|
||||
|
||||
; Step 2: Copy first element - Basic addressing (no pointer advancement)
|
||||
; Load from [R0] and store to [R1] without changing pointer values
|
||||
LDR R2,[R0] ; R2 = SRC[0] (R0 unchanged)
|
||||
STR R2,[R1] ; DST[0] = R2 (R1 unchanged)
|
||||
|
||||
; Step 3: Copy next 3 elements - Post-increment addressing
|
||||
; Using '!' symbol means pointer is updated after the operation
|
||||
LDR R3,[R0,#4]! ; R3 = SRC[1], then R0 = R0 + 4
|
||||
STR R3,[R1,#4]! ; DST[1] = R3, then R1 = R1 + 4
|
||||
|
||||
LDR R4,[R0,#4]! ; R4 = SRC[2], then R0 = R0 + 4
|
||||
STR R4,[R1,#4]! ; DST[2] = R4, then R1 = R1 + 4
|
||||
|
||||
LDR R5,[R0,#4]! ; R5 = SRC[3], then R0 = R0 + 4
|
||||
STR R5,[R1,#4]! ; DST[3] = R5, then R1 = R1 + 4
|
||||
|
||||
; Step 4: Copy next 3 elements - Pre-indexed addressing without advancement
|
||||
; Without '!' symbol, pointers are not automatically updated
|
||||
; Manual pointer advancement is needed (not shown here, which may be intentional)
|
||||
LDR R6,[R0,#4] ; R6 = SRC[4] (R0 unchanged)
|
||||
STR R6,[R1,#4] ; DST[4] = R6 (R1 unchanged)
|
||||
|
||||
LDR R7,[R0,#4] ; R7 = SRC[5] (R0 unchanged)
|
||||
STR R7,[R1,#4] ; DST[5] = R7 (R1 unchanged)
|
||||
|
||||
LDR R8,[R0,#4] ; R8 = SRC[6] (R0 unchanged)
|
||||
STR R8,[R1,#4] ; DST[6] = R8 (R1 unchanged)
|
||||
|
||||
; Step 5: Copy last 3 elements - Post-increment addressing again
|
||||
; Switch back to post-increment mode for the final elements
|
||||
LDR R9,[R0],#4 ; R9 = SRC[7], then R0 = R0 + 4
|
||||
STR R9,[R1],#4 ; DST[7] = R9, then R1 = R1 + 4
|
||||
|
||||
LDR R10,[R0],#4 ; R10 = SRC[8], then R0 = R0 + 4
|
||||
STR R10,[R1],#4 ; DST[8] = R10, then R1 = R1 + 4
|
||||
|
||||
LDR R11,[R0],#4 ; R11 = SRC[9], then R0 = R0 + 4
|
||||
STR R11,[R1],#4 ; DST[9] = R11, then R1 = R1 + 4
|
||||
|
||||
; Step 6: Program termination
|
||||
; Create an infinite loop to stop program execution
|
||||
STOP
|
||||
B STOP
|
||||
ALIGN
|
||||
B STOP ; Branch to STOP label (infinite loop)
|
||||
|
||||
ALIGN ; Ensure proper alignment for data section
|
||||
|
||||
; ========================================================================================
|
||||
; Data Section - Source and Destination Arrays
|
||||
; ========================================================================================
|
||||
; SRC array contains 10 elements (40 bytes total):
|
||||
; Each element is a 32-bit word in hexadecimal format
|
||||
; Note: The middle section (elements 4-6) uses pre-indexed addressing without
|
||||
; pointer advancement, which means the same memory locations are accessed
|
||||
; multiple times. This demonstrates different addressing mode behaviors.
|
||||
SRC DCD 0x00000032, 0x12345644, 0x00000005, 0x00000098, 0x000000AB, 0x000000CD, 0x00000055, 0x00000032, 0x000000CA, 0x00000045
|
||||
AREA mydate, DATA, READWRITE
|
||||
|
||||
AREA mydate, DATA, READWRITE ; Define a read-write data section
|
||||
|
||||
; DST array - initially contains space for one element, but will be expanded
|
||||
; during copy operations to accommodate all 10 elements
|
||||
DST DCD 0
|
||||
END
|
||||
|
||||
END ; End of the assembly program
|
|
@ -1,40 +1,93 @@
|
|||
AREA RESET, DATA, READONLY
|
||||
EXPORT __Vectors
|
||||
__Vectors
|
||||
DCD 0x10001000
|
||||
DCD Reset_Handler
|
||||
ALIGN
|
||||
AREA mycode,CODE,READONLY
|
||||
ENTRY
|
||||
EXPORT Reset_Handler
|
||||
Reset_Handler
|
||||
LDR R0, =SRC
|
||||
LDR R1, =DST
|
||||
LDR R2, [R0]
|
||||
STR R2, [R1]
|
||||
LDR R3, [R0,#4]!
|
||||
STR R3, [R1,#4]!
|
||||
LDR R4, [R0,#4]!
|
||||
STR R4, [R1,#4]!
|
||||
LDR R5, [R0,#4]!
|
||||
STR R5, [R1,#4]!
|
||||
LDR R6, [R0,#4]!
|
||||
STR R6, [R1,#4]!
|
||||
LDR R7, [R0,#4]!
|
||||
STR R7, [R1,#4]!
|
||||
LDR R8, [R0,#4]!
|
||||
STR R8, [R1,#4]!
|
||||
LDR R9, [R0,#4]!
|
||||
STR R9, [R1,#4]!
|
||||
LDR R10, [R0,#4]!
|
||||
STR R10, [R1,#4]!
|
||||
LDR R11, [R0,#4]!
|
||||
STR R11, [R1,#4]!
|
||||
; ========================================================================================
|
||||
; SWAP.asm - Basic Array Copy Using Post-Increment Addressing
|
||||
; ========================================================================================
|
||||
; This program demonstrates how to copy data from one array to another using
|
||||
; post-increment addressing mode. Each load/store operation automatically
|
||||
; advances the pointer to the next array element, eliminating the need for
|
||||
; separate pointer arithmetic instructions.
|
||||
|
||||
AREA RESET, DATA, READONLY ; Define a read-only data section for the vector table
|
||||
EXPORT __Vectors ; Export the vector table for external linking
|
||||
|
||||
__Vectors ; Start of the vector table
|
||||
DCD 0x10001000 ; Stack pointer initial value (points to top of stack)
|
||||
DCD Reset_Handler ; Address of the reset handler (program entry point)
|
||||
ALIGN ; Ensure proper alignment for the next section
|
||||
|
||||
AREA mycode,CODE,READONLY ; Define the code section as read-only
|
||||
ENTRY ; Mark the entry point of the program
|
||||
EXPORT Reset_Handler ; Export the reset handler function
|
||||
|
||||
; ========================================================================================
|
||||
; Reset_Handler - Main program execution
|
||||
; ========================================================================================
|
||||
; Algorithm Overview:
|
||||
; 1. Load addresses of source (SRC) and destination (DST) arrays
|
||||
; 2. Copy each element individually using post-increment addressing
|
||||
; 3. The '!' symbol after the offset means post-increment addressing:
|
||||
; - Load from [R0, #4]! means: load from R0+4, then R0 = R0 + 4
|
||||
; - Store to [R1, #4]! means: store to R1+4, then R1 = R1 + 4
|
||||
; 4. This approach copies 10 elements (using registers R2-R11)
|
||||
Reset_Handler
|
||||
; Step 1: Initialize array pointers
|
||||
; R0 points to the beginning of the source array
|
||||
LDR R0, =SRC ; R0 = address of first element in SRC array
|
||||
|
||||
; R1 points to the beginning of the destination array
|
||||
LDR R1, =DST ; R1 = address of first element in DST array
|
||||
|
||||
; Step 2: Copy first element (no post-increment for initial load)
|
||||
; Load from SRC[0] into R2, store to DST[0]
|
||||
LDR R2, [R0] ; R2 = SRC[0] (no increment yet)
|
||||
STR R2, [R1] ; DST[0] = R2 (no increment yet)
|
||||
|
||||
; Step 3: Copy remaining elements using post-increment addressing
|
||||
; Each load/store pair advances both pointers by 4 bytes automatically
|
||||
LDR R3, [R0,#4]! ; R3 = SRC[1], then R0 = R0 + 4
|
||||
STR R3, [R1,#4]! ; DST[1] = R3, then R1 = R1 + 4
|
||||
|
||||
LDR R4, [R0,#4]! ; R4 = SRC[2], then R0 = R0 + 4
|
||||
STR R4, [R1,#4]! ; DST[2] = R4, then R1 = R1 + 4
|
||||
|
||||
LDR R5, [R0,#4]! ; R5 = SRC[3], then R0 = R0 + 4
|
||||
STR R5, [R1,#4]! ; DST[3] = R5, then R1 = R1 + 4
|
||||
|
||||
LDR R6, [R0,#4]! ; R6 = SRC[4], then R0 = R0 + 4
|
||||
STR R6, [R1,#4]! ; DST[4] = R6, then R1 = R1 + 4
|
||||
|
||||
LDR R7, [R0,#4]! ; R7 = SRC[5], then R0 = R0 + 4
|
||||
STR R7, [R1,#4]! ; DST[5] = R7, then R1 = R1 + 4
|
||||
|
||||
LDR R8, [R0,#4]! ; R8 = SRC[6], then R0 = R0 + 4
|
||||
STR R8, [R1,#4]! ; DST[6] = R8, then R1 = R1 + 4
|
||||
|
||||
LDR R9, [R0,#4]! ; R9 = SRC[7], then R0 = R0 + 4
|
||||
STR R9, [R1,#4]! ; DST[7] = R9, then R1 = R1 + 4
|
||||
|
||||
LDR R10, [R0,#4]! ; R10 = SRC[8], then R0 = R0 + 4
|
||||
STR R10, [R1,#4]! ; DST[8] = R10, then R1 = R1 + 4
|
||||
|
||||
LDR R11, [R0,#4]! ; R11 = SRC[9], then R0 = R0 + 4
|
||||
STR R11, [R1,#4]! ; DST[9] = R11, then R1 = R1 + 4
|
||||
|
||||
; Step 4: Program termination
|
||||
; Create an infinite loop to stop program execution
|
||||
STOP
|
||||
B STOP
|
||||
ALIGN
|
||||
B STOP ; Branch to STOP label (infinite loop)
|
||||
|
||||
ALIGN ; Ensure proper alignment for data section
|
||||
|
||||
; ========================================================================================
|
||||
; Data Section - Source and Destination Arrays
|
||||
; ========================================================================================
|
||||
; SRC array contains 10 elements (40 bytes total):
|
||||
; Each element is a 32-bit word in hexadecimal format
|
||||
SRC DCD 0x00000032, 0x12345644, 0x00000005, 0x00000098, 0x000000AB, 0x000000CD, 0x00000055, 0x00000032, 0x000000CA, 0x00000045
|
||||
AREA mydate, DATA, READWRITE
|
||||
|
||||
AREA mydate, DATA, READWRITE ; Define a read-write data section
|
||||
|
||||
; DST array - initially contains one zero, but will be expanded during copy operations
|
||||
; The actual size will be determined by how many elements are copied
|
||||
DST DCD 0
|
||||
END
|
||||
|
||||
END ; End of the assembly program
|
Loading…
Add table
Add a link
Reference in a new issue