-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_only_odd_of_array.asm
72 lines (61 loc) · 1.32 KB
/
print_only_odd_of_array.asm
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
.data
array: .space 2000 #2000 bytes
space: .asciiz" "
Size: .asciiz"Enter the number of integers less than 500: "
inputMsg: .asciiz"\nEnter the elements of array: "
oddMsg: .asciiz"\nOdd numbers of the Array: "
.text
main:
#print string Size
li $v0,4
la $a0,Size
syscall
#Number of input
li $v0,5 #for taking input
syscall
move $s1,$v0 #s1=5 integers
mul $s1,$s1,4 #s1=20 bytes
addi $s2,$zero,2 #for finding reminder
#printing inputMsg, asking for elements of the array
li $v0,4
la $a0, inputMsg
syscall
addi $s0,$zero,0
inputLoop:
#s0 will be 0,4,8,12,16.... if S0==20, exit the loop
beq $s0,$s1, output #S0==s1, go to output, finished taking input
li $v0,5 #taking input
syscall
move $t1,$v0
#store value in array
sw $t1, array($s0) #array[0]= $t1 0,4,8,12,16
addi $s0,$s0,4
j inputLoop
output:
#printing outputMsg
li $v0,4
la $a0,oddMsg
syscall
addi $s0,$zero,0
printLoop:
beq $s0,$s1,Exit
lw $s3, array($s0)
div $s3,$s2 #lo=(quotient), hi=$s2 (reminder)
mfhi $s4 #s4=reminder
#checking even or not
bnez $s4, printOdd #if reminder!=0,then odd
#increment index, s0= s0+4
addi $s0,$s0,4
j printLoop
printOdd:
li $v0,1
move $a0,$s3
syscall
li $v0,4
la $a0, space
syscall
addi $s0,$s0,4
j printLoop
Exit:
li $v0,10
syscall