2023-SC2-COS10031-Computer Technology
WEEK 10
Name- Manuja sellahewa
Swin Id- 104853169
10.1.1
1| MOV R1, #.red
2| STR R1, .Pixel32
3| STR R1, .Pixel33
4| STR R1, .Pixel34
5| STR R1, .Pixel35
6| STR R1, .Pixel36
7| STR R1, .Pixel37
8| STR R1, .Pixel38
9| STR R1, .Pixel39
10| STR R1, .Pixel40
11| STR R1, .Pixel41
12| STR R1, .Pixel42
13| STR R1, .Pixel43
14| STR R1, .Pixel44
15| STR R1, .Pixel45
16| STR R1, .Pixel46
17| STR R1, .Pixel47
18| STR R1, .Pixel48
19| STR R1, .Pixel49
20| STR R1, .Pixel50
21| STR R1, .Pixel51
22| MOV R1, #.red
23| STR R1, .Pixel15
24| STR R1, .Pixel47
25| STR R1, .Pixel79
26| STR R1, .Pixel111
27| STR R1, .Pixel143
28| STR R1, .Pixel175
29| STR R1, .Pixel207
30| STR R1, .Pixel239
31| STR R1, .Pixel271
32| STR R1, .Pixel303
33| STR R1, .Pixel335
34| STR R1, .Pixel367
35| STR R1, .Pixel399
36| STR R1, .Pixel431
37| STR R1, .Pixel463
38| STR R1, .Pixel495
39| STR R1, .Pixel527
40| STR R1, .Pixel559
41| STR R1, .Pixel591
42| STR R1, .Pixel623
43| HALT
10.1.3
a)
I have used indirect addressing. After calculating the byte offset for the next pixel and then store it in the R4.
After that, it loads to the memory location which is pointed by R4 into R5 using the LDR R5[R4] . After that by
using STR R2, R[5] instructions it will store the value R2 into the memory location of R5
b)
1| MOV R1, #.PixelScreen // base address of the medium and high res pixel display memory 2| MOV R2, #.red
3| MOV R3, #256
4|loop:
5| ADD R4, R1, R3 // calculate the byte offset (R1 + R3) for the next pixel and store new address in R4 6| STR R2,
[R4]
7| ADD R3,R3,#4
8| CMP R3, #336
9| BLT loop 10| HALT
c)
1| MOV R1, #.PixelScreen // base address of the medium and high res pixel display memory 2| MOV R2,
#.red
3| MOV R3, #256
4| MOV R5, #124
5|loop:
6| ADD R4, R1, R3 // calculate the byte offset (R1 + R3) for the next pixel and store new address in R4
7| STR R2, [R4]
8| ADD R3,R3,#4
9| CMP R3, #336
10| BLT loop 11|loop1:
12| ADD R6, R1,R5
13| STR R2, [R6]
14| ADD R5,R5,#256
15| CMP R5,#5376
16| BLT loop1 17| HALT
10.2.1
1| MOV R1,
#.PixelScreen 2| MOV
R2, #.red
3| MOV R3, #0
4|loop: ADD R4, R1, R3
5| STR R2, [R4]
6| ADD R3,R3,#4
7| CMP R3, #80
8| BLT loop
9| HALT
10.2.2
1| MOV R1, #.PixelScreen 2| MOV R2, #.red
3| MOV R3, #0
4| MOV R5, #80
5|loop:
6| STR R2, [R1 + R3]
7| ADD R3,R3,#4
8| CMP R3, R5
9| BLT loop
10| ADD R3, R3,#176
11| ADD R5, R5,#256
12| CMP R5, #2640
13| BEQ stop
14| B loop 15|stop:
16| HALT
10.3.1
a) Ensure the subsequent data that have been aligned on a 256-byte memory boundary is the purpose of this.
It will optimize the memory access and potentially improves performance
b)
1| MOV R1, #arrayData
2| LDR R0, [R1 + #16]
3| HALT
4| .ALIGN 256
5|arrayLength: 10
6|arrayData: .Word 9
7| 8
8| 7
9| 6
10| 5
11| 4
12| 3
13| 2
14| 1
15| 0
c)
1| MOV R2, #arrayData
2| MOV R1, #16
3| LDR R0, [R2 + R1]
4| HALT
5| .ALIGN 256
6|arrayLength: 10
7|arrayData: .Word 9
8| 8
9| 7
10| 6
11| 5
12| 4
13| 3
14| 2
15| 1
16| 0
10.3.2 and 10.3.3
1| MOV R1, #arrayData 2| MOV R2, #0
3| MOV R0, #0
4|loop:
5| LDR R3, [R1 + R2]
6| ADD R0, R0, R3
7| ADD R2, R2,#4
8| CMP R2, #arrayLength 9| BLT loop
10| STR R0, .WriteSignedNum 11| HALT
12| .ALIGN 256
13|arrayLength: 10
14|arrayData: .Word 9
15| 8
16| 7
17| 5
18| 6
19| 4
20| 2
21| 1
22| 0
10.4.1
1| MOV R1,
#arrayData 2| MOV
R2, #36
3| MOV R0,
#reversearray 4| MOV
R4, #0
5| MOV R5, #0
6|loop:
7| LDR R3, [R1 + R2]
8| STR R3, [R0 + R4]
9| SUB R2, R2,#4
10| ADD R4, R4,#4
11| CMP R2, #0
12| BGT loop
13| CMP
R2,#0
14| BEQ
loop 15|loop1:
16| LDR R3, [R0 + R5]
17| STR R3,
.WriteSignedNum 18| ADD
R5, R5,#4
19| CMP R5, #40
20| BLT
loop1 21|
HALT
22| .ALIGN 256
23|arrayLength: 10
24|arrayData: .Word 9
25| 8
26| 7
27| 6
28| 5
29| 4
30| 3
31| 2
32| 1
33| 0
34|reversearray: .Word 0
35| 0
36| 0
37| 0
38| 0
39| 0
40| 0
41| 0
42| 0
43| 0
10.4.2
1| MOV R1, #arrayData 2| MOV R2, #0
3| MOV R0, #0
4| MOV R4, #36
5| MOV R6, #0
6|loop:
7| LDR R3, [R1 + R2]
8| LDR R5, [R1 + R4]
9| MOV R0,R3
10| MOV R3,R5
11| MOV R5,R0
12| ADD R2, R2,#4
13| SUB R4,R4,#4
14| CMP R2, #arrayLength 15| BLT loop
16|loop1:
17| LDR R3, [R1 + R6]
18| STR R3, .WriteSignedNum 19| ADD R6, R6,#4
20| CMP R6, #40
21| BLT loop1 22| HALT
23| .ALIGN 256
24|arrayLength: 10
25|arrayData: .Word 9
26| 8
27| 7
28| 6
29| 5
30| 4
31| 3
32| 2
33| 1
34| 0