-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmycodeForPractical.asm
More file actions
174 lines (121 loc) · 3.28 KB
/
mycodeForPractical.asm
File metadata and controls
174 lines (121 loc) · 3.28 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
.model small
.stack
.data
;data declaration for (Bubble Sort) function
dataSet db 5h, 2h, 4h, 3h, 1h, 14h, 23h, 11h, 6h, 10h, 7h, 13h, 16h, 10h, 1h
dataSetSize dw 15 ;Size of the dataSet
whileLoopControl dw ?
;---------------------------
;data for exploration
datas dw 12h, 3, 01ABh, 100h
;---------------------------
;data for Exer2
y dw ? ; y-int
m dw 5h ; slope
x dw 3h ; x-int
b dw 0Ah
;---------------------------
;data for Exer3
numFac dw 5 ;Number to be factor out
;---------------------------
;data for Exer4
numToTest dw 5h
divCtr dw 0
divisorHolder dw ?
myBoolPrime dw 0 ;1 = prime 0 = not prime
;---------------------------
.code
main proc near
Mov AX, @Data
Mov DS, AX
Mov ES, AX
;--------------------------
;----calling function -----
;call practice
;call Exer2
;call Exer3
;call Exer4
;--------------------------
;------ Cmp and Jmps ------
;mov DH, 5
;mov DL, 5
;cmp DH, DL
;jne callShit
;mov DX, 00h
;callShit:
; call practice
;--------------------------
;---- Termination code----
Mov AX, 4C00H
int 21H
main endp
; Practice problem (Bubble Sort)
practice proc near
myWhileLoop:
Mov whileLoopControl, 0
Dec dataSetSize
Mov CX, dataSetSize
Lea SI, dataSet
myForLoop:
Mov BH, [SI]
Mov BL, [SI+1]
Cmp BH, BL
Jbe skipSwapping
Mov whileLoopControl, 2
xchg BH, BL
Mov [SI], BH
Mov [SI+1], BL
skipSwapping:
Inc SI
loop myForLoop
Mov CX, whileLoopControl
Jcxz skipLoop
loop myWhileLoop
skipLoop:
ret
practice endp
;Slope of a Line
Exer2 proc near
Mov AX, m
Mov BX, x
Mul BX
Add AX, b
Mov y, AX
ret
Exer2 endp
;Factorial
Exer3 proc near
Mov AX, numFac
myLoop:
Dec numFac
Mov CX, numFac
Mul CX
loop myLoop
Mov DX, AX ; Factorial of numFac
ret
Exer3 endp
;Prime numbers
Exer4 proc near
; Get the number half of the number to serve as starting divisors
Mov AX, numToTest
Mov CX, 2
Div CX
Mov divisorHolder, AX
myPrimeTester:
Mov AX, numToTest
Mov CX, divisorHolder
Div CX
Cmp DX, 0
Jnz SkipCtr
Inc divCtr
SkipCtr:
dec divisorHolder
Loop myPrimeTester
Mov BX, divCtr
Cmp BX, 1
Jne notPrime
Mov myBoolPrime, 1
notPrime:
Mov DX, myBoolPrime
ret
Exer4 endp