-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_4_2a.s
49 lines (36 loc) · 1.04 KB
/
lab_4_2a.s
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
.text
.globl main
main:
# start of main program
la $a0, prompt
li $v0, 4
syscall # display "Enter integer number :"
li $v0, 5
syscall # read integer
move $a0, $v0 # Pass the integer as an argument to the recursive procedure
jal recursive # Call the recursive procedure
# Continue with displaying the end of line and exiting
la $a0, endl
li $v0, 4
syscall # display end of line
li $v0, 10
syscall # exit
# end of main program
# start of procedure
recursive:
# Check if the integer is zero
beq $a0, $zero, end_recursive # If the integer is zero, return
# Print the value of the integer
move $a0, $a0
li $v0, 1
syscall
# Decrement the integer by one
sub $a0, $a0, 1
# Recursive call to the procedure
jal recursive
end_recursive:
jr $ra # Return to the caller
# end of procedure
.data
prompt: .asciiz "Enter integer number :"
endl: .asciiz "\n"