;ex4_2400 exercises for chapter 4 of  CENG2400. It is for your own revision purpose,no need to submit answers to tutors.
;1) create a project based on this .s code
;2) In keil-ide, use project/rebuild all target files to build the project
;3) use Debug/run_to_cursor_line to run the top line of the program, 
;4)  use the single step mode to view the memory locations (in DEbug mode/view/memory_wndows)from 0x4000000 to 0x40000013, registers and cpsr after the execution of each statement.
;5) Explain the observations and results.


; declare variables	  New test12D
   		AREA	|.data|, DATA, READWRITE
Table1 DCD 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 ,0x1, 0x1
Table2 DCD 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 ,0x1, 0x1
		align
;-------------------------------------------------------------

; User Initial Stack & Heap
		
        AREA    |.text|, CODE, READONLY

        EXPORT  __main
__main	
;clear flags

memory_init	 ; set the memory content in table1
		LDR r1, =Table1
		LDR r2, =Table2
		MOV r3,#0
		MOV r0,#0x00
loop	ADD r0,r0,#0x11
		STR r0,[r1]
		ADD r1,r1,#4
		ADD r3,r3,#1
		CMP r3,#10
		BNE loop
		NOP
		NOP



ex4_1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		BL memory_reset	
		LDR r1,=Table1
		LDR r2,=Table2
		LDR r0, [r1]
		STR r0, [r2]
		NOP
		NOP


ex4_2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		BL memory_reset	
		LDR r1,=Table1
		LDR r2,=Table2
		MOV r3, #0
loop1 	LDR r0,[r1]
		STR r0,[r2]
		ADD r1,r1,#4
		ADD r2,r2,#4
		ADD r3,r3,#1
		CMP r3,#5
		BNE loop1
		NOP
		NOP

ex4_3;;;;;;;;
		BL memory_reset	
		LDR r1,=Table1
		LDR r2,=Table2
		LDR r0,[r1]
		STR r0,[r2]
		LDR r0,[r1,#4]
		STR r0,[r2,#4]
		NOP
		NOP

ex4_4;;;;;;;;
		BL memory_reset	
		LDR r1,=Table1
		LDR r2,=Table2
		LDR r0,[r1]
		STR r0,[r2]
		LDR r0,[r1,#4]!
		STR r0,[r2,#4]!
		NOP
		NOP

memory_reset   ; reset the content in table2 to be all 0
		LDR r5,=Table2
		MOV r6,#0
		MOV r7,#0
loop2	STR r6,[r5]
		ADD r5,r5,#4
 		ADD r7,r7,#1
		CMP r7,#10
		BNE loop2
		BX LR

	   END
