-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount1s.s
More file actions
48 lines (40 loc) · 1.33 KB
/
Copy pathcount1s.s
File metadata and controls
48 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
.syntax unified
.cpu cortex-m4
.thumb
.global Main
Main:
@
@ write your program here
@
MOV R0 , #0 @ value =0
MOV R3 , #0 @ result = 0 ;
MOV R4 , #0 @ onesRow = 0 ;
MOV R5 , #32 @ b = 32
MOV R6 , #1
For : @ for ( result = 0 ; result < 32 ; result ++)
CMP R3 , R5
BHS EndFor
MOVS R1 ,R1, LSL R6 @ ( shift the bits to the left )
BCC ElseIf @ { if ( BSS) {
ADD R4, R4, R6 @ onesRow = onesRow + 1
ElseIf : @ else if {
BCS EndIf @ if ( onesRow > value )
CMP R4, R0
BLE EndIf2
MOV R0 , #0 @ value = 0 ;
ADD R0, R0, R4 @ value = value + onesRow
EndIf2 :
MOV R4, #0 @ onesRow = 0 ;
EndIf :
ADD R3, R6 @ result = result + 1 ;
B For
EndFor :
CMP R4, R0 @ if ( onesRow > value )
BLE End
MOV R0 ,#0 @ value = 0 ;
ADD R0,R0, R4 @ value = value + onesRow
End :
@ End of program ... check your result
End_Main:
BX lr
.end