Skip to content

Commit 2e7fa35

Browse files
committed
part 2 is done
1 parent ebe83e2 commit 2e7fa35

File tree

1 file changed

+46
-52
lines changed

1 file changed

+46
-52
lines changed

Experiment - 3/part2.asm

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,53 @@
1414
*/
1515

1616

17-
18-
; Allocate space in memory for the array
19-
a r r . s p a c e 100
20-
2117
; Initialize registers
22-
mov.w #arr, R10 ; Set R10 to the address of the array
23-
mov.w #1d, R8 ; Initialize R8 as the current number
24-
mov.w #0d, R9 ; Initialize R9 to keep track of the count of divisible numbers
18+
main mov.w #arr, R10 ; Set R10 to the address of the array
19+
mov.w #1d, R8 ; Initialize R8 as the current number
20+
mov.w #0d, R9 ; Initialize R9 to keep track of the count of divisible numbers
2521

2622
; Start the loop to find and store 50 numbers
27-
findNumbers:
28-
; Check if the current number (R8) is divisible by 3 or 4
29-
mov.w R8, R11 ; Copy the current number to R11
30-
mov.w #3d, R12 ; Set R12 to 3
31-
mov.w R11, R13 ; Copy R11 to R13 (to preserve the original number)
32-
mod_divisible:
33-
sub.w R12, R11
34-
jz divisible_by_3 ; If R11 becomes 0, the number is divisible by 3
35-
jn div_by_3_check ; If R11 is negative, it's not divisible by 3
36-
jmp mod_divisible ; Continue the division process
37-
38-
div_by_3_check:
39-
; Check if the current number is divisible by 4
40-
mov.w R13, R11 ; Restore the original number
41-
mov.w #4d, R12 ; Set R12 to 4
42-
mod_divisible_by_4:
43-
sub.w R12, R11
44-
jz divisible_by_4 ; If R11 becomes 0, the number is divisible by 4
45-
jn next_number ; If R11 is negative, it's not divisible by 4
46-
jmp mod_divisible_by_4 ; Continue the division process
47-
48-
divisible_by_3:
49-
; The current number is divisible by 3, store it in the array
50-
mov.w R8, 0(R10) ; Store the divisible number in the array
51-
add.w #2d, R10 ; Move to the next position in the array
52-
inc.w R9 ; Increment the count
53-
jmp next_number ; Move to the next number
54-
55-
divisible_by_4:
56-
; The current number is divisible by 4, store it in the array
57-
mov.w R8, 0(R10) ; Store the divisible number in the array
58-
add.w #2d, R10 ; Move to the next position in the array
59-
inc.w R9 ; Increment the count
60-
61-
next_number:
62-
; Check if we've found 50 divisible numbers
63-
cmp #50d, R9
64-
jeq done ; If we've found 50 numbers, we're done
65-
66-
; Increment the current number and continue the loop
67-
inc.w R8
68-
jmp findNumbers
69-
70-
done:
71-
; End of the program
23+
findNumbers ; Check if the current number (R8) is divisible by 3 or 4
24+
mov.w R8, R11 ; Copy the current number to R11
25+
mov.w #3d, R12 ; Set R12 to 3
26+
mov.w R11, R13 ; Copy R11 to R13 (to preserve the original number)
27+
28+
mod_divisible sub.w R12, R11
29+
jz divisible_by_3 ; If R11 becomes 0, the number is divisible by 3
30+
jn div_by_3_check ; If R11 is negative, it's not divisible by 3
31+
jmp mod_divisible ; Continue the division process
32+
33+
div_by_3_check ; Check if the current number is divisible by 4
34+
mov.w R13, R11 ; Restore the original number
35+
mov.w #4d, R12 ; Set R12 to 4
36+
37+
mod_divisible_by_4 sub.w R12, R11
38+
jz divisible_by_4 ; If R11 becomes 0, the number is divisible by 4
39+
jn next_number ; If R11 is negative, it's not divisible by 4
40+
jmp mod_divisible_by_4 ; Continue the division process
41+
42+
divisible_by_3 ; The current number is divisible by 3, store it in the array
43+
mov.w R8, 0(R10) ; Store the divisible number in the array
44+
add.w #2d, R10 ; Move to the next position in the array
45+
inc.w R9 ; Increment the count
46+
jmp next_number ; Move to the next number
47+
48+
divisible_by_4 ; The current number is divisible by 4, store it in the array
49+
mov.w R8, 0(R10) ; Store the divisible number in the array
50+
add.w #2d, R10 ; Move to the next position in the array
51+
inc.w R9 ; Increment the count
52+
53+
next_number ; Check if we've found 50 divisible numbers
54+
cmp #50d, R9
55+
jeq done ; If we've found 50 numbers, we're done
56+
57+
; Increment the current number and continue the loop
58+
inc.w R8
59+
jmp findNumbers
60+
61+
62+
done ; End of the program
7263

64+
65+
; Allocate space in memory for the array
66+
arr .space 100

0 commit comments

Comments
 (0)