-
Notifications
You must be signed in to change notification settings - Fork 0
/
DecisionTree.asm
112 lines (95 loc) · 1.86 KB
/
DecisionTree.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
.model small
.stack 100h
.data
temp_prompt db 'Enter temperature (0-100): $'
humid_prompt db 'Enter humidity (0-100): $'
rain_msg db 'Prediction: It will rain$'
no_rain_msg db 'Prediction: It will not rain$'
continue_msg db 'Make another prediction? (y/n): $'
temp dw ?
humid dw ?
.code
main proc
mov ax, @data
mov ds, ax
predict_loop:
; Get temperature
mov dx, offset temp_prompt
mov ah, 9
int 21h
call read_number
mov [temp], ax
; Get humidity
mov dx, offset humid_prompt
mov ah, 9
int 21h
call read_number
mov [humid], ax
; Make prediction
call decision_tree
; Ask to continue
mov dx, offset continue_msg
mov ah, 9
int 21h
mov ah, 1
int 21h
cmp al, 'y'
je predict_loop
; Exit program
mov ah, 4Ch
int 21h
main endp
read_number proc
xor ax, ax
xor cx, cx
read_loop:
mov ah, 1
int 21h
cmp al, 13 ; Check for Enter key
je end_read
sub al, '0'
xor ah, ah
push ax
mov ax, 10
mul cx
mov cx, ax
pop ax
add cx, ax
jmp read_loop
end_read:
mov ax, cx
ret
read_number endp
decision_tree proc
; Check if temperature > 70
mov ax, [temp]
cmp ax, 70
jg high_temp
; Temperature <= 70
mov ax, [humid]
cmp ax, 80
jg predict_rain
jmp predict_no_rain
high_temp:
; Temperature > 70
mov ax, [humid]
cmp ax, 60
jg predict_rain
jmp predict_no_rain
predict_rain:
mov dx, offset rain_msg
jmp display_prediction
predict_no_rain:
mov dx, offset no_rain_msg
display_prediction:
mov ah, 9
int 21h
; New line
mov ah, 2
mov dl, 13
int 21h
mov dl, 10
int 21h
ret
decision_tree endp
end main