-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09.GreatestAndSmallest.asm
More file actions
141 lines (108 loc) · 5.05 KB
/
09.GreatestAndSmallest.asm
File metadata and controls
141 lines (108 loc) · 5.05 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
134
135
136
137
138
139
140
TITLE GreatestAndSmallestNumber
;Program Desctiption: This program receives three numbers and outputs the smallest and the largest numbers
;Author: Liul Alemayehu
.MODEL MEDIUM ; com program, Memory Descriptor (Tiny | Small | Medium | Large)
.STACK 100 ; stack size
.DATA ; Beginning of data segment where data is stored
msg db "Enter Three numbers: $" ; Declare variable msg and assigned it a value ($ used to indicate end of string)
newline db 13,10,'$' ; Creates newline
largestMsg db "The largest number:- $" ; Largest message
smallestMsg db "The smallest number:- $" ; Smallest message
.CODE ; Beginning of code segment
;main PROC
; Start
MOV Ax,@DATA ; Moving address of data (data segment) to Ax register
MOV Ds,Ax ; Initializing of Data segment register (Ds) from Accumilator register (Ax)
; Prompt
LEA Dx,msg ; Loading the effective address of our msg to the Data register (Dx)
MOV Ah,09 ; Print from data
INT 21h ; Does it!
; Read First number
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
SUB Al, 48 ; Changes from ASCII to decimal
MOV Bl,Al ; Moves value from Al to Bl
; Read Second number
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
SUB Al, 48 ; Changes from ASCII to decimal
MOV Cl,Al ; Moves value from Al to Cl
;Read Third number
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
SUB Al, 48 ; Changes from ASCII to decimal
MOV Ch,Al ; Moves value from Al to Dh
; Check if ENTER is pressed
MOV AH,01 ; Reads an input String to the Accumilator register (high)
INT 21h ; Does it!
CMP Al,13 ; Compare the input in the Accumilator registor to the ASCII value of the ENTER key (13)
JE Enter ; Jumps to 'Enter' label if the CMP is equal
JMP Exit ; Jumps to 'Exit' label otherwise
; Enter Pressed
Enter:
CALL largest ; Calls the 'largest' procedure
; Print largest number
; Newline
LEA Dx,newline
MOV Ah,09h
INT 21h
; Print largest message
LEA Dx,largestMsg ; Loading the effective address of our message to the Data register (Dx)
MOV Ah,09 ; Print from data
INT 21h ; Does it!
; Print value
MOV Ah,02 ; Prints to screen
ADD Bh,48 ; Changes value in Bh to decimal
MOV Dl,Bh ; Moves it to Dl
INT 21h ; Does it
CALL smallest ; Calls the 'smallest' procedure
;Print smallest number
; Newline
LEA Dx,newline
MOV Ah,09h
INT 21h
; Print smallest message
LEA Dx,smallestMsg ; Loading the effective address of our message to the Data register (Dx)
MOV Ah,09 ; Print from data
INT 21h ; Does it!
; Print value
MOV Ah,02 ; Prints to screen
ADD Bh,48 ; Changes value in Bh to decimal
MOV Dl,Bh ; Moves it to Dl
INT 21h ; Does it
JMP Exit
;...................... PROCEDURES ............................
; largest
largest PROC
MOV Bh,Bl
CMP Bh,Cl
JG next
MOV Bh,Cl
next:
CMP Bh,Ch
JG next2
MOV Bh,Ch
next2:
MOV Al,Bh
RET
largest ENDP
; smallest
smallest PROC
MOV Bh,Bl
CMP Bh,Cl
JL nexxt
MOV Bh,Cl
nexxt:
CMP Bh,Ch
JL nexxt2
MOV Bh,Ch
nexxt2:
MOV Al,Bh
RET
smallest ENDP
;...................... PROCEDURES ............................
Exit:
MOV Ah,4Ch ; Exit
INT 21h ; Does it!
;main ENDP
END main