This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab 6.asm
155 lines (142 loc) · 3.11 KB
/
Lab 6.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
; Ryan Schlimme
; 06 April 2022
; Lab 6
; This program prompts the user for a court number (max 7 uppercase and numeric characters) and searches two linked lists of courses.
; If there is a match in the first list, it will print "<Course Number> is already being offered this semester." and if there is
; a match in the second list, it will add the course number to the first list and print, "<Course Number> has been added to this
; semester's course offerings." If there is not a match in either, it will print "The entered Course Number does not exist in the
; current course catalog." Course numbers are formatted as follows: 1-3 uppercase letters, 3 digits, an optional uppercase letter,
; NO SPACES.
.ORIG x3000
; Prompt Algorithm
LEA R0, Prompt
PUTS
LEA R1, CODE
LoopStart
AND R2, R2, #0; Load a register with ASCII of enter key
ADD R2, R2, x0A
GETC; Get a character and print to console
OUT
STR R0, R1, #0; Store character in memory
ADD R1, R1, #1; Increment memory pointer
NOT R0, R0; Subtract key value from register with enter
ADD R0, R0, #1
ADD R2, R0, R2
BRnp LoopStart; If value is not enter, loop
; Clear enter from memory
ADD R1, R1, #-1
STR R2, R1, #0
; End of Prompt Algorithm
; Search/Compare Algorithm 1
LD R0, DATA
LDR R1, R0, #0
BRz NoMatch
LDR R0, R1, #0
LEA R4, CODE
BRnzp NextNode
Loop1
LDR R1, R0, #0
LDR R2, R0, #1
BRz NextNode
CompareLoop
LDR R3, R2, #0
BRnp Fail1
LDR R5, R4, #0
BRz Match2
Fail1
LDR R5, R4, #0
NOT R5, R5
ADD R5, R5, #1
ADD R3, R3, R5
BRnp NextNode
ADD R4, R4, #1
ADD R2, R2, #1
BRnzp CompareLoop
Next
ADD R0, R0, #1
ADD R4, R4, #1
BRnzp Loop1
NextNode
LEA R4, CODE
ADD R0, R1, #0
ADD R0, R0, #0
BRnp Loop1
; End of Search/Compare Algorithm `
; Search/Compare Algorithm 2
NoMatch
AND R6, R6, #0; Initialize a counter register
LD R0, DATA
ADD R0, R0, #1; Increment to course catalog list
LDR R1, R0, #0
BRz NoMatch2
BRnp NextNode2
Loop2
LDR R1, R0, #0
LDR R2, R0, #1
BRz NextNode2
CompareLoop2
LDR R3, R2, #0
BRnp Fail2
LDR R5, R4, #0
BRz Match2
Fail2
LDR R5, R4, #0
NOT R5, R5
ADD R5, R5, #1
ADD R3, R3, R5
BRnp NextNode2
ADD R4, R4, #1
ADD R2, R2, #1
BRnzp CompareLoop2
Next2
ADD R0, R0, #1
ADD R4, R4, #1
BRnzp Loop2
NextNode2
LEA R4, CODE
ADD R6, R0, #0
ADD R0, R1, #0
BRnp Loop2
BRz NoMatch2
; End of Search Compare/Algorithm 2
; Response Algorithm
; If there is a match in search 1
Match
ADD R5, R5, #0
BRnp NoMatch
LEA R0, CODE
PUTS
LEA R0, YesResponse
PUTS
BRnzp EndProgram
; If there is a match in search 2
Match2
; NODE DELETION
LDR R3, R0, #0
STR R3, R6, #0
; NODE INSERTION
LD R1, DATA
LDR R1, R1, #0
STR R1, R0, #0
LD R1, DATA
STR R0, R1, #0
LEA R0, CODE
PUTS
LEA R0, Yes2Response
PUTS
BRnzp ENDProgram
; If there is not a match in either
NoMatch2
LEA R0, NoMatchResponse
PUTS
BRnzp EndProgram
; End of Response Algorithm
EndProgram HALT
DATA .FILL x4000
NextDATA .FILL x4001
CODE .BLKW #8
Prompt .STRINGZ "Type Course Number and press Enter: "
YesResponse .STRINGZ " is already being offered this semester."
Yes2Response .STRINGZ " has been added to this semester's course offerings."
NoMatchResponse .STRINGZ "The entered Course Number does not exist in the current course catalog."
.END