-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmin_max.s
41 lines (40 loc) · 1.48 KB
/
min_max.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
; A program to find minimum and maximum of given values
vals: ; values
DB 0x12
DB 0x34
DB 0x78
DB 0x13
DB 0x99
DB 0x65
DB 0x85
DB 0x11
DB 0x84
DB 0x36
last:DB 0 ; declaring an element to get total number of elements later, and also to separate values from min and max
MIN: DB 0 ; place to store minimum number
MAX: DB 0 ; place to store maximum number
; actual entry point of the program
start:
MOV SI,0 ; move starting point of values in si
MOV CX,OFFSET last ; move number of values to cx
MOV AL, byte [SI] ; move value to al
back:
CMP byte [SI],AL ; compare value to al
JNC skip ; if not smaller, jump to skip
MOV AL,byte [SI] ; move the value to si
skip:
INC SI ; increment counter
loop back ; loop back
mov byte MIN,AL ; move minimum value to MIN
mov SI,0 ; move starting point of values in si
mov CX, OFFSET last ; move number of values to cx
mov AL, byte [SI] ; move value to al
back1:
CMP AL,byte [SI] ; compare al to value
JNC skip1 ; if value is smaller jump to skip1
MOV AL,byte [SI] ; move the value to al
skip1:
INC SI ; increment counter
loop back1 ; loop back1
mov byte MAX,AL ; move the maximum value to MAX
print mem :15 ; print the final state of memory