Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; CS1022 Introduction to Computing II 2018/2019
- ; Lab 2 - Subarray
- ;
- N EQU 7
- M EQU 3
- AREA RESET, CODE, READONLY
- ENTRY
- ; initialize system stack pointer (SP)
- LDR SP, =0x40010000
- LDR R1, =LARGE_A
- LDR R2, =SMALL_A
- ;
- ; Write your program here to determine whether SMALL_A
- ; is a subarray of LARGE_A
- ;
- ; Store 1 in R0 if SMALL_A is a subarray and zero otherwise
- ;
- MOV R0,#0; boolean subArray = false
- MOV R3,#0;
- forI ;
- CMP R3,#N; for(i = 0; i <array.length;i++)
- BGE endForI;{
- MOV R4,R3; for(j =0;j <array.length;j++)
- forJ ; {
- CMP R4,#N
- BGE endForJ
- MOV R7,#N; r7 = arrayLarge.length
- MUL R7,R3,R7; r7 = i * arrayLarge.length
- ADD R7,R7,R4; index = r7 + coloumn[j]
- LDR R7,[R1,R7,LSL#2];r7 = arrayLarge[i][j]
- MOV R8,#0 ;r8 = 0
- LDR R8,[R2,R8,LSL#2];r8 = arraySmall[0][0] (We do this as we only have to check if the first element of the small array
- ; is equal to the element of the large array. This means we only loop when we have an equal element.
- CMP R7,R8 ;if(arrayLarge[i][j] == arraySmall[0][0]
- BNE notSubArray ;{
- MOV R0,#1 ; subArray = true;
- ; (We set subArray to true. This stays true unless the next indexs are not equal until we reach the end.)
- MOV R9,R3 ; int x =i
- MOV R5,#0 ;
- forK ; for(k = 0; k < arraySmall.length;k++)
- CMP R5,#M ; {
- BGE endForK ;
- MOV R10,R4 ; int y = j
- ;
- MOV R6,#0 ; for(l=0;l<arraySmall.length;l++)
- forL ; {
- CMP R6,#M ; r6 = arraySmall.length
- BGE endForL ;
- MOV R7,#N ; r7 = arrayLarge.length
- MUL R7,R9,R7 ; r7 = x * arrayLarge.length(rowsize)
- ADD R7,R7,R10 ; index = x + coloumn(y)
- LDR R7,[R1,R7,LSL#2]; r7 = arrayLarge[x][y]
- MOV R8,#M ; r8 = arraySmall.length
- MUL R8,R5,R8 ; r8 = k * arrayLarge.length(rowsize)
- ADD R8,R8,R6 ; index = k + coloumn(j)
- LDR R8,[R2,R8,LSL #2]; r8 = arraySmall[k][l]
- CMP R7,R8 ; if(arrayLarge[x][y] != arraySmall[k][l])
- BEQ isEql ; {
- MOV R0,#0 ; subArray = false;
- isEql ; }
- ADD R10,R10,#1 ; y++
- ADD R6,R6,#1 ; }
- B forL ; }
- endForL
- ADD R9,R9,#1 ; x++
- ADD R5,R5,#1 ;}
- B forK ;
- endForK
- notSubArray
- ADD R4,R4,#1;
- B forJ ; }
- endForJ
- ADD R3,R3,#1;
- B forI ;}
- endForI
- STOP B STOP
- ;
- ; test data
- ;
- LARGE_A DCD 48, 37, 15, 44, 3, 17, 26
- DCD 2, 9, 12, 18, 14, 33, 16
- DCD 13, 20, 1, 22, 7, 48, 21
- DCD 27, 19, 44, 49, 44, 18, 10
- DCD 29, 17, 22, 4, 46, 43, 41
- DCD 37, 35, 38, 34, 16, 25, 0
- DCD 17, 0, 48, 15, 27, 35, 11
- SMALL_A DCD 49, 44, 18
- DCD 4, 46, 43
- DCD 34, 16, 25
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement