Repository navigation
Expand file tree
/
Copy pathTaskManagerAPP.asm
More file actions
133 lines (104 loc) · 2.3 KB
/
Copy pathTaskManagerAPP.asm
File metadata and controls
133 lines (104 loc) · 2.3 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
.data
task_titles: .space 100 # space for 5 titles, 20 chars each
task_flags: .space 20 # space for 20 flags (0/1)
task_count: .word 0
newline: .asciiz "\n"
menu: .asciiz "\n1. Add Task\n2. Complete Task\n3. Show Tasks\n4. Exit\nChoose: "
enter_title: .asciiz "Enter task title: "
enter_index: .asciiz "Enter task number: "
completed_msg: .asciiz "Task marked complete.\n"
invalid_msg: .asciiz "Invalid choice.\n"
task_list_hdr: .asciiz "\n--- Task List ---\n"
.text
.globl main
main:
# menu loop
menu_loop:
li $v0, 4
la $a0, menu
syscall
li $v0, 5 # read int
syscall
move $t0, $v0 # choice
beq $t0, 1, add_task
beq $t0, 2, complete_task
beq $t0, 3, show_tasks
beq $t0, 4, exit_program
# invalid choice
li $v0, 4
la $a0, invalid_msg
syscall
j menu_loop
# --- Add Task ---
add_task:
# ask for title
li $v0, 4
la $a0, enter_title
syscall
li $v0, 8 # read string
la $a0, task_titles
li $a1, 20 # max length
syscall
# store completion flag = 0
la $t1, task_flags
lw $t2, task_count
sll $t3, $t2, 2
add $t1, $t1, $t3
sw $zero, 0($t1)
# increment task_count
lw $t2, task_count
addi $t2, $t2, 1
sw $t2, task_count
j menu_loop
# --- Complete Task ---
complete_task:
li $v0, 4
la $a0, enter_index
syscall
li $v0, 5 # read int
syscall
move $t1, $v0 # task number
lw $t2, task_count
bge $t1, $t2, invalid_complete
# mark complete
la $t3, task_flags
sll $t4, $t1, 2
add $t3, $t3, $t4
li $t5, 1
sw $t5, 0($t3)
li $v0, 4
la $a0, completed_msg
syscall
j menu_loop
invalid_complete:
li $v0, 4
la $a0, invalid_msg
syscall
j menu_loop
# --- Show Tasks ---
show_tasks:
li $v0, 4
la $a0, task_list_hdr
syscall
lw $t0, task_count
li $t1, 0
show_loop:
beq $t1, $t0, menu_loop
# print task index
li $v0, 1
move $a0, $t1
syscall
# print ": "
li $v0, 4
la $a0, newline
syscall
# (for simplicity: printing one title here, expand for all tasks)
li $v0, 4
la $a0, task_titles
syscall
addi $t1, $t1, 1
j show_loop
# --- Exit ---
exit_program:
li $v0, 10
syscall