TTL mem_transfer
; give name to the file
AREA Myprog, CODE, READONLY ;
defining name to the
ENTRY
EXPORT main
; Export address of
main to MKL25Z4.s
main
;---------------------------------------------------------------------------------------------------------
;Prerequisite
; Register R0-R7 can only use
;For half word transfer 0th bit of source address must be 0, to avoid HARDfault
exception
;For word transfer 0th and 1st both bits of source address must be 0, to avoid
HARDfault exception
; Read page no 132, note for the same of ARM cortex M0 and M0+ definitive
guide.
; R7=0x1FFFF100 it is already memory mapped, if you take any other value you need to go to debug ;and need to memory map manually for reading and writing.
;Part-1 register offset addressing mode
LDR R7, =0x1FFFF100 ;load value of
"top of the stack" into R7=address of stack area
LDR R1,=0x00
;r1=00
LDRB R2,[R7,R1]
;Byte transfer R2= memory (R7+R1)
LDR R1,=0x02
; TO avoide HARD
fault exception 0th bit always 0 while transferring ;half word
LDRH R3,[R7,R1]
;Half word transfer R2= memory (R7+R1)
LDR R1,=0x04
;TO avoide
HARD fault exception 0th, 1st bits always 0 while ;transferring word
LDR R4,[R7, R1]
;Word transfer R2= memory (R7+R1)
;Part-2 immediate offset addressing mode
LDRB R5, [R7,#0x00]
;R5=R7+0x00
LDRH R6, [R7,#0x02]
;R6=R7+(0x02)
LDR R2, [R7,#0x04]
;R6=R7+(0x04)
;Part-3 Stack pointer
LDR R3, [SP,#0x00] ;
R3= SP(0x1FFFF160)+0x04
;Part-4 Sign extended Load
LDR R1,=0x02
LDRSH R4,[R7, R1]
LDR R1,=0x03
LDRSB R5,[R7, R1]
;part-5 Store the values to the memory location with relative register
LDR R1,=0x08
; to get the proper offset for Store operation
leave first locations
STRB R2, [R7, R1] ;
memory[R7+R1] = R2
LDR R1,=0x0A
; R1=0X0A
STRH R3,[R7,R1] ;
memory[R7+R1] = R3
LDR R1,=0x0C
; R1=0x0C
STR R4,[R7,R1]
; memory[R7+R1] = R4
;Part-6 Store the value to the memory location with relative immediate address
STRB R5,[R7,#0x0D]
STRH R6,[R7,#0x0E]
STR R2,[R7,#0x10]
;Part-7 Store the value to the memory location with SP relative address
STR R3, [SP,#0x04] ; Store word on memory
location form by [SP+4] = R3
done
SWI &11 ; go to system subroutine
write on location 11
END ;End
of the code
;-------------------------------------------------------------------------------------------------------------------
;Now you need to save the file-> Build the project -> debug it it and.
; prior to start debug follow below steps
;--------------------------------------------------------------------------------------------------------------------
; in memory window of the keil micro vision enter address 0x1FFFF100.
; enter random data in to eight sub subsequent addresses, to observe the result
;to observe the result of this LDR R3, [SP,#0x00]; instruction we need to enter values in to 4
; subsequent 8bit data starting from 0x1FFFF160 to 0x1FFFF163 .
;--------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment