├── .gitattributes
├── .gitignore
├── Intel-Assembly-Language-Programming-Exercises.sln
├── Intel-Assembly-Language-Programming-Exercises
├── 3_1_IntegerExpressionCalculation.asm
├── 3_2_SymbolicIntegerConstants.asm
├── 4_1_ConvertingfromBigEndiantoLittleEndian.asm
├── 4_2_ExchangingPairsofArrayValues.asm
├── 4_3_SummingtheGapsbetweenArrayValues.asm
├── 4_4_CopyingaWordArraytoaDoubleWordarray.asm
├── 4_5_FibonacciNumbers.asm
├── 4_6_ReverseanArray.asm
├── 4_7_CopyaStringinReverseOrder.asm
├── 4_8_ShiftingtheElementsinanArray.asm
├── 5_10_FibonacciGenerator.asm
├── 5_11_FindingMultiplesofK.asm
├── 5_1_DrawTextColours.asm
├── 5_2_LinkingArrayItems.asm
├── 5_3_SimpleAddition(1).asm
├── 5_4_SimpleAddition(2).asm
├── 5_5_BetterRandomRangeProcedure.asm
├── 5_6_RandomString.asm
├── 5_7_RandomScreenLocations.asm
├── 5_8_ColourMatrix.asm
├── 5_9_RecursiveProcedure.asm
├── 6_10_ParityChecking.asm
├── 6_1_FillinganArray.asm
├── 6_2_SummingArrayElementsinaRange.asm
├── 6_3_TestScoreEvaluation.asm
├── 6_4_CollegeRegistration.asm
├── 6_5-6_BooleanCalculator.asm
├── 6_7_ProbabilitiesandColours.asm
├── 6_8_MessageEncryption.asm
├── 6_9_ValidatingaPIN.asm
├── 7_1_DisplayASCIIDecimal.asm
├── 7_2_ExtendedSubtractionProcedure.asm
├── 7_3_PackedDecimalConversion.asm
├── 7_4_EncryptionUsingRotateOperations.asm
├── 7_5_PrimeNumbers.asm
├── 7_6_GCD.asm
├── 7_7_BitwiseMultiplication.asm
├── Board_main.asm
├── Inputs_main.asm
├── Intel-Assembly-Language-Programming-Exercises.lst
├── Intel-Assembly-Language-Programming-Exercises.vcxproj
├── Intel-Assembly-Language-Programming-Exercises.vcxproj.filters
├── Largest_main.asm
├── Threes_main.asm
├── _differentinputs.asm
├── _display.asm
├── _drawboard.asm
├── _drawrow.asm
├── _drawsquare.asm
├── _findlargest.asm
├── _findthrees.asm
├── board.inc
├── inputs.inc
├── largest.inc
└── threes.inc
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27703.2000
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Intel-Assembly-Language-Programming-Exercises", "Intel-Assembly-Language-Programming-Exercises\Intel-Assembly-Language-Programming-Exercises.vcxproj", "{48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}.Debug|x64.ActiveCfg = Debug|x64
17 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}.Debug|x64.Build.0 = Debug|x64
18 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}.Debug|x86.ActiveCfg = Debug|Win32
19 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}.Debug|x86.Build.0 = Debug|Win32
20 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}.Release|x64.ActiveCfg = Release|x64
21 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}.Release|x64.Build.0 = Release|x64
22 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}.Release|x86.ActiveCfg = Release|Win32
23 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {07600966-0537-4455-B7F3-BC13C218AB8B}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/3_1_IntegerExpressionCalculation.asm:
--------------------------------------------------------------------------------
1 | TITLE Integer Expression Calculation
2 | ; This program calculates the following expression, using registers:
3 | ; val1 = (val1 + val2) - (val3 + val4).
4 |
5 | INCLUDE Irvine32.inc
6 |
7 | .DATA
8 | description BYTE "This program will calculate the integer expression A = ",0
9 | expression BYTE "(A + B) - (C + D)",0
10 |
11 | .DATA?
12 | val1 DWORD ?
13 | val2 DWORD ?
14 | val3 DWORD ?
15 | val4 DWORD ?
16 | result DWORD ?
17 |
18 | .CODE
19 | main PROC
20 | call Clrscr
21 | mov edx,OFFSET description
22 | call Writestring
23 | mov edx,OFFSET expression
24 | call Writestring
25 | call Crlf
26 | call Crlf
27 |
28 | call GetInput
29 | call CalculateExpression
30 | call Output
31 |
32 | call Crlf
33 |
34 | exit
35 | main ENDP
36 |
37 | .DATA
38 | prompt1 BYTE "Please enter integer A: ",0
39 | prompt2 BYTE "Please enter integer B: ",0
40 | prompt3 BYTE "Please enter integer C: ",0
41 | prompt4 BYTE "Please enter integer D: ",0
42 |
43 | .CODE
44 | ; Receives: prompt1, prompt2, prompt3, prompt4
45 | ; Returns: val1, val2, val3, val4
46 | GetInput PROC USES eax edx
47 | mov edx,OFFSET prompt1
48 | call Writestring
49 | call Readint
50 | mov val1,eax
51 | call Crlf
52 |
53 | mov edx,OFFSET prompt2
54 | call Writestring
55 | call Readint
56 | mov val2,eax
57 | call Crlf
58 |
59 | mov edx,OFFSET prompt3
60 | call Writestring
61 | call Readint
62 | mov val3,eax
63 | call Crlf
64 |
65 | mov edx,OFFSET prompt4
66 | call Writestring
67 | call Readint
68 | mov val4,eax
69 | call Crlf
70 |
71 | ret
72 | GetInput ENDP
73 |
74 | ; Receives: val1, val2, val3, val4
75 | ; Returns: result = calculated expression
76 | CalculateExpression PROC USES eax ebx ecx edx
77 | mov eax,val1
78 | mov ebx,val2
79 | mov ecx,val3
80 | mov edx,val4
81 |
82 | add eax,ebx
83 | add ecx,edx
84 | sub eax,ecx
85 |
86 | mov result,eax
87 |
88 | ret
89 | CalculateExpression ENDP
90 |
91 | .DATA
92 | equals BYTE " = ",0
93 |
94 | .CODE
95 | ; Receives: result
96 | Output PROC USES eax edx
97 | mov edx,OFFSET expression
98 | call WriteString
99 | mov edx,OFFSET equals
100 | call WriteString
101 | mov eax,result
102 | call WriteInt
103 | call Crlf
104 |
105 | ret
106 | Output ENDP
107 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/3_2_SymbolicIntegerConstants.asm:
--------------------------------------------------------------------------------
1 | TITLE Symbolic Integer Constants
2 | ; This program defines symbolic constants for all seven days of the week
3 | ; and creates an array variable that uses the symbols as initialisers.
4 |
5 | INCLUDE Irvine32.inc
6 |
7 | SUN EQU <"Sunday",0>
8 | MON EQU <"Monday",0>
9 | TUE EQU <"Tuesday",0>
10 | WED EQU <"Wednesday",0>
11 | THU EQU <"Thursday",0>
12 | FRI EQU <"Friday",0>
13 | SAT EQU <"Saturday",0>
14 | NUMBER_OF_DAYS = 7
15 |
16 | .DATA
17 | weekdays BYTE SUN,MON,TUE,WED,THU,FRI,SAT
18 |
19 | .CODE
20 | main PROC
21 | call Clrscr
22 | mov edi,OFFSET weekdays
23 | mov ecx,NUMBER_OF_DAYS
24 |
25 | PrintDay:
26 | mov edx,edi
27 | call Writestring
28 | call Crlf
29 | FindNextNumber:
30 | inc edi
31 | cmp BYTE PTR [edi],0
32 | jnz FindNextNumber
33 | inc edi
34 | loop PrintDay
35 |
36 | exit
37 | main ENDP
38 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/4_1_ConvertingfromBigEndiantoLittleEndian.asm:
--------------------------------------------------------------------------------
1 | TITLE Converting from Big Endian to Little Endian
2 | ; This program copies the value from bigEndian to littleEndian, reversing
3 | ; the order of the bytes
4 |
5 | INCLUDE Irvine32.inc
6 |
7 | .DATA
8 | ; The number's 32-bit value is understood to be 12345678 hexadecimal
9 | bigEndian BYTE 12h,34h,56h,78h
10 |
11 | .DATA?
12 | littleEndian DWORD ?
13 |
14 | .DATA
15 | bigEndianMem BYTE "The data definition:",0Dh,0Ah,0Dh,0Ah
16 | BYTE " bigEndian BYTE 12h,34h,56h,78h",0Dh,0Ah,0Dh,0Ah
17 | BYTE "is stored in memory as follows:",0Dh,0Ah,0
18 | bigEndianDWORD BYTE 0Dh,0Ah
19 | BYTE "When represented as a DWORD, this is its value:"
20 | BYTE 0Dh,0Ah,0
21 | littleEndianMem BYTE "After reversing the order of the bytes, this is how "
22 | BYTE "the littleEndian variable is stored in memory:"
23 | BYTE 0Dh,0Ah,0
24 | littleEndianDWORD BYTE 0Dh,0Ah
25 | BYTE "and this is its DWORD representation:",0Dh,0Ah,0
26 |
27 | .CODE
28 | main PROC
29 | call Clrscr
30 | mov edx,OFFSET bigEndianMem
31 | call Writestring
32 | mov esi,OFFSET bigEndian
33 | mov ecx,LENGTHOF bigEndian
34 | mov ebx,TYPE bigEndian
35 | call DumpMem
36 | mov edx,OFFSET bigEndianDWORD
37 | call Writestring
38 | mov esi,OFFSET bigEndian
39 | mov ecx,1
40 | mov ebx,TYPE DWORD
41 | call DumpMem
42 |
43 | mov al,bigEndian[3]
44 | mov ah,bigEndian[2]
45 | mov WORD PTR littleEndian,ax
46 | mov al,bigEndian[1]
47 | mov ah,bigEndian
48 | mov WORD PTR littleEndian[2],ax
49 |
50 | call Crlf
51 | mov edx,OFFSET littleEndianMem
52 | call WriteString
53 | mov esi,OFFSET littleEndian
54 | mov ecx,4
55 | mov ebx,TYPE BYTE
56 | call DumpMem
57 | mov edx,OFFSET littleEndianDWORD
58 | call WriteString
59 | mov esi,OFFSET littleEndian
60 | mov ecx,LENGTHOF littleEndian
61 | mov ebx,TYPE littleEndian
62 | call DumpMem
63 |
64 | call Crlf
65 |
66 | exit
67 | main ENDP
68 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/4_2_ExchangingPairsofArrayValues.asm:
--------------------------------------------------------------------------------
1 | TITLE Exchanging Pairs of Array Values
2 | ; This program exchanges every pair of values in an array with an even
3 | ; number of elements using a loop and indexed addressing.
4 |
5 | INCLUDE Irvine32.inc
6 |
7 | .DATA
8 | intArray DWORD 10000h,20000h,30000h,40000h
9 | introduction BYTE "This is the original array:",0
10 | conclusion BYTE "This is the array with swapped elements:",0
11 |
12 | .CODE
13 | main PROC
14 | call Clrscr
15 | mov edx,OFFSET introduction
16 | call Writestring
17 | call Crlf
18 | mov esi,OFFSET intArray
19 | mov ecx,LENGTHOF intArray
20 | mov ebx,TYPE intArray
21 | call DumpMem
22 |
23 | mov edi,OFFSET intArray
24 | mov ecx,LENGTHOF intArray / 2
25 | SwapElements:
26 | mov eax,[edi]
27 | mov ebx,[edi + TYPE intArray]
28 | mov [edi],ebx
29 | add edi,TYPE intArray
30 | mov [edi],eax
31 | add edi,TYPE intArray
32 | loop SwapElements
33 |
34 | call Crlf
35 | mov edx,OFFSET conclusion
36 | call Writestring
37 | call Crlf
38 | mov esi,OFFSET intArray
39 | mov ecx,LENGTHOF intArray
40 | mov ebx,TYPE intArray
41 | call DumpMem
42 | call Crlf
43 |
44 | exit
45 | main ENDP
46 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/4_3_SummingtheGapsbetweenArrayValues.asm:
--------------------------------------------------------------------------------
1 | TITLE Summing the Gaps between Array Values
2 | ; This program calculates the sum of all the gaps between successive array
3 | ; elements using a loop and indexed addressing.
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | intArray DWORD 0,2,5,9,10
8 | introduction BYTE "This is the original array:",0
9 | conclusion BYTE "This is the sum of the gaps: ",0
10 |
11 | .DATA?
12 | sum DWORD ?
13 |
14 | .CODE
15 | main PROC
16 | call Clrscr
17 | mov edx,OFFSET introduction
18 | call Writestring
19 | call Crlf
20 | mov esi,OFFSET intArray
21 | mov ecx,LENGTHOF intArray
22 | mov ebx,TYPE intArray
23 | call DumpMem
24 | mov esi,OFFSET intArray
25 | mov ecx,LENGTHOF intArray - 1
26 | SumGaps:
27 | mov eax,[esi]
28 | add esi,TYPE intArray
29 | mov ebx,[esi]
30 | sub ebx,eax
31 | add sum,ebx
32 | loop SumGaps
33 | call Crlf
34 | mov edx,OFFSET conclusion
35 | call Writestring
36 | mov eax,sum
37 | call Writeint
38 | call Crlf
39 | call Crlf
40 |
41 | exit
42 | main ENDP
43 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/4_4_CopyingaWordArraytoaDoubleWordarray.asm:
--------------------------------------------------------------------------------
1 | TITLE Copying a Word Array to a DoubleWord array
2 | ; This program copies all the elements from an unsigned Word (16-bit)
3 | ; array into an unsigned doubleword (32-bit) array using a loop.
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | wordArray WORD 100h,200h,300h,400h
8 | introduction BYTE "This is the original word array:",0
9 | conclusion BYTE "This is the doubleword copy:",0
10 |
11 | .DATA?
12 | dWordArray DWORD LENGTHOF wordArray DUP(?)
13 |
14 | .CODE
15 | main PROC
16 | call Clrscr
17 | mov edx,OFFSET introduction
18 | call Writestring
19 | call Crlf
20 | mov esi,OFFSET wordArray
21 | mov ecx,LENGTHOF wordArray
22 | mov ebx,TYPE wordArray
23 | call DumpMem
24 | call Crlf
25 |
26 | mov esi,0
27 | mov ecx,LENGTHOF wordArray
28 | CopyArrayElements:
29 | movzx eax,wordArray[esi]
30 | mov dWordArray[esi * 2],eax
31 | add esi,TYPE wordArray
32 | loop CopyArrayElements
33 |
34 | mov edx,OFFSET conclusion
35 | call Writestring
36 | call Crlf
37 | mov esi,OFFSET dWordArray
38 | mov ecx,LENGTHOF dWordArray
39 | mov ebx,TYPE dWordArray
40 | call DumpMem
41 | call Crlf
42 |
43 | exit
44 | main ENDP
45 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/4_5_FibonacciNumbers.asm:
--------------------------------------------------------------------------------
1 | TITLE Fibonacci Numbers
2 | ; This program calculates the first seven values of the Fibonacci number
3 | ; sequence using a loop. The sequence is described by the formula:
4 | ; Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n - 1) + Fib(n - 2)
5 | INCLUDE Irvine32.inc
6 |
7 | NUMBER_OF_VALUES = 7
8 |
9 | .DATA
10 | explanation BYTE "First ",0
11 | BYTE " values of the Fibonacci number sequence:",0
12 |
13 | .DATA?
14 | fibonacciSequence BYTE NUMBER_OF_VALUES DUP(?)
15 |
16 | .CODE
17 | main PROC
18 | call Clrscr
19 |
20 | mov fibonacciSequence[0],1
21 | mov fibonacciSequence[1],1
22 | mov ecx,NUMBER_OF_VALUES - 2
23 | mov esi,2
24 | CalculateSequence:
25 | mov al,fibonacciSequence[esi - 1]
26 | add al,fibonacciSequence[esi - 2]
27 | mov fibonacciSequence[esi],al
28 | inc esi
29 | loop CalculateSequence
30 |
31 | mov edx,OFFSET explanation
32 | call Writestring
33 | mov eax,NUMBER_OF_VALUES
34 | call Writedec
35 | mov edx,OFFSET explanation[7]
36 | call Writestring
37 | call Crlf
38 |
39 | mov esi,OFFSET fibonacciSequence
40 | mov ecx,LENGTHOF fibonacciSequence
41 | mov ebx,TYPE fibonacciSequence
42 | call DumpMem
43 | call Crlf
44 |
45 | exit
46 | main ENDP
47 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/4_6_ReverseanArray.asm:
--------------------------------------------------------------------------------
1 | TITLE Reverse an Array
2 | ; This program reverses the elements of an integer array.
3 | ; The array type must be 32-bits or smaller (BYTE, WORD, or DWORD).
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | intArray DWORD 1,5,6,8,0Ah,1Bh,1Eh,22h,2Ah,32h
8 | original BYTE "Original array:",0
9 | reversed BYTE "Reversed array:",0
10 |
11 | .CODE
12 | main PROC
13 | call Clrscr
14 | mov edx,OFFSET original
15 | call Writestring
16 | call Crlf
17 | mov esi,OFFSET intArray
18 | mov ecx,LENGTHOF intArray
19 | mov ebx,TYPE intArray
20 | call DumpMem
21 | mov esi,OFFSET intArray
22 | mov edi,OFFSET intArray + SIZEOF intArray - TYPE intArray
23 | mov ecx,LENGTHOF intArray
24 | mov eax,TYPE intArray
25 |
26 | cmp eax,TYPE DWORD
27 | jne NotDWORD
28 | call ReverseDWORD
29 | jmp Output
30 | NotDWORD:
31 | cmp eax,TYPE WORD
32 | jne NotWORD
33 | call ReverseWORD
34 | jmp Output
35 | NotWORD:
36 | call ReverseBYTE
37 | Output:
38 | mov edx,OFFSET reversed
39 | call Writestring
40 | call Crlf
41 | mov esi,OFFSET intArray
42 | mov ecx,LENGTHOF intArray
43 | mov ebx,TYPE intArray
44 | call DumpMem
45 | call Crlf
46 | exit
47 | main ENDP
48 |
49 | ReverseDWORD PROC
50 | ReverseArray:
51 | mov eax,[esi]
52 | mov ebx,[edi]
53 | xchg eax,ebx
54 | mov [esi],eax
55 | mov [edi],ebx
56 | add esi,TYPE intArray
57 | sub edi,TYPE intArray
58 | dec ecx
59 | loop ReverseArray
60 | ret
61 | ReverseDWORD ENDP
62 |
63 | ReverseWORD PROC
64 | ReverseArray:
65 | mov ax,[esi]
66 | mov bx,[edi]
67 | xchg ax,bx
68 | mov [esi],ax
69 | mov [edi],bx
70 | add esi,TYPE intArray
71 | sub edi,TYPE intArray
72 | dec ecx
73 | loop ReverseArray
74 | ret
75 | ReverseWORD ENDP
76 |
77 | ReverseBYTE PROC
78 | ReverseArray:
79 | mov al,[esi]
80 | mov bl,[edi]
81 | xchg al,bl
82 | mov [esi],al
83 | mov [edi],bl
84 | add esi,TYPE intArray
85 | sub edi,TYPE intArray
86 | dec ecx
87 | loop ReverseArray
88 | ret
89 | ReverseBYTE ENDP
90 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/4_7_CopyaStringinReverseOrder.asm:
--------------------------------------------------------------------------------
1 | TITLE Copy a String in Reverse Order
2 | ; This program copies a string from source to target, reversing the
3 | ; character order in the process.
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | source BYTE "This is the source string",0
8 | target BYTE SIZEOF source DUP("#")
9 |
10 | .CODE
11 | main PROC
12 | mov esi,OFFSET source + SIZEOF source - 2
13 | mov edi,OFFSET target
14 | mov ecx,SIZEOF source - 1
15 | ReverseString:
16 | mov al,[esi]
17 | mov [edi],al
18 | inc edi
19 | dec esi
20 | loop ReverseString
21 | mov al,0
22 | mov [edi],al
23 |
24 | call Clrscr
25 | mov edx,OFFSET source
26 | call Writestring
27 | call Crlf
28 | mov edx,OFFSET target
29 | call Writestring
30 | call Crlf
31 |
32 | exit
33 | main ENDP
34 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/4_8_ShiftingtheElementsinanArray.asm:
--------------------------------------------------------------------------------
1 | TITLE Shifting the Elements in an Array
2 | ; This program rotates the numbers of a 32-bit integer array forward one
3 | ; position. The value at the end of the array wraps around to the first
4 | ; position.
5 | INCLUDE Irvine32.inc
6 |
7 | .DATA
8 | intArray DWORD 10,20,30,40
9 | introduction BYTE "This is the original array:",0
10 | conclusion BYTE "This is the shifted array:",0
11 |
12 | .CODE
13 | main PROC
14 | call Clrscr
15 | mov edx,OFFSET introduction
16 | call Writestring
17 | call Crlf
18 | mov esi,OFFSET intArray
19 | mov ecx,LENGTHOF intArray
20 | mov ebx,TYPE intArray
21 | call DumpMem
22 | mov ecx,LENGTHOF intArray - 1
23 | mov ebx,intArray[0]
24 | mov esi,TYPE intArray
25 | ShiftArrayElements:
26 | mov eax,ebx
27 | mov ebx,intArray[esi]
28 | mov intArray[esi],eax
29 | add esi,TYPE intArray
30 | loop ShiftArrayElements
31 | mov intArray[0],ebx
32 | call Crlf
33 | mov edx,OFFSET conclusion
34 | call Writestring
35 | call Crlf
36 | mov esi,OFFSET intArray
37 | mov ecx,LENGTHOF intArray
38 | mov ebx,TYPE intArray
39 | call DumpMem
40 | call Crlf
41 |
42 | exit
43 | main ENDP
44 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_10_FibonacciGenerator.asm:
--------------------------------------------------------------------------------
1 | TITLE Fibonacci Generator
2 | ; This program produces N values of the Fibonacci number series and stores
3 | ; them in an array of doubleword.
4 | INCLUDE Irvine32.inc
5 |
6 | N = 47
7 |
8 | .DATA?
9 | fibonacciSequence DWORD N DUP(?)
10 |
11 | .CODE
12 | main PROC
13 | call Clrscr
14 | mov fibonacciSequence[0],1
15 | mov fibonacciSequence[4],1
16 | mov ecx,N - 2
17 | mov esi,2 * TYPE DWORD
18 | CalculateSequence:
19 | mov eax,fibonacciSequence[esi - TYPE DWORD]
20 | add eax,fibonacciSequence[esi - 2 * TYPE DWORD]
21 | mov fibonacciSequence[esi],eax
22 | add esi,TYPE DWORD
23 | loop CalculateSequence
24 | mov esi,OFFSET fibonacciSequence
25 | mov ecx,LENGTHOF fibonacciSequence
26 | mov ebx,TYPE fibonacciSequence
27 | call DumpMem
28 | call Crlf
29 | exit
30 | main ENDP
31 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_11_FindingMultiplesofK.asm:
--------------------------------------------------------------------------------
1 | TITLE Finding Multiples of K
2 | ; This program finds all multiples of K that are less than N.
3 | INCLUDE Irvine32.inc
4 |
5 | N = 50
6 |
7 | .DATA
8 | bArray BYTE N DUP(0)
9 | partOne BYTE "All multiples of ",0
10 | partTwo BYTE " that are less than ",0
11 |
12 | .DATA?
13 | K DWORD ?
14 |
15 | .CODE
16 | main PROC
17 | call Clrscr
18 | mov K,2
19 | mov edx,OFFSET partOne
20 | call WriteString
21 | mov eax,K
22 | call WriteDec
23 | mov edx,OFFSET partTwo
24 | call WriteString
25 | mov eax,N
26 | call WriteDec
27 | call Crlf
28 | call FindMultiplesOfK
29 | call Crlf
30 |
31 | mov K,3
32 | mov edx,OFFSET partOne
33 | call WriteString
34 | mov eax,K
35 | call WriteDec
36 | mov edx,OFFSET partTwo
37 | call WriteString
38 | mov eax,N
39 | call WriteDec
40 | call Crlf
41 | call FindMultiplesOfK
42 | call Crlf
43 | exit
44 | main ENDP
45 |
46 | ; In a byte array of size N, this procedure finds all multiples of K that
47 | ; are less than N.
48 | ; Receives: bArray = uninitialised byte array, N = array size,
49 | ; K = number whose multiples are searched for
50 | ; Returns: bArray = corresponding array elements of multiples are
51 | ; marked
52 | FindMultiplesOfK PROC USES ebx ecx edx esi
53 | mov esi,OFFSET bArray
54 | mov ecx,N
55 | mov edx,1
56 | mov ebx,K
57 | TraverseValues:
58 | cmp ebx,edx
59 | jne NotMultiple
60 | mov BYTE PTR [esi],1
61 | add ebx,K
62 | mov eax,edx
63 | call WriteDec
64 | call Crlf
65 | NotMultiple:
66 | inc edx
67 | add esi,TYPE bArray
68 | loop TraverseValues
69 | ret
70 | FindMultiplesOfK ENDP
71 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_1_DrawTextColours.asm:
--------------------------------------------------------------------------------
1 | TITLE Draw Text Colours
2 | ; This program displays the same string in four different colours, using
3 | ; the SetTextColor procedure from the Irvine32 link library and a loop.
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | myString BYTE "This string will change colours!",0
8 |
9 | .CODE
10 | main PROC
11 | mov eax,lightRed + (blue * 16)
12 | call SetTextColor
13 | call Clrscr
14 | mov ecx,4
15 | ChangeColours:
16 | call SetTextColor
17 | mov edx,OFFSET myString
18 | call Writestring
19 | call Crlf
20 | add eax,1
21 | loop ChangeColours
22 | exit
23 | main ENDP
24 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_2_LinkingArrayItems.asm:
--------------------------------------------------------------------------------
1 | TITLE Linking Array Items
2 | ; Given the starting index in a list, an array of characters, and an array
3 | ; of link index, this program traverses the links and locates the
4 | ; characters in their correct sequence. Each character the program
5 | ; locates is then copied to a new array.
6 | INCLUDE Irvine32.inc
7 |
8 | .DATA
9 | start DWORD 1
10 | chars BYTE 'H','A','C','E','B','D','F','G'
11 | links DWORD 0,4,5,6,2,3,7,0
12 | linksType BYTE TYPE links
13 |
14 | .DATA?
15 | outputArray BYTE LENGTHOF chars DUP(?)
16 |
17 | .CODE
18 | main PROC
19 | mov ecx,LENGTHOF outputArray
20 | mov edi,OFFSET outputArray
21 | TraverseLinks:
22 | mov esi,OFFSET chars
23 | add esi,start
24 | mov al,[esi]
25 | mov [edi],al
26 |
27 | mov edx,OFFSET links
28 | mov eax,start
29 | mul linksType
30 | mov start,eax
31 | add edx,start
32 | mov eax,[edx]
33 | mov start,eax
34 | inc edi
35 | loop TraverseLinks
36 |
37 | exit
38 | main ENDP
39 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_3_SimpleAddition(1).asm:
--------------------------------------------------------------------------------
1 | TITLE Simple Addition (1)
2 | ; This program clears the screen, locates the cursor near the middle of
3 | ; the screen, prompts the user for two integers, adds the integers, and
4 | ; displays their sum.
5 | INCLUDE Irvine32.inc
6 |
7 | .DATA
8 | prompt1 BYTE "Enter the first integer: ",0
9 | prompt2 BYTE "Enter the second integer: ",0
10 | result BYTE "The sum of the two integers is: ",0
11 |
12 | .DATA?
13 | integer1 DWORD ?
14 | integer2 DWORD ?
15 | sum DWORD ?
16 |
17 | .CODE
18 | main PROC
19 | call Clrscr
20 | mov dh,12
21 | mov dl,40
22 | call Gotoxy
23 | mov edx,OFFSET prompt1
24 | call Writestring
25 | call Readint
26 | mov integer1,eax
27 | mov dh,13
28 | mov dl,40
29 | call Gotoxy
30 | mov edx,OFFSET prompt2
31 | call WriteString
32 | call Readint
33 | mov integer2,eax
34 |
35 | mov eax,integer1
36 | add eax,integer2
37 | mov sum,eax
38 |
39 | mov dh,15
40 | mov dl,36
41 | call Gotoxy
42 | mov edx,OFFSET result
43 | call Writestring
44 | mov eax,sum
45 | call Writeint
46 | call Crlf
47 | mov dh,17
48 | mov dl,40
49 | call Gotoxy
50 |
51 | exit
52 | main ENDP
53 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_4_SimpleAddition(2).asm:
--------------------------------------------------------------------------------
1 | TITLE Simple Addition (2)
2 | ; This program does the same thing as Simple Addition (1) but repeats it
3 | ; three times with a loop
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | prompt1 BYTE "Enter the first integer: ",0
8 | prompt2 BYTE "Enter the second integer: ",0
9 | result BYTE "The sum of the two integers is: ",0
10 |
11 | .DATA?
12 | integer1 DWORD ?
13 | integer2 DWORD ?
14 | sum DWORD ?
15 |
16 | .CODE
17 | main PROC
18 | mov ecx,3
19 | RunProgram:
20 | call GetInput
21 | mov eax,integer1
22 | add eax,integer2
23 | mov sum,eax
24 | mov dh,15
25 | mov dl,36
26 | call Gotoxy
27 | mov edx,OFFSET result
28 | call Writestring
29 | mov eax,sum
30 | call Writeint
31 | call Crlf
32 | mov dh,17
33 | mov dl,40
34 | call Gotoxy
35 | cmp ecx,1
36 | je next
37 | call WaitMsg
38 | loop RunProgram
39 | next:
40 | exit
41 | main ENDP
42 |
43 | GetInput PROC
44 | call Clrscr
45 | mov dh,12
46 | mov dl,40
47 | call Gotoxy
48 | mov edx,OFFSET prompt1
49 | call Writestring
50 | call Readint
51 | mov integer1,eax
52 | mov dh,13
53 | mov dl,40
54 | call Gotoxy
55 | mov edx,OFFSET prompt2
56 | call WriteString
57 | call Readint
58 | mov integer2,eax
59 | ret
60 | GetInput ENDP
61 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_5_BetterRandomRangeProcedure.asm:
--------------------------------------------------------------------------------
1 | TITLE BetterRandomRange Procedure
2 | ; This program showcases the BetterRandomRange procedure, an improved
3 | ; version of the RandomRange procedure.
4 | INCLUDE Irvine32.inc
5 |
6 | NUMBER_OF_CALLS = 50
7 |
8 | .DATA
9 | M DWORD -300
10 | N DWORD 100
11 |
12 | .CODE
13 | main PROC
14 | call Clrscr
15 | mov eax,N
16 | mov ebx,M
17 | mov ecx,NUMBER_OF_CALLS
18 | GenerateValues:
19 | call BetterRandomRange
20 | loop GenerateValues
21 | exit
22 | main ENDP
23 |
24 | ; This procedure is a improved version of the RandomRange procedure.
25 | ; Instead of generating a pseudorandom integer between 0 and N - 1, it
26 | ; generates an integer between M ands N - 1
27 | ; Receives: EBX = M (lower range), EAX = N (upper range)
28 | ; Returns: EAX = psuedorandom value
29 | BetterRandomRange PROC USES eax ebx
30 | sub eax,ebx
31 | call RandomRange
32 | add eax,ebx
33 | call Writeint
34 | call Crlf
35 | ret
36 | BetterRandomRange ENDP
37 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_6_RandomString.asm:
--------------------------------------------------------------------------------
1 | TITLE Random Strings
2 | ; This program showcases the RandomString procedure, which generates a
3 | ; random string of length L.
4 | INCLUDE Irvine32.inc
5 |
6 | NUMBER_OF_STRINGS = 20
7 | L = 7
8 |
9 | .DATA?
10 | randomString BYTE L DUP (?)
11 |
12 | .CODE
13 | main PROC
14 | call Clrscr
15 | mov eax,L
16 | mov esi,OFFSET randomString
17 | mov ecx,NUMBER_OF_STRINGS
18 | GenerateStrings:
19 | call GenerateRandomString
20 | mov edx,OFFSET randomString
21 | call Writestring
22 | call Crlf
23 | loop GenerateStrings
24 | exit
25 | main ENDP
26 |
27 | ; Generates a random string of length L.
28 | ; Receives: EAX = L (string length)
29 | ; ESI = pointer to array of bytes that will hold the
30 | ; random string
31 | ; Returns: randomString = the pseudorandomly generated string
32 | GenerateRandomString PROC USES eax ecx esi
33 | mov ecx,eax
34 | GenerateChar:
35 | mov eax,26
36 | call RandomRange
37 | add eax,65
38 | mov [esi],eax
39 | inc esi
40 | loop GenerateChar
41 | mov eax,0
42 | mov [esi],eax
43 | ret
44 | GenerateRandomString ENDP
45 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_7_RandomScreenLocations.asm:
--------------------------------------------------------------------------------
1 | TITLE Random Screen Location
2 | ; This program displays a single character at 100 random screen locations,
3 | ; using a timing delay of 100 milliseconds.
4 | INCLUDE Irvine32.inc
5 |
6 | NUMBER_OF_CHARS = 100
7 |
8 | .DATA
9 | char BYTE 'A'
10 |
11 | .DATA?
12 | rows BYTE ?
13 | cols BYTE ?
14 |
15 | .CODE
16 | main PROC
17 | call GetMaxXY
18 | mov ecx,NUMBER_OF_CHARS
19 | GenerateCharsAndPrint:
20 | call RandomScreenLocation
21 | loop GenerateCharsAndPrint
22 | exit
23 | main ENDP
24 |
25 | RandomScreenLocation PROC USES eax edx
26 | movzx eax,al
27 | call RandomRange
28 | mov dh,al
29 | movzx eax,dl
30 | call RandomRange
31 | mov dl,al
32 | call Gotoxy
33 | mov al,char
34 | call WriteChar
35 | ret
36 | RandomScreenLocation ENDP
37 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_8_ColourMatrix.asm:
--------------------------------------------------------------------------------
1 | TITLE Colour Matrix
2 | ; This program displays a single character in all possible combinations of
3 | ; foreground and background colours (16 X 16 = 256).
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA?
7 | loopCounter DWORD ?
8 |
9 | .CODE
10 | main PROC
11 | mov eax,0
12 | mov ecx,16
13 | L1:
14 | mov loopCounter,ecx
15 | push eax
16 | mov ecx,16
17 | L2:
18 | call SetTextColor
19 | push eax
20 | mov al,'A'
21 | call WriteChar
22 | mov eax,100
23 | call Delay
24 | pop eax
25 | inc eax
26 | loop L2
27 | call Crlf
28 | pop eax
29 | add eax,16
30 | mov ecx,loopCounter
31 | loop L1
32 | call Crlf
33 | mov eax,lightGray + (black * 16)
34 | exit
35 | main ENDP
36 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/5_9_RecursiveProcedure.asm:
--------------------------------------------------------------------------------
1 | TITLE Recursive Procedure
2 | ; This program calls a recursive procedure.
3 | INCLUDE Irvine32.inc
4 |
5 | NUMBER_OF_CALLS = 10
6 |
7 | .DATA?
8 | counter DWORD ?
9 |
10 | .CODE
11 | main PROC
12 | mov counter,0
13 | mov ecx,NUMBER_OF_CALLS
14 | call RecursiveProcedure
15 | exit
16 | main ENDP
17 |
18 | RecursiveProcedure PROC
19 | inc counter
20 | cmp counter,ecx
21 | jz quit
22 | call RecursiveProcedure
23 | quit:
24 | ret
25 | RecursiveProcedure ENDP
26 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_10_ParityChecking.asm:
--------------------------------------------------------------------------------
1 | TITLE Parity Checking
2 |
3 | ; This program calculates the parity (even or odd) of the bytes in an
4 | ; array.
5 |
6 | INCLUDE Irvine32.inc
7 |
8 | True = 1
9 | False = 0
10 |
11 | .DATA
12 | array1 BYTE 1,2,3,4,1,20,35,-12,66,4,6 ; odd array
13 | array2 BYTE 4,2,6,8,10,12,14,16,22,56,44 ; even array
14 |
15 | .CODE
16 | main PROC
17 | mov ebx,OFFSET array1 ; point to the array
18 | mov ecx,SIZEOF array1 ; loop counter
19 | call CheckParity
20 | call WriteInt
21 | call Crlf
22 | mov ebx,OFFSET array2 ; point to the array
23 | mov ecx,SIZEOF array2 ; loop counter
24 | call CheckParity
25 | call WriteInt
26 | call Crlf
27 | exit
28 | main ENDP
29 |
30 | ;-----------------------------------------------
31 | CheckParity PROC USES ebx ecx
32 | ;
33 | ; Determines if there is an even or odd number of bits in the entire array.
34 | ; Receives: EBX points to the array, ECX = length of the array
35 | ; Returns: EAX = True if the parity is even, False if the parity is odd
36 | ;-----------------------------------------------------
37 | movzx eax,BYTE PTR [ebx] ; EAX = value of first byte
38 | cmp ecx,1 ; arraySize <= 1 ?
39 | jle DoneTraversing ; yes: jump straight to calculation
40 | dec ecx ; loop for SIZEOF array - 1
41 | TraverseArray:
42 | inc ebx ; point to next byte
43 | xor al,BYTE PTR [ebx] ; xor the current value with next byte
44 | loop TraverseArray
45 | DoneTraversing:
46 | jnp OddParity
47 | mov eax,True
48 | jmp next
49 | OddParity:
50 | mov eax,False
51 | next:
52 | ret
53 | CheckParity ENDP
54 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_1_FillinganArray.asm:
--------------------------------------------------------------------------------
1 | TITLE Filling an Array
2 | ; This program fills an array of doublewords with N random integers in the
3 | ; range j...k inclusive.
4 | INCLUDE Irvine32.inc
5 |
6 | N = 7
7 |
8 | .DATA
9 | promptj BYTE "Lowest value in range: ",0
10 | promptk BYTE "Highest value in range: ",0
11 |
12 | .DATA?
13 | dArray DWORD N DUP(?)
14 | j DWORD ?
15 | k DWORD ?
16 |
17 | .CODE
18 | main PROC
19 | call Clrscr
20 | call GetInput
21 | call FillArray
22 | mov esi,OFFSET dArray
23 | mov ecx,N
24 | mov ebx,TYPE dArray
25 | call DumpMem
26 | call Crlf
27 | call GetInput
28 | call FillArray
29 | mov esi,OFFSET dArray
30 | mov ecx,N
31 | mov ebx,TYPE dArray
32 | call DumpMem
33 | call Crlf
34 | exit
35 | main ENDP
36 |
37 | ; Returns: j = low range, k = high range
38 | GetInput PROC USES edx eax
39 | mov edx,OFFSET promptj
40 | call WriteString
41 | call ReadInt
42 | mov j,eax
43 | mov edx,OFFSET promptk
44 | call WriteString
45 | call ReadInt
46 | mov k,eax
47 | ret
48 | GetInput ENDP
49 |
50 | ; Receives: ESI = pointer to array, N, j, k
51 | ; Returns: dArray = filled array
52 | FillArray PROC USES esi ecx eax ebx
53 | mov esi,OFFSET dArray
54 | mov ecx,N
55 | TraverseArray:
56 | mov eax,k
57 | mov ebx,j
58 | sub eax,ebx
59 | add eax,1
60 | call RandomRange
61 | add eax,j
62 | mov [esi],eax
63 | add esi,TYPE dArray
64 | loop TraverseArray
65 | ret
66 | FillArray ENDP
67 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_2_SummingArrayElementsinaRange.asm:
--------------------------------------------------------------------------------
1 | TITLE Summing Array Elements in a Range
2 | ; This program calls the SumArrayElementsInRange procedure twice.
3 | INCLUDE Irvine32.inc
4 |
5 | .DATA
6 | myArray SDWORD 0D1EFB5CBh,3E3000h,40100Ah,19FF84h,19FF94h,246h
7 |
8 | .DATA?
9 | j SDWORD ?
10 | k SDWORD ?
11 |
12 | .CODE
13 | main PROC
14 | call Clrscr
15 | mov esi,OFFSET myArray ; pointer to the array
16 | mov ecx,LENGTHOF myArray ; length of the array
17 |
18 | ; First test range: only the first and last elements will be added
19 | ; 0D1EFB5CBh + 246h = 0D1EFB811
20 | mov j,0D050F800h
21 | mov k,3E8h
22 | call SumArrayElementsInRange
23 |
24 | ; Second test range: all but the first element will be added
25 | ; 3E3000h + 40100Ah + 19FF84h + 19FF94h + 246h = 0B24168h
26 | mov j,246h
27 | mov k,40100Ah
28 | call SumArrayElementsInRange
29 | exit
30 | main ENDP
31 |
32 | ; This procedure calculates the sum of all array elements falling within
33 | ; the range j...k (inclusive).
34 | ; Receives: ESI = pointer to a signed doubleword array
35 | ; ECX = the length of the array
36 | ; j = lowest value, k = highest value
37 | ; Returns: EAX = the sum
38 | SumArrayElementsInRange PROC USES esi ecx ebx
39 | mov eax,0 ; initialise EAX
40 | TraverseArray: ; loop to traverse array
41 | mov ebx,SDWORD PTR [esi] ; EBX = current array element
42 | cmp ebx,j ; EBX >= j ?
43 | jl OutOfRange ; if not, jump to OutOfRange
44 | cmp ebx,k ; EBX <= k ?
45 | jg OutOfRange ; if not, jump to OutOfRange
46 | add eax,ebx ; if in range, add to EAX
47 | OutOfRange:
48 | add esi,TYPE myArray ; next element in array
49 | loop TraverseArray
50 | ret
51 | SumArrayElementsInRange ENDP
52 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_3_TestScoreEvaluation.asm:
--------------------------------------------------------------------------------
1 | TITLE Test Score Evaluation
2 | ; This program generates 10 random scores between 50 and 100 inclusive and
3 | ; passes each of them to the CalcGrade procedure which returns the
4 | ; corresponding letter grade for each score.
5 | INCLUDE Irvine32.inc
6 |
7 | .DATA
8 | tableHeader BYTE "Score Letter",0Dh,0Ah,0
9 |
10 | .CODE
11 | main PROC
12 | mov edx,OFFSET tableHeader
13 | call WriteString ; print table header
14 | call Randomize ; initialise the starting seed value
15 | mov ecx,10 ; generate 10 grades
16 | GenerateGrades:
17 | mov eax,51 ; produce a random integer (0 -> 50)
18 | call RandomRange
19 | add eax,50 ; (0 -> 50) + 50 = (50 -> 100)
20 | call WriteDec ; print score to console window
21 | push eax
22 | mov al,9 ; ASCII code for tab
23 | call WriteChar ; print a tab
24 | pop eax
25 | call CalcGrade ; get letter grade
26 | call WriteChar ; print the letter grade
27 | call Crlf
28 | loop GenerateGrades
29 | call Crlf
30 | exit
31 | main ENDP
32 |
33 | ; This program receives a score and returns the corresponding letter grade
34 | ; for that value.
35 | ; Receives: EAX = an integer value (0 - 100)
36 | ; Returns: AL = a single capital letter
37 | CalcGrade PROC
38 | cmp eax,90 ; is score >= 90
39 | jae GradeA ; if yes, grade = A
40 | cmp eax,80 ; is score >= 80
41 | jae GradeB ; if yes, grade = B
42 | cmp eax,70 ; is score >= 70
43 | jae GradeC ; if yes, grade = C
44 | cmp eax,60 ; is score >= 60
45 | jae GradeD ; if yes, grade = D
46 | jmp GradeF ; if score < 60, grade = F
47 | GradeA:
48 | mov al,'A'
49 | jmp done
50 | GradeB:
51 | mov al,'B'
52 | jmp done
53 | GradeC:
54 | mov al,'C'
55 | jmp done
56 | GradeD:
57 | mov al,'D'
58 | jmp done
59 | GradeF:
60 | mov al,'F'
61 | done:
62 | ret
63 | CalcGrade ENDP
64 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_4_CollegeRegistration.asm:
--------------------------------------------------------------------------------
1 | TITLE College Registration
2 | ; This program determines whether or not a student is able to register
3 | ; for class depending on his grade average and number of desired credits.
4 | INCLUDE Irvine32.inc
5 |
6 | TRUE = 1
7 | FALSE = 0
8 |
9 | .DATA
10 | promptGradeAverage BYTE "Please enter your grade average: ",0
11 | promptCredits BYTE "Please enter the number of credits you want: ",0
12 | canRegister BYTE "The student can register",0Dh,0Ah,0
13 | cannotRegister BYTE "The student cannot register",0Dh,0Ah,0
14 | errorMessage BYTE "ERROR: Invalid input.",0Dh,0Ah,0
15 |
16 | .DATA?
17 | gradeAverage WORD ?
18 | credits WORD ?
19 | validInput BYTE ?
20 | OkToRegister BYTE ?
21 |
22 | .CODE
23 | main PROC
24 | mov edx,OFFSET promptGradeAverage ; prompt the user for gradeAverage
25 | call WriteString
26 | call ReadDec
27 | mov gradeAverage,ax
28 | mov edx,OFFSET promptCredits ; prompt the user for credits
29 | call WriteString
30 | call ReadDec
31 | mov credits,ax
32 |
33 | call CheckRange ; validate input
34 | mov al,validInput
35 | ; .IF validInput == FALSE
36 | cmp al,FALSE ; is input not valid ?
37 | jne C1 ; if input is valid, proceed
38 | mov eax,red + (black * 16) ; print error message in red
39 | call SetTextColor
40 | mov edx,OFFSET errorMessage ; if not, print error message
41 | call WriteString
42 | mov eax,lightGray + (black * 16) ; reset color
43 | call SetTextColor
44 | jmp done
45 | ; .ENDIF
46 | C1: ; input is valid
47 | call OkToRegisterOrNot
48 | mov al,OkToRegister
49 | ;.IF OkToRegister == TRUE
50 | cmp al,TRUE ; OkToRegister?
51 | jne cannot
52 | mov edx,OFFSET canRegister
53 | ;.ELSE
54 | jmp can
55 | cannot:
56 | mov edx,OFFSET cannotRegister
57 | ;.ENDIF
58 | can:
59 | call WriteString
60 | done:
61 | exit
62 | main ENDP
63 |
64 | ; This procedure uses two criteria to determine whether or not a student
65 | ; can register: The first is the person's grade average, based on a 0 to
66 | ; 400 scale, where 400 is the highest possible grade. The second is the
67 | ; number of credits the person wants to take.
68 | ; Receives: gradeAverage (0 - 400), credits (1 - 30)
69 | ; Returns: OkToRegister
70 | OkToRegisterOrNot PROC USES eax ebx
71 | mov OkToRegister,FALSE ; default: not ok to register
72 | mov ax,gradeAverage
73 | mov bx,credits
74 | ; .IF gradeAverage > 350
75 | cmp ax,350 ; is gradeAverage > 350 ?
76 | jbe C1 ; if not, jump to ElseIf1
77 | mov OkToRegister,TRUE ; if yes, OkToRegister = TRUE
78 | ; .ELSEIF (gradeAverage > 250) && (credits <= 16)
79 | jmp done ; if not, OkToRegister remains FALSE
80 | C1:
81 | cmp ax,250 ; is gradeAverage > 250 ?
82 | jbe C2 ; if not, jump to ElseIf2
83 | cmp bx,16 ; is credits <= 16 ?
84 | ja C2 ; if not, jump to ElseIf2
85 | mov OkToRegister,TRUE ; if yes, OkToRegister = TRUE
86 | ; .ELSEIF (credits <= 12)
87 | jmp done ; if not, OkToRegister remains FALSE
88 | C2:
89 | cmp bx,12 ; is credits <= 12
90 | ja done ; if not, OkToRegister remains FALSE
91 | mov OkToRegister,TRUE ;if yes, OkToRegister = TRUE
92 | ; .ENDIF
93 | done:
94 | ret
95 | OkToRegisterOrNot ENDP
96 |
97 | ; This procedure determines if determines if the grade average and credits
98 | ; values are within the valid range. gradeAverage must be between 0 and
99 | ; 400, credits must be between 1 and 30.
100 | ; Receives: gradeAverage, credits
101 | ; Returns: validInput
102 | CheckRange PROC
103 | mov validInput,FALSE ; default: input is invalid
104 | mov ax,gradeAverage
105 | mov bx,credits
106 | ; .IF (gradeAverage >= 0 && gradeAverage <= 400) &&
107 | ; (credits >= 1 && credits <= 30)
108 | cmp ax,0 ; is gradeAverage >= 0 ?
109 | jb done ; if not, input invalid
110 | cmp ax,400 ; is gradeAverage <= 400 ?
111 | ja done ; if not, input invalid
112 | cmp bx,1 ; is credits >= 1 ?
113 | jb done ; if not, input invalid
114 | cmp bx,30 ; is credits <= 30 ?
115 | ja done ; if not, input invalid
116 | mov validInput,TRUE ; if all conditions are true, input is valid
117 | ; .ENDIF
118 | done:
119 | ret
120 | CheckRange ENDP
121 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_5-6_BooleanCalculator.asm:
--------------------------------------------------------------------------------
1 | TITLE Boolean Calculator
2 | ; This program functions as a simple boolean calculator for 32-bit
3 | ; integers.
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | CaseTable BYTE '1' ; lookup value
8 | DWORD AND_op ; address of procedure
9 | EntrySize = ($ - CaseTable)
10 | BYTE '2'
11 | DWORD OR_op
12 | BYTE '3'
13 | DWORD NOT_op
14 | BYTE '4'
15 | DWORD XOR_op
16 | NumberOfEntries = ($ - CaseTable) / EntrySize
17 | prompt BYTE "Please make a selection from the following list by pressing the corresponding digit:",0Dh,0Ah
18 | BYTE "1. x AND y",0Dh,0Ah
19 | BYTE "2. x OR y",0Dh,0Ah
20 | BYTE "3. NOT x",0Dh,0Ah
21 | BYTE "4. x XOR y",0Dh,0Ah
22 | BYTE "5. Exit program",0Dh,0Ah,0Dh,0Ah
23 | BYTE "Your Selection: ",0
24 | msg1 BYTE "AND_op",0Dh,0Ah,0
25 | msg2 BYTE "OR_op",0Dh,0Ah,0
26 | msg3 BYTE "NOT_op",0Dh,0Ah,0
27 | msg4 BYTE "XOR_op",0Dh,0Ah,0
28 | xPrompt BYTE 0Dh,0Ah,"Please enter the value of x in hexadecimal: ",0
29 | yPrompt BYTE 0Dh,0Ah,"Please enter the value of y in hexadecimal: ",0
30 |
31 | .DATA?
32 | x DWORD ?
33 | y DWORD ?
34 |
35 | .CODE
36 | main PROC
37 | mov edx,OFFSET prompt ; ask user for input
38 | call WriteString
39 | call ReadChar ; read character into AL
40 | mov ebx,OFFSET CaseTable ; point EBX to the table
41 | mov ecx,NumberOfEntries ; loop counter
42 | TraverseCaseTable:
43 | cmp al,[ebx] ; match found?
44 | jne Continue ; no: continue
45 | call NEAR PTR [ebx + 1] ; yes: call the procedure
46 | call Crlf
47 | jmp done ; exit the search
48 | Continue:
49 | add ebx,EntrySize ; point to the next entry
50 | loop TraverseCaseTable
51 | done:
52 | exit
53 | main ENDP
54 |
55 | .DATA
56 | andResult BYTE " AND ",0
57 | equals BYTE " = ",0
58 |
59 | .CODE
60 | AND_op PROC
61 | mov edx,OFFSET msg1
62 | call GetX
63 | call GetY
64 | call Crlf
65 |
66 | mov eax,x
67 | call WriteHex ; display x
68 | mov edx,OFFSET andResult
69 | call WriteString ; display " AND "
70 | mov eax,y
71 | call WriteHex ; display y
72 | mov edx,OFFSET equals
73 | call WriteString ; display " = "
74 | mov eax,x
75 | and eax,y
76 | call WriteHex ; display result
77 | call Crlf
78 | ret
79 | AND_op ENDP
80 |
81 | .DATA
82 | orResult BYTE " OR ",0
83 |
84 | .CODE
85 | OR_op PROC
86 | mov edx,OFFSET msg2
87 | call GetX
88 | call GetY
89 | call Crlf
90 |
91 | mov eax,x
92 | call WriteHex ; display x
93 | mov edx,OFFSET orResult
94 | call WriteString ; display " OR "
95 | mov eax,y
96 | call WriteHex ; display y
97 | mov edx,OFFSET equals
98 | call WriteString ; display " = "
99 | mov eax,x
100 | or eax,y
101 | call WriteHex ; display result
102 | call Crlf
103 | ret
104 | OR_op ENDP
105 |
106 | .DATA
107 | notResult BYTE "NOT ",0
108 |
109 | .CODE
110 | NOT_op PROC
111 | mov edx,OFFSET msg3
112 | call GetX
113 | call Crlf
114 |
115 | mov edx,OFFSET notResult
116 | call WriteString ; display "NOT "
117 | mov eax,x
118 | call WriteHex ; display x
119 | mov edx,OFFSET equals
120 | call WriteString ; display " = "
121 | mov eax,x
122 | not eax
123 | call WriteHex ; display result
124 | call Crlf
125 | ret
126 | NOT_op ENDP
127 |
128 | .DATA
129 | xorResult BYTE " XOR ",0
130 |
131 | .CODE
132 | XOR_op PROC
133 | mov edx,OFFSET msg4
134 | call GetX
135 | call GetY
136 | call Crlf
137 |
138 | mov eax,x
139 | call WriteHex ; display x
140 | mov edx,OFFSET xorResult
141 | call WriteString ; display " XOR "
142 | mov eax,y
143 | call WriteHex ; display y
144 | mov edx,OFFSET equals
145 | call WriteString ; display " = "
146 | mov eax,x
147 | xor eax,y
148 | call WriteHex ; display result
149 | call Crlf
150 | ret
151 | XOR_op ENDP
152 |
153 | GetX PROC
154 | call WriteString ; display message
155 | mov edx,OFFSET xPrompt
156 | call WriteString ; get x
157 | call ReadHex
158 | mov x,eax
159 | ret
160 | GetX ENDP
161 |
162 | GetY PROC
163 | mov edx,OFFSET yPrompt
164 | call WriteString ; get y
165 | call ReadHex
166 | mov y,eax
167 | ret
168 | GetY ENDP
169 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_7_ProbabilitiesandColours.asm:
--------------------------------------------------------------------------------
1 | TITLE Probabilities and Colours
2 | ; This program randomly chooses amongst three different colours for
3 | ; displaying text on the screen.
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | text BYTE "This is string will randomly change colours!",0Dh,0Ah,0
8 |
9 | .CODE
10 | main PROC
11 | call Randomize
12 | mov ecx,20 ; 20 lines of text
13 | PrintText:
14 | mov eax,10 ; generate a random integer between 0 and 9
15 | call RandomRange
16 | cmp eax,2 ; 0 <= EAX <= 2 ?
17 | ja NotWhite
18 | mov eax,white + (black * 16) ; white = 30% probability
19 | jmp done
20 | NotWhite:
21 | cmp eax,3 ; EAX == 3 ?
22 | jne NotBlue
23 | mov eax,blue + (black * 16) ; blue = 10% probability
24 | jmp done
25 | NotBlue: ; 4 <= EAX <= 9 ?
26 | mov eax,green + (black * 16) ; green = 60% probability
27 | done:
28 | call SetTextColor
29 | mov edx,OFFSET text
30 | call WriteString
31 | loop PrintText
32 |
33 | mov eax,lightGray + (black * 16) ; reset text colour
34 | call SetTextColor
35 | call Crlf
36 | exit
37 | main ENDP
38 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_8_MessageEncryption.asm:
--------------------------------------------------------------------------------
1 | TITLE Message Encryption
2 | ; This program encrypts and decrypts some text that the user enters using
3 | ; symmetric encryption.
4 | INCLUDE Irvine32.inc
5 |
6 | BUFMAX = 128 ; maximum buffer size
7 |
8 | .DATA
9 | sPrompt BYTE "Enter the plain text: ",0
10 | sEncrypt BYTE "Cipher text: ",0
11 | sDecrypt BYTE "Decrypted: ",0
12 | buffer BYTE BUFMAX+1 DUP(0)
13 | key BYTE "ABXmv#7"
14 |
15 | .DATA?
16 | bufSize DWORD ?
17 |
18 | .CODE
19 | main PROC
20 | call InputTheString ; input the plain text
21 | call TranslateBuffer ; encrypt the buffer
22 | mov edx,OFFSET sEncrypt ; display encrypted message
23 | call DisplayMessage
24 | call TranslateBuffer ; decrypt the buffer
25 | mov edx,OFFSET sDecrypt ; display decrypted message
26 | call DisplayMessage
27 | exit
28 | main ENDP
29 |
30 | ; This procedure prompts the user for a plaintext string and saves the
31 | ; string and its length.
32 | InputTheString PROC
33 | pushad ; save 32-bit registers
34 | mov edx,OFFSET sPrompt ; display a prompt
35 | call WriteString
36 | mov ecx,BUFMAX ; maximum character count
37 | mov edx,OFFSET buffer ; point to the buffer
38 | call ReadString ; input the string
39 | mov bufSize,eax ; save the length
40 | call Crlf
41 | popad
42 | ret
43 | InputTheString ENDP
44 |
45 | ; This procedure displays the encrypted or decrypted message.
46 | ; Receives: EDX points to the message
47 | DisplayMessage PROC
48 | pushad
49 | call WriteString
50 | mov edx,OFFSET buffer ; display the buffer
51 | call WriteString
52 | call Crlf
53 | call Crlf
54 | popad
55 | ret
56 | DisplayMessage ENDP
57 |
58 | ; This procedure translates the string by exlusive-ORing each byte with
59 | ; the encryption key byte.
60 | TranslateBuffer PROC
61 | pushad
62 | mov ecx,bufSize ; loop counter
63 | mov esi,0 ; index 0 in buffer
64 | mov edi,0 ; index 0 in key
65 | TranslateBytes:
66 | mov al,key[edi] ; AL = current character in key
67 | inc edi ; next character in key
68 | cmp edi,SIZEOF key ; is EDI >= SIZEOF key ?
69 | jb Continue ; if not, continue
70 | sub edi,SIZEOF key ; if yes, reset EDI tofirst char of key
71 | Continue:
72 | xor buffer[esi],al ; translate a byte
73 | inc esi ; point to the next byte
74 | loop TranslateBytes
75 | popad
76 | ret
77 | TranslateBuffer ENDP
78 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/6_9_ValidatingaPIN.asm:
--------------------------------------------------------------------------------
1 | TITLE Validating a PIN
2 | ; This program validates a number of 5-digit PINs to ensure the values are
3 | ; within the specified ranges.
4 | INCLUDE Irvine32.inc
5 |
6 | PIN_LENGTH = 5
7 |
8 | .DATA
9 | pin1 BYTE 5,2,4,1,3 ; valid PIN
10 | pin2 BYTE 4,3,5,3,4 ; first digit out of range
11 | pin3 BYTE 6,4,5,3,7 ; last digit out of range
12 | pin4 BYTE 7,4,6,3,5 ; valid PIN
13 |
14 | .CODE
15 | main PROC
16 | mov esi,OFFSET pin1
17 | call Output
18 | mov esi,OFFSET pin2
19 | call Output
20 | mov esi,OFFSET pin3
21 | call Output
22 | mov esi,OFFSET pin4
23 | call Output
24 | exit
25 | main ENDP
26 |
27 | .DATA
28 | minVals BYTE 5,2,4,1,3
29 | maxVals BYTE 9,5,8,4,6
30 |
31 | .CODE
32 | ; This procedure validates each digit of the PIN.
33 | ; Receives: ESI points to the PIN
34 | ; Returns: EAX = position of invalid digit or 0 if PIN is valid
35 | Validate_PIN PROC USES ecx edi esi
36 | mov edi,0 ; index of value arrays
37 | mov ecx,PIN_LENGTH ; loop counter
38 | TraversePIN:
39 | mov al,[esi] ; current digit of PIN
40 | cmp al,minVals[edi] ; is al < minVals[edi] ?
41 | jb ReturnIndex ; if yes, immediately return
42 | cmp al,maxVals[edi] ; is al > maxVals[edi] ?
43 | jbe NextDigit ; if no, continue
44 | ReturnIndex:
45 | mov eax,edi ; return index of invalid digit
46 | inc eax
47 | jmp done
48 | NextDigit:
49 | inc esi
50 | inc edi
51 | loop TraversePIN
52 | mov eax,0 ; all digits are valid
53 | done:
54 | ret
55 | Validate_PIN ENDP
56 |
57 | .DATA
58 | valid BYTE "Valid",0
59 | invalid BYTE " digit is invalid",0
60 |
61 | .CODE
62 | Output PROC USES edx
63 | call Validate_PIN
64 | or eax,eax ; EAX == 0 ?
65 | jne NotValid ; if no, invalid
66 | mov edx,OFFSET valid ; "Valid"
67 | call WriteString
68 | jmp IsValid
69 | NotValid:
70 | call WriteDec ; # " digit is invalid"
71 | mov edx,OFFSET invalid
72 | call WriteString
73 | IsValid:
74 | call Crlf
75 | ret
76 | Output ENDP
77 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/7_1_DisplayASCIIDecimal.asm:
--------------------------------------------------------------------------------
1 | TITLE Display ASCII Decimal
2 | ; This program passes three numbers of different sizes to the WriteScaled
3 | ; procedure, which outputs each of the numbers with a decimal point.
4 | INCLUDE Irvine32.inc
5 |
6 | DECIMAL_OFFSET = 5
7 |
8 | .DATA
9 | decimal_one BYTE "100123456789765"
10 | decimal_two BYTE "444143474143"
11 | decimal_three BYTE "222001"
12 |
13 | .CODE
14 | main PROC
15 | mov ebx,DECIMAL_OFFSET
16 | call Clrscr
17 | mov edx,OFFSET decimal_one
18 | mov ecx,LENGTHOF decimal_one
19 | call WriteScaled
20 | call Crlf
21 | mov edx,OFFSET decimal_two
22 | mov ecx,LENGTHOF decimal_two
23 | call WriteScaled
24 | call Crlf
25 | mov edx,OFFSET decimal_three
26 | mov ecx,LENGTHOF decimal_three
27 | call WriteScaled
28 | call Crlf
29 | exit
30 | main ENDP
31 |
32 | ; This procedure outputs a decimal ASCII number with an implied decimal
33 | ; point.
34 | ; Receives: EDX = number's offset, ECX = number's length
35 | ; EBX = decimal's offset
36 | WriteScaled PROC
37 | pushad
38 | sub ecx,ebx
39 | WriteNumberBeforeDecimal:
40 | mov al,[edx]
41 | call WriteChar
42 | inc edx
43 | loop WriteNumberBeforeDecimal
44 | mov al,'.'
45 | call WriteChar
46 | mov ecx,ebx
47 | WriteNumberAfterDecimal:
48 | mov al,[edx]
49 | call WriteChar
50 | inc edx
51 | loop WriteNumberAfterDecimal
52 | popad
53 | ret
54 | WriteScaled ENDP
55 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/7_2_ExtendedSubtractionProcedure.asm:
--------------------------------------------------------------------------------
1 | TITLE Extended Subtraction Procedure
2 | ; This program passes several pairs of integers, each at least 10 bytes
3 | ; long to the Extended_Sub procedure which then subtract them.
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | pair1op1 BYTE 34h,12h,98h,74h,06h,0A4h,0B2h,0A2h,56h,78h
8 | pair1op2 BYTE 02h,45h,23h,00h,00h,87h,10h,80h,13h,24h
9 | pair2op1 BYTE 5Bh,0FCh,6Ah,22h,00h,20h,70h,00h,00h,40h
10 | pair2op2 BYTE 10h,0Ah,00h,40h,10h,0Ah,00h,40h,10h,0Ah
11 | result BYTE 11 DUP(0)
12 |
13 | .CODE
14 | main PROC
15 | mov esi,OFFSET pair1op1 ; first operand
16 | mov edi,OFFSET pair1op2 ; second operand
17 | mov ebx,OFFSET result ; result operand
18 | mov ecx,LENGTHOF pair1op1 ; number of bytes
19 | call Extended_Sub
20 | mov esi,OFFSET result ; display the result
21 | mov ecx,LENGTHOF result
22 | call Display_Result
23 | call Crlf
24 | mov esi,OFFSET pair2op1 ; first operand
25 | mov edi,OFFSET pair2op2 ; second operand
26 | mov ebx,OFFSET result ; result operand
27 | mov ecx,LENGTHOF pair2op1 ; number of bytes
28 | call Extended_Sub
29 | mov esi,OFFSET result ; display the result
30 | mov ecx,LENGTHOF result
31 | call Display_Result
32 | call Crlf
33 | exit
34 | main ENDP
35 |
36 | ; This procedure subtracts two extended integers stored as arrays of bytes.
37 | ; Receives: ESI and EDI point to the two integers,
38 | ; EBX points to a variable that will hold the result,
39 | ; ECX indicates the number of bytes to be subtracted
40 | Extended_Sub PROC
41 | pushad
42 | clc ; clear the Carry flag
43 | SubtractEachByte:
44 | mov al,[esi] ; get the first integer
45 | sbb al,[edi] ; subtract the second integer
46 | pushfd ; save the Carry flag
47 | mov [ebx],al ; store partial result
48 | inc esi ; increment pointers
49 | inc edi
50 | inc ebx
51 | popfd ; restore the Carry flag
52 | loop SubtractEachByte
53 | mov BYTE PTR [ebx],0 ; clear high byte of result
54 | sbb BYTE PTR [ebx],0 ; subtract any leftover carry
55 | popad
56 | ret
57 | Extended_Sub ENDP
58 |
59 | ; This procedure displays the result in its proper order, starting with
60 | ; the high-order byte, and working its way down to the low-order byte.
61 | ; Receives: ESI points to a variable that contains the result,
62 | ;l ECX indicates the number of bytes in the result
63 | Display_Result PROC
64 | pushad
65 | add esi,ecx ; point to the last array element
66 | sub esi,TYPE BYTE
67 | mov ebx,TYPE BYTE
68 | DisplayEachByte:
69 | mov al,[esi] ; get an array byte
70 | call WriteHexB ; display it
71 | sub esi,TYPE BYTE ; point to the previous byte
72 | loop DisplayEachByte
73 | popad
74 | ret
75 | Display_Result ENDP
76 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/7_3_PackedDecimalConversion.asm:
--------------------------------------------------------------------------------
1 | TITLE Packed Decimal Conversion
2 | ; This program converts packed decimal to ASCII.
3 | INCLUDE Irvine32.inc
4 |
5 | .DATA
6 | pdi1 DWORD 12345678h ; 12,345,678 decimal
7 | pdi2 DWORD 08723654h ; 8,723,654 decimal
8 | pdi3 DWORD 23456739h ; 23,456,739 decimal
9 | pdi4 DWORD 28737285h ; 28,737,285 decimal
10 | pdi5 DWORD 93450237h ; 93,450,237 decimal
11 | buffer BYTE 8 DUP(0),0
12 |
13 | .CODE
14 | main PROC
15 | mov edx,pdi1 ; EDX = packed decimal integer
16 | mov esi,OFFSET buffer ; points to the buffer
17 | call PackedToAsc ; do the conversion
18 | mov edx,OFFSET buffer ; display the buffer
19 | call WriteString ; output: 12345678
20 | call Crlf
21 |
22 | mov edx,pdi2
23 | mov esi,OFFSET buffer
24 | call PackedToAsc
25 | mov edx,OFFSET buffer
26 | call WriteString ; output: 08723654
27 | call Crlf
28 |
29 | mov edx,pdi3
30 | mov esi,OFFSET buffer
31 | call PackedToAsc
32 | mov edx,OFFSET buffer
33 | call WriteString ; output: 23456739
34 | call Crlf
35 |
36 | mov edx,pdi4
37 | mov esi,OFFSET buffer
38 | call PackedToAsc
39 | mov edx,OFFSET buffer
40 | call WriteString ; output: 28737285
41 | call Crlf
42 |
43 | mov edx,pdi5
44 | mov esi,OFFSET buffer
45 | call PackedToAsc
46 | mov edx,OFFSET buffer
47 | call WriteString ; output: 93450237
48 | call Crlf
49 |
50 | exit
51 | main ENDP
52 |
53 | ;---------------------------------------------------------
54 | PackedToAsc PROC
55 | ;
56 | ; Converts a 4-byte packed decimal integer to a string of ASCII decimal
57 | ; digits.
58 | ; Receives: EDX = packed integer, ESI points to buffer
59 | ; Returns: buffer filled with ASCII binary digits
60 | ;---------------------------------------------------------
61 | push eax
62 | push ecx
63 | push edx
64 |
65 | mov ecx,8 ; ASCII stores one digit per byte
66 | ConvertToASCII:
67 | mov al,dl ; AL = two lowest digits
68 | and al,0Fh ; clear 4 highest bits, AL = lowest digit
69 | or al,30h ; convert unpacked to ASCII
70 | mov [esi + ecx - 1],al ; add digit to buffer
71 | shr edx,4 ; shift right 4 bits to current lowest digit
72 | loop ConvertToASCII
73 |
74 | pop edx
75 | pop ecx
76 | pop eax
77 | ret
78 | PackedToAsc ENDP
79 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/7_4_EncryptionUsingRotateOperations.asm:
--------------------------------------------------------------------------------
1 | TITLE Encryption Using Rotate Operations
2 | ; This program tests the TranslateBuffer procedure by calling it twice
3 | ; with different data sets.
4 | INCLUDE Irvine32.inc
5 |
6 | .DATA
7 | key1 BYTE -2,4,1,0,-3,5,2,-4,-4,6
8 | keySize = $ - key1
9 | key2 BYTE -3,4,1,0,-3,5,2,-4,-4,6
10 | plain BYTE "Plain text: ",0
11 | cipher BYTE "Cipher text: ",0
12 | buffer1 BYTE "Bank account #: 8753257",0
13 | buffer2 BYTE "This is a Plaintext message",0
14 |
15 | .CODE
16 | main PROC
17 | mov edx,OFFSET plain
18 | call WriteString
19 | mov edx,OFFSET buffer1
20 | call WriteString
21 | call Crlf
22 | mov esi,OFFSET buffer1
23 | mov edi,OFFSET key1
24 | mov ecx,SIZEOF buffer1
25 | call TranslateBuffer ; encrypt the buffer
26 | mov edx,OFFSET cipher ; display encrypted message
27 | mov esi,OFFSET buffer1
28 | call DisplayMessage
29 |
30 | mov edx,OFFSET plain
31 | call WriteString
32 | mov edx,OFFSET buffer2
33 | call WriteString
34 | call Crlf
35 | mov esi,OFFSET buffer2
36 | mov edi,OFFSET key2
37 | mov ecx,SIZEOF buffer2
38 | call TranslateBuffer ; encrypt the buffer
39 | mov edx,OFFSET cipher ; display encrypted message
40 | mov esi,OFFSET buffer2
41 | call DisplayMessage
42 | exit
43 | main ENDP
44 |
45 | ; This procedure performs simple encryption by rotating each plaintext
46 | ; byte a varying number of positions in different directions.
47 | ; Receives: ESI = points to the buffer, EDI = points to the key,
48 | ; ECX = size of buffer
49 | TranslateBuffer PROC
50 | pushad
51 | mov edx,0
52 | TranslateBytes:
53 | push ecx
54 | mov cl,[edi + edx] ; AL = current character in key
55 | inc edx ; next character in key
56 | cmp edx,keySize ; is EDI >= SIZEOF key ?
57 | jb Continue ; if not, continue
58 | sub edx,keySize ; if yes, reset EDI tofirst char of key
59 | Continue:
60 | or cl,cl ; set Zero and Sign flags
61 | je Done ; if Zero flag is set, CL = 0
62 | js IsNegative ; if Sign flag is set, CL < 0
63 | ror BYTE PTR [esi],cl ; CL > 0 so rotate right
64 | jmp Done
65 | IsNegative:
66 | neg cl ; CL < 0 so rotate left
67 | rol BYTE PTR [esi],cl
68 | Done:
69 | inc esi ; point to the next byte
70 | pop ecx
71 | loop TranslateBytes
72 | popad
73 | ret
74 | TranslateBuffer ENDP
75 |
76 | ; This procedure displays the encrypted or decrypted message.
77 | ; Receives: EDX points to the message, ESI points to the buffer
78 | DisplayMessage PROC
79 | pushad
80 | call WriteString
81 | mov edx,esi ; display the buffer
82 | call WriteString
83 | call Crlf
84 | popad
85 | ret
86 | DisplayMessage ENDP
87 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/7_5_PrimeNumbers.asm:
--------------------------------------------------------------------------------
1 | TITLE Prime Numbers
2 | ; This program generates all prime numbers between 2 and 1000, using the
3 | ; Sieve of Eratosthenes method and displays them.
4 | INCLUDE Irvine32.inc
5 |
6 | TRUE = 1
7 | FALSE = 0
8 | n = 1000
9 | sqrt_n = 31
10 |
11 | .DATA?
12 | A BYTE n DUP(?)
13 |
14 | .CODE
15 | main PROC
16 | mov edi,OFFSET A + 2 ; initial index = 2
17 | mov ecx,n - 2
18 | mov eax,1
19 | rep stosb
20 | mov WORD PTR [A],FALSE ; set 0 & 1 to FALSE
21 | mov esi,1 ; initial value = 2, inc at start of loop
22 | OuterLoop:
23 | inc esi ; next value
24 | cmp esi,sqrt_n ; ESI > sqrt_n ?
25 | ja Display ; yes: done, display values
26 | cmp A[esi],TRUE ; A[ESI] == true ?
27 | jne OuterLoop ; no: continue loop
28 | mov edi,esi
29 | imul edi,edi ; InnerLoop initial val = ESI^2
30 | InnerLoop:
31 | cmp edi,n ; EDI > n ?
32 | jae OuterLoop ; yes: continue outer loop
33 | mov A[edi],FALSE ; no: value is not prime
34 | add edi,esi ; EDI = ESI^2 + ESI, ESI^2 + 2 * ESI ...
35 | jmp InnerLoop
36 | Display:
37 | mov esi,1 ; initial value = 2, inc at start of loop
38 | DisplayPrimeNumbers:
39 | inc esi
40 | cmp esi,n ; ESI >= n ?
41 | jae Done ; yes: done
42 | cmp BYTE PTR A[esi],TRUE ; A[ESI] == TRUE ?
43 | jne DisplayPrimeNumbers ; no: value is not prime, continue loop
44 | mov eax,esi ; yes: value is prime, display it
45 | call WriteDec
46 | call Crlf
47 | jmp DisplayPrimeNumbers
48 | Done:
49 | exit
50 | main ENDP
51 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/7_6_GCD.asm:
--------------------------------------------------------------------------------
1 | TITLE Greatest Common Divisor
2 | ; This program finds the greatest common divisor of two integers.
3 | INCLUDE Irvine32.inc
4 |
5 | GCD PROTO x:SDWORD, y:SDWORD
6 | abs PROTO, x:PTR SDWORD
7 |
8 | .CODE
9 | main PROC
10 | INVOKE GCD, 54, 24
11 | call WriteInt ; 6
12 | call Crlf
13 | INVOKE GCD, 42, 56
14 | call WriteInt ; 14
15 | call Crlf
16 | INVOKE GCD, 48, 180
17 | call WriteInt ; 12
18 | call Crlf
19 | INVOKE GCD, -24, 54
20 | call WriteInt ; 6
21 | call Crlf
22 | exit
23 | main ENDP
24 |
25 | ;-----------------------------------------------------
26 | GCD PROC USES ebx edx,
27 | x:SDWORD,
28 | y:SDWORD
29 | ;
30 | ; Calculates the GCD of two 32-bit integers.
31 | ; Returns: EAX = GCD(x,y)
32 | ;-----------------------------------------------------
33 | INVOKE abs, ADDR x ; x = abs(x)
34 | INVOKE abs, ADDR y ; y = abs(y)
35 |
36 | LoopStart: ; do {
37 | mov edx,0
38 | mov eax,x
39 | mov ebx,y
40 | div ebx ; EDX = x % y
41 | mov x,ebx ; x = y
42 | mov y,edx ; y = EDX
43 | cmp y,0
44 | jle Done
45 | jmp LoopStart ; } while (y > 0)
46 | Done:
47 | mov eax,x ; return the GCD in EAX
48 | ret
49 | GCD ENDP
50 |
51 | ;-----------------------------------------------------
52 | abs PROC USES eax edx esi,
53 | val:PTR SDWORD
54 | ;
55 | ; Calculates the absolute value of a 32-bit integer using
56 | ; abs(val) = (val XOR val2) - val2
57 | ; where val2 = val SAR 31.
58 | ; Returns: val = abs(val)
59 | ;-----------------------------------------------------
60 | mov esi,val
61 | mov eax,[esi] ; [esi] is memory for val on stack
62 | sar eax,31 ; EAX = val2
63 | mov edx,eax
64 | xor edx,[esi] ; EDX = val XOR val2
65 | mov [esi],edx ; [esi] is memory for output on stack
66 | sub [esi],eax ; (val XOR val2) - val2
67 | ret
68 | abs ENDP
69 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/7_7_BitwiseMultiplication.asm:
--------------------------------------------------------------------------------
1 | TITLE Bitwise Multiplication
2 |
3 | INCLUDE Irvine32.inc
4 |
5 | .CODE
6 | main PROC
7 | mov eax,123
8 | mov ebx,36
9 | call BitwiseMultiply
10 | call DumpRegs ; EAX = 114Ch, 4428d
11 | exit
12 | main ENDP
13 |
14 | ;-----------------------------------------------------
15 | BitwiseMultiply PROC USES ebx edx
16 | ;
17 | ; Multiplies any unsigned 32-bit integer by EAX, using only shifting and
18 | ; addition.
19 | ; Receives: EAX = multiplicand, EBX = multiplier
20 | ; Returns: EAX = product
21 | mov edx,eax ; EDX = multiplicand
22 | mov eax,0 ; initialise result
23 | jmp CmpMultiplier ; while multiplier > 0
24 | TestMultiplier:
25 | test ebx,1
26 | jp NotOdd ; if multiplier is odd, add multiplicand to result
27 | add eax,edx
28 | NotOdd:
29 | shl edx,1 ; double multiplicand
30 | shr ebx,1 ; halve multiplier
31 | CmpMultiplier:
32 | cmp ebx,0
33 | ja TestMultiplier
34 | ret
35 | BitwiseMultiply ENDP
36 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/Board_main.asm:
--------------------------------------------------------------------------------
1 | ; Chess Board Program (Board_main.asm)
2 |
3 | ; This program draws an 8X8 chess board, with alternating gray and white
4 | ; squares.
5 | INCLUDE board.inc
6 |
7 | .CODE
8 | main PROC
9 | call Clrscr
10 | INVOKE DrawBoard
11 | exit
12 | main ENDP
13 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/Inputs_main.asm:
--------------------------------------------------------------------------------
1 | ; DifferentInputs Program (Inputs_main.asm)
2 |
3 | ; Test program for the DifferentInputs procedure.
4 |
5 | INCLUDE inputs.inc
6 |
7 | .CODE
8 | main PROC
9 | call Clrscr
10 | INVOKE DifferentInputs, 1, 1, 1
11 | call DumpRegs ; EAX = 0
12 | INVOKE DifferentInputs, 2, 1, 1
13 | call DumpRegs ; EAX = 0
14 | INVOKE DifferentInputs, 1, 2, 3
15 | call DumpRegs ; EAX = 1
16 | INVOKE DifferentInputs, 1, 2, 1
17 | call DumpRegs ; EAX = 0
18 | INVOKE DifferentInputs, 0, 1, 4
19 | call DumpRegs ; EAX = 1
20 | exit
21 | main ENDP
22 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/Intel-Assembly-Language-Programming-Exercises.lst:
--------------------------------------------------------------------------------
1 | Microsoft (R) Macro Assembler Version 14.14.26428.1 06/25/18 18:29:03
2 | Inputs_main.asm Page 1 - 1
3 |
4 |
5 | ; DifferentInputs Program (Inputs_main.asm)
6 |
7 | ; Test program for the DifferentInputs procedure.
8 |
9 | INCLUDE inputs.inc
10 | C ; Include file for the DifferentInputs Program (inputs.inc)
11 | C INCLUDE Irvine32.inc
12 | C ; Include file for Irvine32.lib (Irvine32.inc)
13 | C
14 | C ;OPTION CASEMAP:NONE ; optional: make identifiers case-sensitive
15 | C
16 | C INCLUDE SmallWin.inc ; MS-Windows prototypes, structures, and constants
17 | C .NOLIST
18 | C .LIST
19 | C
20 | C INCLUDE VirtualKeys.inc
21 | C ; VirtualKeys.inc
22 | C .NOLIST
23 | C .LIST
24 | C
25 | C
26 | C .NOLIST
27 | C .LIST
28 | C
29 | C
30 | C DifferentInputs PROTO,
31 | C input1:DWORD,
32 | C input2:DWORD,
33 | C input3:DWORD
34 | C
35 |
36 | 00000000 .CODE
37 | 00000000 main PROC
38 | 00000000 E8 00000000 E call Clrscr
39 | INVOKE DifferentInputs, 1, 1, 1
40 | 00000010 E8 00000000 E call DumpRegs ; EAX = 0
41 | INVOKE DifferentInputs, 2, 1, 1
42 | 00000020 E8 00000000 E call DumpRegs ; EAX = 0
43 | INVOKE DifferentInputs, 1, 2, 3
44 | 00000030 E8 00000000 E call DumpRegs ; EAX = 1
45 | INVOKE DifferentInputs, 1, 2, 1
46 | 00000040 E8 00000000 E call DumpRegs ; EAX = 0
47 | INVOKE DifferentInputs, 0, 1, 4
48 | 00000050 E8 00000000 E call DumpRegs ; EAX = 1
49 | exit
50 | 0000005C main ENDP
51 | END main
52 | Microsoft (R) Macro Assembler Version 14.14.26428.1 06/25/18 18:29:03
53 | Inputs_main.asm Symbols 2 - 1
54 |
55 |
56 |
57 |
58 | Structures and Unions:
59 |
60 | N a m e Size
61 | Offset Type
62 |
63 | CONSOLE_CURSOR_INFO . . . . . . 00000008
64 | dwSize . . . . . . . . . . . . 00000000 DWord
65 | bVisible . . . . . . . . . . . 00000004 DWord
66 | CONSOLE_SCREEN_BUFFER_INFO . . . 00000016
67 | dwSize . . . . . . . . . . . . 00000000 DWord
68 | dwCursorPosition . . . . . . . 00000004 DWord
69 | wAttributes . . . . . . . . . 00000008 Word
70 | srWindow . . . . . . . . . . . 0000000A QWord
71 | dwMaximumWindowSize . . . . . 00000012 DWord
72 | COORD . . . . . . . . . . . . . 00000004
73 | X . . . . . . . . . . . . . . 00000000 Word
74 | Y . . . . . . . . . . . . . . 00000002 Word
75 | FILETIME . . . . . . . . . . . . 00000008
76 | loDateTime . . . . . . . . . . 00000000 DWord
77 | hiDateTime . . . . . . . . . . 00000004 DWord
78 | FOCUS_EVENT_RECORD . . . . . . . 00000004
79 | bSetFocus . . . . . . . . . . 00000000 DWord
80 | FPU_ENVIRON . . . . . . . . . . 0000001C
81 | controlWord . . . . . . . . . 00000000 Word
82 | statusWord . . . . . . . . . . 00000004 Word
83 | tagWord . . . . . . . . . . . 00000008 Word
84 | instrPointerOffset . . . . . . 0000000C DWord
85 | instrPointerSelector . . . . . 00000010 DWord
86 | operandPointerOffset . . . . . 00000014 DWord
87 | operandPointerSelector . . . . 00000018 Word
88 | INPUT_RECORD . . . . . . . . . . 00000014
89 | EventType . . . . . . . . . . 00000000 Word
90 | Event . . . . . . . . . . . . 00000004 XmmWord
91 | bKeyDown . . . . . . . . . . . 00000000 DWord
92 | wRepeatCount . . . . . . . . . 00000004 Word
93 | wVirtualKeyCode . . . . . . . 00000006 Word
94 | wVirtualScanCode . . . . . . . 00000008 Word
95 | uChar . . . . . . . . . . . . 0000000A Word
96 | UnicodeChar . . . . . . . . . 00000000 Word
97 | AsciiChar . . . . . . . . . . 00000000 Byte
98 | dwControlKeyState . . . . . . 0000000C DWord
99 | dwMousePosition . . . . . . . 00000000 DWord
100 | dwButtonState . . . . . . . . 00000004 DWord
101 | dwMouseControlKeyState . . . . 00000008 DWord
102 | dwEventFlags . . . . . . . . . 0000000C DWord
103 | dwSize . . . . . . . . . . . . 00000000 DWord
104 | dwCommandId . . . . . . . . . 00000000 DWord
105 | bSetFocus . . . . . . . . . . 00000000 DWord
106 | KEY_EVENT_RECORD . . . . . . . . 00000010
107 | bKeyDown . . . . . . . . . . . 00000000 DWord
108 | wRepeatCount . . . . . . . . . 00000004 Word
109 | wVirtualKeyCode . . . . . . . 00000006 Word
110 | wVirtualScanCode . . . . . . . 00000008 Word
111 | uChar . . . . . . . . . . . . 0000000A Word
112 | UnicodeChar . . . . . . . . . 00000000 Word
113 | AsciiChar . . . . . . . . . . 00000000 Byte
114 | dwControlKeyState . . . . . . 0000000C DWord
115 | MENU_EVENT_RECORD . . . . . . . 00000004
116 | dwCommandId . . . . . . . . . 00000000 DWord
117 | MOUSE_EVENT_RECORD . . . . . . . 00000010
118 | dwMousePosition . . . . . . . 00000000 DWord
119 | dwButtonState . . . . . . . . 00000004 DWord
120 | dwMouseControlKeyState . . . . 00000008 DWord
121 | dwEventFlags . . . . . . . . . 0000000C DWord
122 | SMALL_RECT . . . . . . . . . . . 00000008
123 | Left . . . . . . . . . . . . . 00000000 Word
124 | Top . . . . . . . . . . . . . 00000002 Word
125 | Right . . . . . . . . . . . . 00000004 Word
126 | Bottom . . . . . . . . . . . . 00000006 Word
127 | SYSTEMTIME . . . . . . . . . . . 00000010
128 | wYear . . . . . . . . . . . . 00000000 Word
129 | wMonth . . . . . . . . . . . . 00000002 Word
130 | wDayOfWeek . . . . . . . . . . 00000004 Word
131 | wDay . . . . . . . . . . . . . 00000006 Word
132 | wHour . . . . . . . . . . . . 00000008 Word
133 | wMinute . . . . . . . . . . . 0000000A Word
134 | wSecond . . . . . . . . . . . 0000000C Word
135 | wMilliseconds . . . . . . . . 0000000E Word
136 | WINDOW_BUFFER_SIZE_RECORD . . . 00000004
137 | dwSize . . . . . . . . . . . . 00000000 DWord
138 |
139 |
140 | Segments and Groups:
141 |
142 | N a m e Size Length Align Combine Class
143 |
144 | FLAT . . . . . . . . . . . . . . GROUP
145 | STACK . . . . . . . . . . . . . 32 Bit 00001000 Para Stack 'STACK'
146 | _DATA . . . . . . . . . . . . . 32 Bit 00000000 Para Public 'DATA'
147 | _TEXT . . . . . . . . . . . . . 32 Bit 0000005C Para Public 'CODE'
148 |
149 |
150 | Procedures, parameters, and locals:
151 |
152 | N a m e Type Value Attr
153 |
154 | CloseFile . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
155 | CloseHandle . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
156 | Clrscr . . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
157 | CreateFileA . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
158 | CreateOutputFile . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
159 | Crlf . . . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
160 | Delay . . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
161 | DifferentInputs . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
162 | DumpMem . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
163 | DumpRegs . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
164 | ExitProcess . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
165 | FileTimeToDosDateTime . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
166 | FileTimeToSystemTime . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
167 | FlushConsoleInputBuffer . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
168 | FormatMessageA . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
169 | GetCommandLineA . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
170 | GetCommandTail . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
171 | GetConsoleCP . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
172 | GetConsoleCursorInfo . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
173 | GetConsoleMode . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
174 | GetConsoleScreenBufferInfo . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
175 | GetDateTime . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
176 | GetFileTime . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
177 | GetKeyState . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
178 | GetLastError . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
179 | GetLocalTime . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
180 | GetMaxXY . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
181 | GetMseconds . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
182 | GetNumberOfConsoleInputEvents . P Near 00000000 FLAT Length= 00000000 External STDCALL
183 | GetProcessHeap . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
184 | GetStdHandle . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
185 | GetSystemTime . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
186 | GetTextColor . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
187 | GetTickCount . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
188 | Gotoxy . . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
189 | HeapAlloc . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
190 | HeapCreate . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
191 | HeapDestroy . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
192 | HeapFree . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
193 | HeapSize . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
194 | IsDigit . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
195 | LocalFree . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
196 | MessageBoxA . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
197 | MsgBoxAsk . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
198 | MsgBox . . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
199 | OpenInputFile . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
200 | ParseDecimal32 . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
201 | ParseInteger32 . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
202 | PeekConsoleInputA . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
203 | Random32 . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
204 | RandomRange . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
205 | Randomize . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
206 | ReadChar . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
207 | ReadConsoleA . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
208 | ReadConsoleInputA . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
209 | ReadDec . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
210 | ReadFile . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
211 | ReadFloat . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
212 | ReadFromFile . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
213 | ReadHex . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
214 | ReadInt . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
215 | ReadKeyFlush . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
216 | ReadKey . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
217 | ReadString . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
218 | SetConsoleCursorInfo . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
219 | SetConsoleCursorPosition . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
220 | SetConsoleMode . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
221 | SetConsoleScreenBufferSize . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
222 | SetConsoleTextAttribute . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
223 | SetConsoleTitleA . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
224 | SetConsoleWindowInfo . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
225 | SetFilePointer . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
226 | SetLocalTime . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
227 | SetTextColor . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
228 | ShowFPUStack . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
229 | Sleep . . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
230 | StrLength . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
231 | Str_compare . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
232 | Str_copy . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
233 | Str_length . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
234 | Str_trim . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
235 | Str_ucase . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
236 | SystemTimeToFileTime . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
237 | WaitMsg . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
238 | WriteBinB . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
239 | WriteBin . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
240 | WriteChar . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
241 | WriteConsoleA . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
242 | WriteConsoleOutputAttribute . . P Near 00000000 FLAT Length= 00000000 External STDCALL
243 | WriteConsoleOutputCharacterA . . P Near 00000000 FLAT Length= 00000000 External STDCALL
244 | WriteDec . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
245 | WriteFile . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
246 | WriteFloat . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
247 | WriteHexB . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
248 | WriteHex . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
249 | WriteInt . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
250 | WriteStackFrameName . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
251 | WriteStackFrame . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
252 | WriteString . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
253 | WriteToFile . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
254 | WriteWindowsMsg . . . . . . . . P Near 00000000 FLAT Length= 00000000 External STDCALL
255 | main . . . . . . . . . . . . . . P Near 00000000 _TEXT Length= 0000005C Public STDCALL
256 | printf . . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External C
257 | scanf . . . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External C
258 | wsprintfA . . . . . . . . . . . P Near 00000000 FLAT Length= 00000000 External C
259 |
260 |
261 | Symbols:
262 |
263 | N a m e Type Value Attr
264 |
265 | @CodeSize . . . . . . . . . . . Number 00000000h
266 | @DataSize . . . . . . . . . . . Number 00000000h
267 | @Interface . . . . . . . . . . . Number 00000003h
268 | @Model . . . . . . . . . . . . . Number 00000007h
269 | @code . . . . . . . . . . . . . Text _TEXT
270 | @data . . . . . . . . . . . . . Text FLAT
271 | @fardata? . . . . . . . . . . . Text FLAT
272 | @fardata . . . . . . . . . . . . Text FLAT
273 | @stack . . . . . . . . . . . . . Text FLAT
274 | ALT_MASK . . . . . . . . . . . . Number 00000003h
275 | CAPSLOCK_ON . . . . . . . . . . Number 00000080h
276 | CREATE_ALWAYS . . . . . . . . . Number 00000002h
277 | CREATE_NEW . . . . . . . . . . . Number 00000001h
278 | CTRL_MASK . . . . . . . . . . . Number 0000000Ch
279 | CreateFile . . . . . . . . . . . Text CreateFileA
280 | DO_NOT_SHARE . . . . . . . . . . Number 00000000h
281 | ENABLE_ECHO_INPUT . . . . . . . Number 00000004h
282 | ENABLE_LINE_INPUT . . . . . . . Number 00000002h
283 | ENABLE_MOUSE_INPUT . . . . . . . Number 00000010h
284 | ENABLE_PROCESSED_INPUT . . . . . Number 00000001h
285 | ENABLE_PROCESSED_OUTPUT . . . . Number 00000001h
286 | ENABLE_WINDOW_INPUT . . . . . . Number 00000008h
287 | ENABLE_WRAP_AT_EOL_OUTPUT . . . Number 00000002h
288 | ENHANCED_KEY . . . . . . . . . . Number 00000100h
289 | FALSE . . . . . . . . . . . . . Number 00000000h
290 | FILE_APPEND_DATA . . . . . . . . Number 00000004h
291 | FILE_ATTRIBUTE_ARCHIVE . . . . . Number 00000020h
292 | FILE_ATTRIBUTE_COMPRESSED . . . Number 00000800h
293 | FILE_ATTRIBUTE_DEVICE . . . . . Number 00000040h
294 | FILE_ATTRIBUTE_DIRECTORY . . . . Number 00000010h
295 | FILE_ATTRIBUTE_ENCRYPTED . . . . Number 00004000h
296 | FILE_ATTRIBUTE_HIDDEN . . . . . Number 00000002h
297 | FILE_ATTRIBUTE_NORMAL . . . . . Number 00000080h
298 | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED . Number 00002000h
299 | FILE_ATTRIBUTE_OFFLINE . . . . . Number 00001000h
300 | FILE_ATTRIBUTE_READONLY . . . . Number 00000001h
301 | FILE_ATTRIBUTE_REPARSE_POINT . . Number 00000400h
302 | FILE_ATTRIBUTE_SPARSE_FILE . . . Number 00000200h
303 | FILE_ATTRIBUTE_SYSTEM . . . . . Number 00000004h
304 | FILE_ATTRIBUTE_TEMPORARY . . . . Number 00000100h
305 | FILE_BEGIN . . . . . . . . . . . Number 00000000h
306 | FILE_CURRENT . . . . . . . . . . Number 00000001h
307 | FILE_DELETE_CHILD . . . . . . . Number 00000040h
308 | FILE_END . . . . . . . . . . . . Number 00000002h
309 | FILE_READ_DATA . . . . . . . . . Number 00000001h
310 | FILE_SHARE_DELETE . . . . . . . Number 00000004h
311 | FILE_SHARE_READ . . . . . . . . Number 00000001h
312 | FILE_SHARE_WRITE . . . . . . . . Number 00000002h
313 | FILE_WRITE_DATA . . . . . . . . Number 00000002h
314 | FOCUS_EVENT . . . . . . . . . . Number 00000010h
315 | FORMAT_MESSAGE_ALLOCATE_BUFFER . Number 00000100h
316 | FORMAT_MESSAGE_FROM_SYSTEM . . . Number 00001000h
317 | FormatMessage . . . . . . . . . Text FormatMessageA
318 | GENERIC_ALL . . . . . . . . . . Number 10000000h
319 | GENERIC_EXECUTE . . . . . . . . Number 20000000h
320 | GENERIC_READ . . . . . . . . . . Number -80000000h
321 | GENERIC_WRITE . . . . . . . . . Number 40000000h
322 | GetCommandLine . . . . . . . . . Text GetCommandLineA
323 | HANDLE . . . . . . . . . . . . . Text DWORD
324 | HEAP_GENERATE_EXCEPTIONS . . . . Number 00000004h
325 | HEAP_GROWABLE . . . . . . . . . Number 00000002h
326 | HEAP_NO_SERIALIZE . . . . . . . Number 00000001h
327 | HEAP_REALLOC_IN_PLACE_ONLY . . . Number 00000010h
328 | HEAP_ZERO_MEMORY . . . . . . . . Number 00000008h
329 | IDABORT . . . . . . . . . . . . Number 00000003h
330 | IDCANCEL . . . . . . . . . . . . Number 00000002h
331 | IDCLOSE . . . . . . . . . . . . Number 00000008h
332 | IDCONTINUE . . . . . . . . . . . Number 0000000Bh
333 | IDHELP . . . . . . . . . . . . . Number 00000009h
334 | IDIGNORE . . . . . . . . . . . . Number 00000005h
335 | IDNO . . . . . . . . . . . . . . Number 00000007h
336 | IDOK . . . . . . . . . . . . . . Number 00000001h
337 | IDRETRY . . . . . . . . . . . . Number 00000004h
338 | IDTIMEOUT . . . . . . . . . . . Number 00007D00h
339 | IDTRYAGAIN . . . . . . . . . . . Number 0000000Ah
340 | IDYES . . . . . . . . . . . . . Number 00000006h
341 | INVALID_HANDLE_VALUE . . . . . . Number -00000001h
342 | KBDOWN_FLAG . . . . . . . . . . Number 00000001h
343 | KEY_EVENT . . . . . . . . . . . Number 00000001h
344 | KEY_MASKS . . . . . . . . . . . Number 0000001Fh
345 | LEFT_ALT_PRESSED . . . . . . . . Number 00000002h
346 | LEFT_CTRL_PRESSED . . . . . . . Number 00000008h
347 | MB_ABORTRETRYIGNORE . . . . . . Number 00000002h
348 | MB_APPLMODAL . . . . . . . . . . Number 00000000h
349 | MB_CANCELTRYCONTINUE . . . . . . Number 00000006h
350 | MB_DEFBUTTON1 . . . . . . . . . Number 00000000h
351 | MB_DEFBUTTON2 . . . . . . . . . Number 00000100h
352 | MB_DEFBUTTON3 . . . . . . . . . Number 00000200h
353 | MB_DEFBUTTON4 . . . . . . . . . Number 00000300h
354 | MB_HELP . . . . . . . . . . . . Number 00004000h
355 | MB_ICONASTERISK . . . . . . . . Number 00000040h
356 | MB_ICONERROR . . . . . . . . . . Number 00000010h
357 | MB_ICONEXCLAMATION . . . . . . . Number 00000030h
358 | MB_ICONHAND . . . . . . . . . . Number 00000010h
359 | MB_ICONINFORMATION . . . . . . . Number 00000040h
360 | MB_ICONQUESTION . . . . . . . . Number 00000020h
361 | MB_ICONSTOP . . . . . . . . . . Number 00000010h
362 | MB_ICONWARNING . . . . . . . . . Number 00000030h
363 | MB_OKCANCEL . . . . . . . . . . Number 00000001h
364 | MB_OK . . . . . . . . . . . . . Number 00000000h
365 | MB_RETRYCANCEL . . . . . . . . . Number 00000005h
366 | MB_SYSTEMMODAL . . . . . . . . . Number 00001000h
367 | MB_TASKMODAL . . . . . . . . . . Number 00002000h
368 | MB_USERICON . . . . . . . . . . Number 00000080h
369 | MB_YESNOCANCEL . . . . . . . . . Number 00000003h
370 | MB_YESNO . . . . . . . . . . . . Number 00000004h
371 | MENU_EVENT . . . . . . . . . . . Number 00000008h
372 | MOUSE_EVENT . . . . . . . . . . Number 00000002h
373 | MessageBox . . . . . . . . . . . Text MessageBoxA
374 | NULL . . . . . . . . . . . . . . Number 00000000h
375 | NUMLOCK_ON . . . . . . . . . . . Number 00000020h
376 | OPEN_ALWAYS . . . . . . . . . . Number 00000004h
377 | OPEN_EXISTING . . . . . . . . . Number 00000003h
378 | PeekConsoleInput . . . . . . . . Text PeekConsoleInputA
379 | RIGHT_ALT_PRESSED . . . . . . . Number 00000001h
380 | RIGHT_CTRL_PRESSED . . . . . . . Number 00000004h
381 | ReadConsoleInput . . . . . . . . Text ReadConsoleInputA
382 | ReadConsole . . . . . . . . . . Text ReadConsoleA
383 | SCROLLLOCK_ON . . . . . . . . . Number 00000040h
384 | SHIFT_MASK . . . . . . . . . . . Number 00000010h
385 | SHIFT_PRESSED . . . . . . . . . Number 00000010h
386 | STD_ERROR_HANDLE . . . . . . . . Number -0000000Ch
387 | STD_INPUT_HANDLE . . . . . . . . Number -0000000Ah
388 | STD_OUTPUT_HANDLE . . . . . . . Number -0000000Bh
389 | SetConsoleTitle . . . . . . . . Text SetConsoleTitleA
390 | TAB . . . . . . . . . . . . . . Number 00000009h
391 | TRUE . . . . . . . . . . . . . . Number 00000001h
392 | TRUNCATE_EXISTING . . . . . . . Number 00000005h
393 | VK_11 . . . . . . . . . . . . . Number 000000BDh
394 | VK_12 . . . . . . . . . . . . . Number 000000BBh
395 | VK_ADD . . . . . . . . . . . . . Number 0000006Bh
396 | VK_BACK . . . . . . . . . . . . Number 00000008h
397 | VK_CANCEL . . . . . . . . . . . Number 00000003h
398 | VK_CAPITAL . . . . . . . . . . . Number 00000014h
399 | VK_CLEAR . . . . . . . . . . . . Number 0000000Ch
400 | VK_CONTROL . . . . . . . . . . . Number 00000011h
401 | VK_DECIMAL . . . . . . . . . . . Number 0000006Eh
402 | VK_DELETE . . . . . . . . . . . Number 0000002Eh
403 | VK_DIVIDE . . . . . . . . . . . Number 0000006Fh
404 | VK_DOWN . . . . . . . . . . . . Number 00000028h
405 | VK_END . . . . . . . . . . . . . Number 00000023h
406 | VK_ESCAPE . . . . . . . . . . . Number 0000001Bh
407 | VK_EXECUTE . . . . . . . . . . . Number 0000002Bh
408 | VK_F10 . . . . . . . . . . . . . Number 00000079h
409 | VK_F11 . . . . . . . . . . . . . Number 0000007Ah
410 | VK_F12 . . . . . . . . . . . . . Number 0000007Bh
411 | VK_F13 . . . . . . . . . . . . . Number 0000007Ch
412 | VK_F14 . . . . . . . . . . . . . Number 0000007Dh
413 | VK_F15 . . . . . . . . . . . . . Number 0000007Eh
414 | VK_F16 . . . . . . . . . . . . . Number 0000007Fh
415 | VK_F17 . . . . . . . . . . . . . Number 00000080h
416 | VK_F18 . . . . . . . . . . . . . Number 00000081h
417 | VK_F19 . . . . . . . . . . . . . Number 00000082h
418 | VK_F1 . . . . . . . . . . . . . Number 00000070h
419 | VK_F20 . . . . . . . . . . . . . Number 00000083h
420 | VK_F21 . . . . . . . . . . . . . Number 00000084h
421 | VK_F22 . . . . . . . . . . . . . Number 00000085h
422 | VK_F23 . . . . . . . . . . . . . Number 00000086h
423 | VK_F24 . . . . . . . . . . . . . Number 00000087h
424 | VK_F2 . . . . . . . . . . . . . Number 00000071h
425 | VK_F3 . . . . . . . . . . . . . Number 00000072h
426 | VK_F4 . . . . . . . . . . . . . Number 00000073h
427 | VK_F5 . . . . . . . . . . . . . Number 00000074h
428 | VK_F6 . . . . . . . . . . . . . Number 00000075h
429 | VK_F7 . . . . . . . . . . . . . Number 00000076h
430 | VK_F8 . . . . . . . . . . . . . Number 00000077h
431 | VK_F9 . . . . . . . . . . . . . Number 00000078h
432 | VK_HELP . . . . . . . . . . . . Number 0000002Fh
433 | VK_HOME . . . . . . . . . . . . Number 00000024h
434 | VK_INSERT . . . . . . . . . . . Number 0000002Dh
435 | VK_LBUTTON . . . . . . . . . . . Number 00000001h
436 | VK_LCONTROL . . . . . . . . . . Number 000000A2h
437 | VK_LEFT . . . . . . . . . . . . Number 00000025h
438 | VK_LMENU . . . . . . . . . . . . Number 000000A4h
439 | VK_LSHIFT . . . . . . . . . . . Number 000000A0h
440 | VK_MENU . . . . . . . . . . . . Number 00000012h
441 | VK_MULTIPLY . . . . . . . . . . Number 0000006Ah
442 | VK_NEXT . . . . . . . . . . . . Number 00000022h
443 | VK_NUMLOCK . . . . . . . . . . . Number 00000090h
444 | VK_NUMPAD0 . . . . . . . . . . . Number 00000060h
445 | VK_NUMPAD1 . . . . . . . . . . . Number 00000061h
446 | VK_NUMPAD2 . . . . . . . . . . . Number 00000062h
447 | VK_NUMPAD3 . . . . . . . . . . . Number 00000063h
448 | VK_NUMPAD4 . . . . . . . . . . . Number 00000064h
449 | VK_NUMPAD5 . . . . . . . . . . . Number 00000065h
450 | VK_NUMPAD6 . . . . . . . . . . . Number 00000066h
451 | VK_NUMPAD7 . . . . . . . . . . . Number 00000067h
452 | VK_NUMPAD8 . . . . . . . . . . . Number 00000068h
453 | VK_NUMPAD9 . . . . . . . . . . . Number 00000069h
454 | VK_PAUSE . . . . . . . . . . . . Number 00000013h
455 | VK_PRINT . . . . . . . . . . . . Number 0000002Ah
456 | VK_PRIOR . . . . . . . . . . . . Number 00000021h
457 | VK_RBUTTON . . . . . . . . . . . Number 00000002h
458 | VK_RCONTROL . . . . . . . . . . Number 000000A3h
459 | VK_RETURN . . . . . . . . . . . Number 0000000Dh
460 | VK_RIGHT . . . . . . . . . . . . Number 00000027h
461 | VK_RMENU . . . . . . . . . . . . Number 000000A5h
462 | VK_RSHIFT . . . . . . . . . . . Number 000000A1h
463 | VK_SCROLL . . . . . . . . . . . Number 00000091h
464 | VK_SEPARATER . . . . . . . . . . Number 0000006Ch
465 | VK_SHIFT . . . . . . . . . . . . Number 00000010h
466 | VK_SNAPSHOT . . . . . . . . . . Number 0000002Ch
467 | VK_SPACE . . . . . . . . . . . . Number 00000020h
468 | VK_SUBTRACT . . . . . . . . . . Number 0000006Dh
469 | VK_TAB . . . . . . . . . . . . . Number 00000009h
470 | VK_UP . . . . . . . . . . . . . Number 00000026h
471 | WINDOW_BUFFER_SIZE_EVENT . . . . Number 00000004h
472 | WriteConsoleOutputCharacter . . Text WriteConsoleOutputCharacterA
473 | WriteConsole . . . . . . . . . . Text WriteConsoleA
474 | black . . . . . . . . . . . . . Number 00000000h
475 | blue . . . . . . . . . . . . . . Number 00000001h
476 | brown . . . . . . . . . . . . . Number 00000006h
477 | cyan . . . . . . . . . . . . . . Number 00000003h
478 | exit . . . . . . . . . . . . . . Text INVOKE ExitProcess,0
479 | gray . . . . . . . . . . . . . . Number 00000008h
480 | green . . . . . . . . . . . . . Number 00000002h
481 | lightBlue . . . . . . . . . . . Number 00000009h
482 | lightCyan . . . . . . . . . . . Number 0000000Bh
483 | lightGray . . . . . . . . . . . Number 00000007h
484 | lightGreen . . . . . . . . . . . Number 0000000Ah
485 | lightMagenta . . . . . . . . . . Number 0000000Dh
486 | lightRed . . . . . . . . . . . . Number 0000000Ch
487 | magenta . . . . . . . . . . . . Number 00000005h
488 | red . . . . . . . . . . . . . . Number 00000004h
489 | white . . . . . . . . . . . . . Number 0000000Fh
490 | wsprintf . . . . . . . . . . . . Text wsprintfA
491 | yellow . . . . . . . . . . . . . Number 0000000Eh
492 |
493 | 0 Warnings
494 | 0 Errors
495 |
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/Intel-Assembly-Language-Programming-Exercises.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 15.0
23 | {48E7232B-75B1-4AFF-92DE-1EDB0BF7077E}
24 | IntelAssemblyLanguageProgrammingExercises
25 | 10.0.17134.0
26 |
27 |
28 |
29 | Application
30 | true
31 | v141
32 | MultiByte
33 |
34 |
35 | Application
36 | false
37 | v141
38 | true
39 | MultiByte
40 |
41 |
42 | Application
43 | true
44 | v141
45 | MultiByte
46 |
47 |
48 | Application
49 | false
50 | v141
51 | true
52 | MultiByte
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | Level3
77 | Disabled
78 | true
79 | true
80 |
81 |
82 | C:\Irvine
83 | $(ProjectName).lst
84 |
85 |
86 | C:\Irvine
87 | irvine32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
88 | true
89 | Console
90 | false
91 | false
92 |
93 |
94 |
95 |
96 | Level3
97 | Disabled
98 | true
99 | true
100 |
101 |
102 |
103 |
104 | Level3
105 | MaxSpeed
106 | true
107 | true
108 | true
109 | true
110 |
111 |
112 | true
113 | true
114 |
115 |
116 |
117 |
118 | Level3
119 | MaxSpeed
120 | true
121 | true
122 | true
123 | true
124 |
125 |
126 | true
127 | true
128 |
129 |
130 |
131 |
132 | true
133 | Document
134 |
135 |
136 | true
137 |
138 |
139 | true
140 |
141 |
142 | true
143 |
144 |
145 | true
146 |
147 |
148 | true
149 |
150 |
151 | true
152 |
153 |
154 | true
155 |
156 |
157 | true
158 |
159 |
160 | true
161 |
162 |
163 | true
164 |
165 |
166 | true
167 |
168 |
169 | true
170 |
171 |
172 | true
173 |
174 |
175 | true
176 |
177 |
178 | true
179 |
180 |
181 | true
182 |
183 |
184 | true
185 |
186 |
187 | true
188 |
189 |
190 | true
191 |
192 |
193 | true
194 |
195 |
196 | true
197 |
198 |
199 | true
200 |
201 |
202 | true
203 |
204 |
205 | true
206 |
207 |
208 | true
209 |
210 |
211 | true
212 |
213 |
214 | true
215 |
216 |
217 | true
218 |
219 |
220 | true
221 |
222 |
223 | true
224 |
225 |
226 | true
227 |
228 |
229 | true
230 |
231 |
232 | true
233 |
234 |
235 | true
236 |
237 |
238 | true
239 |
240 |
241 | true
242 |
243 |
244 | true
245 |
246 |
247 |
248 | true
249 |
250 |
251 | true
252 |
253 |
254 |
255 | true
256 |
257 |
258 | true
259 |
260 |
261 | true
262 |
263 |
264 | true
265 |
266 |
267 | true
268 |
269 |
270 | true
271 |
272 |
273 |
274 |
275 | true
276 |
277 |
278 |
279 | true
280 |
281 |
282 | true
283 |
284 |
285 |
286 |
287 |
288 |
289 |
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/Intel-Assembly-Language-Programming-Exercises.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {9e563c40-0f14-404e-99a9-970c8ee00f8e}
6 |
7 |
8 | {aa1b131b-eabe-4284-b37d-49cbba044fe7}
9 |
10 |
11 | {d2eba451-30e9-4a5b-a1f6-305d17929c22}
12 |
13 |
14 | {a7df512f-10a5-49ed-b5e3-b7222d7839fc}
15 |
16 |
17 | {a8732510-67db-4360-93e8-1638bae4ab29}
18 |
19 |
20 | {42345568-031a-423f-9d4e-e98bb90d720c}
21 |
22 |
23 | {0b56d321-2cd7-466f-86ff-69ed08858a31}
24 |
25 |
26 | {4f7c7dff-40f3-4d39-850c-cb1670e3f306}
27 |
28 |
29 | {286e86e1-2212-4d7f-ae9f-2b5fc6777769}
30 |
31 |
32 | {02774db5-02b7-423d-bbce-88d68e109aa3}
33 |
34 |
35 |
36 |
37 | Chapter3
38 |
39 |
40 | Chapter3
41 |
42 |
43 | Chapter4
44 |
45 |
46 | Chapter4
47 |
48 |
49 | Chapter4
50 |
51 |
52 | Chapter4
53 |
54 |
55 | Chapter4
56 |
57 |
58 | Chapter4
59 |
60 |
61 | Chapter4
62 |
63 |
64 | Chapter4
65 |
66 |
67 | Chapter5
68 |
69 |
70 | Chapter5
71 |
72 |
73 | Chapter5
74 |
75 |
76 | Chapter5
77 |
78 |
79 | Chapter5
80 |
81 |
82 | Chapter5
83 |
84 |
85 | Chapter5
86 |
87 |
88 | Chapter5
89 |
90 |
91 | Chapter5
92 |
93 |
94 | Chapter5
95 |
96 |
97 | Chapter5
98 |
99 |
100 | Chapter6
101 |
102 |
103 | Chapter6
104 |
105 |
106 | Chapter6
107 |
108 |
109 | Chapter6
110 |
111 |
112 | Chapter6
113 |
114 |
115 | Chapter6
116 |
117 |
118 | Chapter6
119 |
120 |
121 | Chapter6
122 |
123 |
124 | Chapter7
125 |
126 |
127 | Chapter7
128 |
129 |
130 | Chapter7
131 |
132 |
133 | Chapter8\1. FindLargest
134 |
135 |
136 | Chapter8\1. FindLargest
137 |
138 |
139 | Chapter8\1. FindLargest
140 |
141 |
142 | Chapter8\2. Chess Board
143 |
144 |
145 | Chapter8\2. Chess Board
146 |
147 |
148 | Chapter8\2. Chess Board
149 |
150 |
151 | Chapter8\2. Chess Board
152 |
153 |
154 | Chapter8\4. FindThrees
155 |
156 |
157 | Chapter8\4. FindThrees
158 |
159 |
160 | Chapter6
161 |
162 |
163 | Chapter7
164 |
165 |
166 | Chapter7
167 |
168 |
169 | Chapter7
170 |
171 |
172 | Chapter7
173 |
174 |
175 | Chapter8\5. DifferentInputs
176 |
177 |
178 | Chapter8\5. DifferentInputs
179 |
180 |
181 |
182 |
183 | Chapter8\1. FindLargest
184 |
185 |
186 | Chapter8\2. Chess Board
187 |
188 |
189 | Chapter8\4. FindThrees
190 |
191 |
192 | Chapter8\5. DifferentInputs
193 |
194 |
195 |
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/Largest_main.asm:
--------------------------------------------------------------------------------
1 | ; FindLargest Program (Largest_main.asm)
2 |
3 | ; This program inputs three different arrays of different lengths to the
4 | ; FindLargest Procedure which then finds the largest value in each array.
5 | INCLUDE largest.inc
6 |
7 | .DATA
8 | array1 SDWORD 0,0,0,0,1,20,35,-12,66,4,0
9 | array2 SDWORD 1,0,0,0
10 | array3 SDWORD 0,0,0,0
11 | text BYTE "The largest value in the array is: ",0
12 |
13 | .DATA?
14 | largest SDWORD ?
15 |
16 | .CODE
17 | main PROC
18 | call Clrscr
19 |
20 | INVOKE FindLargest,
21 | ADDR array1,
22 | LENGTHOF array1
23 | mov largest,eax ; save the value
24 | INVOKE DisplayLargest,
25 | ADDR text,
26 | largest
27 | call Crlf
28 | INVOKE FindLargest,
29 | ADDR array2,
30 | LENGTHOF array2
31 | mov largest,eax ; save the value
32 | INVOKE DisplayLargest,
33 | ADDR text,
34 | largest
35 | call Crlf
36 | INVOKE FindLargest,
37 | ADDR array3,
38 | LENGTHOF array3
39 | mov largest,eax ; save the value
40 | INVOKE DisplayLargest,
41 | ADDR text,
42 | largest
43 | call Crlf
44 | exit
45 | main ENDP
46 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/Threes_main.asm:
--------------------------------------------------------------------------------
1 | ; FindThrees Program (Threes_main.asm)
2 |
3 | ;
4 | INCLUDE threes.inc
5 |
6 | .DATA
7 | array1 DWORD 1,2,4,5,6,3,3,4,7,8,9,3,3,3,5,6
8 | array2 DWORD 3,3,2,5,6,3,3,7,7,8,3,3,9,0,0,3
9 | array3 DWORD 1,2,3,3,4,4,4,5,5,6,6,5,5,6,5,3,3,3
10 |
11 | .CODE
12 | main PROC
13 | INVOKE FindThrees, ADDR array1, LENGTHOF array1
14 | call DumpRegs
15 | INVOKE FindThrees, ADDR array2, LENGTHOF array2
16 | call DumpRegs
17 | INVOKE FindThrees, ADDR array3, LENGTHOF array3
18 | call DumpRegs
19 | exit
20 | main ENDP
21 | END main
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/_differentinputs.asm:
--------------------------------------------------------------------------------
1 | ; DifferentInputs Procedure (_differentinputs.asm)
2 | INCLUDE inputs.inc
3 |
4 | .CODE
5 | ;-----------------------------------------------------
6 | DifferentInputs PROC USES ebx edx,
7 | input1:DWORD,
8 | input2:DWORD,
9 | input3:DWORD
10 | ;
11 | ; Returns 1 if the values of the three input parameters are all different;
12 | ; otherwise returns 0.
13 | ; Returns: EAX
14 | ;-----------------------------------------------------
15 | mov ebx,input1
16 | mov edx,input2
17 | cmp ebx,edx
18 | je Equal
19 | cmp ebx,input3
20 | je Equal
21 | cmp edx,input3
22 | je Equal
23 | mov eax,1
24 | jmp Done
25 | Equal:
26 | mov eax,0
27 | Done:
28 | ret
29 | DifferentInputs ENDP
30 | END
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/_display.asm:
--------------------------------------------------------------------------------
1 | ; DisplayLargest Procedure (_display.asm)
2 | INCLUDE largest.inc
3 |
4 | .CODE
5 | ;-----------------------------------------------------
6 | DisplayLargest PROC,
7 | ptrPrompt:PTR BYTE, ; prompt string
8 | result:DWORD ; the largest element in the array
9 | ;
10 | ; Displays the result on the console.
11 | ; Returns: nothing.
12 | ;-----------------------------------------------------
13 | push eax
14 | push edx
15 |
16 | mov edx,ptrPrompt ; pointer to prompt
17 | call WriteString
18 | mov eax,result
19 | call WriteInt ; display EAX
20 | call Crlf
21 |
22 | pop edx
23 | pop eax
24 | ret
25 | DisplayLargest ENDP
26 | END
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/_drawboard.asm:
--------------------------------------------------------------------------------
1 | ; DrawBoard Procedure (_drawboard.asm)
2 | INCLUDE board.inc
3 |
4 | .CODE
5 | ;-----------------------------------------------------
6 | DrawBoard PROC USES eax ecx
7 | ;
8 | ; Draws the entire chess board.
9 | ; Returns: nothing.
10 | ;-----------------------------------------------------
11 | mov ecx,8
12 | DrawChessBoard:
13 | dec cl
14 | INVOKE DrawRow, cl
15 | inc cl
16 | loop DrawChessBoard
17 | mov eax,0 ; set foreground & background colours to black to hide waitmsg
18 | call SetTextColor
19 | ret
20 | DrawBoard ENDP
21 | END
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/_drawrow.asm:
--------------------------------------------------------------------------------
1 | ; DrawRow Procedure (_drawrow.asm)
2 | INCLUDE board.inc
3 |
4 | .CODE
5 | ;-----------------------------------------------------
6 | DrawRow PROC USES eax ecx edx,
7 | rowNum:BYTE ; row number
8 | ;
9 | ; Draws a row of the chess board.
10 | ; Returns: nothing.
11 | ;-----------------------------------------------------
12 | mov dh,rowNum ; current row
13 | mov ecx,8 ; loop counter
14 | mov dl,0 ; first X-coordinate
15 | DrawSquares:
16 | call Gotoxy ; locate cursor at current square
17 | mov al,dl
18 | add al,dh
19 | test al,1 ; parity check
20 | jnp DrawWhite ; if odd, draw white
21 | INVOKE DrawSquare, gray
22 | jmp next ; if even, draw gray
23 | DrawWhite:
24 | INVOKE DrawSquare, white
25 | next:
26 | inc dl
27 | loop DrawSquares
28 | ret
29 | DrawRow ENDP
30 | END
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/_drawsquare.asm:
--------------------------------------------------------------------------------
1 | ; DrawSquare Procedure (_drawsquare.asm)
2 | INCLUDE board.inc
3 |
4 | .CODE
5 | ;-----------------------------------------------------
6 | DrawSquare PROC USES eax,
7 | bgColour:BYTE ; square colour
8 | ;
9 | ; Draws a square.
10 | ; Returns: nothing.
11 | ;-----------------------------------------------------
12 | movzx eax,bgColour ; 8 denotes gray square, 15 denotes white square
13 | shl eax,4 ; multiply background colour by 16
14 | call SetTextColor
15 | mov al,' ' ; draw blank character
16 | call WriteChar
17 | ret
18 | DrawSquare ENDP
19 | END
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/_findlargest.asm:
--------------------------------------------------------------------------------
1 | ; FindLargest Procedure (_findlargest.asm)
2 | INCLUDE largest.inc
3 |
4 | .CODE
5 | ;-----------------------------------------------------
6 | FindLargest PROC,
7 | ptrSDWORDArray:PTR SDWORD, ; points to the array
8 | arraySize:DWORD ; size of the array
9 | ;
10 | ; Finds the largest elements in the array.
11 | ; Returns: EAX = the value of the largest array member.
12 | ;-----------------------------------------------------
13 | push ecx ; preserve all registers (except EAX)
14 | push esi
15 |
16 | mov esi,ptrSDWORDArray ; point to the first element
17 | mov eax,[esi] ; set max to first element
18 | add esi,TYPE DWORD ; point to 2nd element
19 | mov ecx,arraySize ; loop counter
20 | dec ecx
21 |
22 | ScanArray:
23 | mov ebx,DWORD PTR [esi]
24 | cmp ebx,eax
25 | jle NotGreater
26 | mov eax,ebx
27 | NotGreater:
28 | add esi,TYPE DWORD
29 | loop ScanArray
30 |
31 | pop esi
32 | pop ecx ; return sum in EAX
33 | ret
34 | FindLargest ENDP
35 | END
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/_findthrees.asm:
--------------------------------------------------------------------------------
1 | ; FindThrees Procedure (_findthrees.asm)
2 | INCLUDE threes.inc
3 |
4 | .CODE
5 | ;-----------------------------------------------------
6 | FindThrees PROC,
7 | arrayPtr:PTR DWORD,
8 | arraySize:DWORD
9 | LOCAL counter:DWORD
10 | ;
11 | ; Returns 1 if an array has three consecutive values of 3 somewhere in the
12 | ; array. Otherwise, return 0.
13 | ; Returns: EAX = result.
14 | mov esi,arrayPtr
15 | mov ecx,arraySize
16 | mov counter,0
17 | TraverseArray:
18 | mov eax,[esi]
19 | cmp eax,3
20 | jne Not3
21 | inc counter
22 | jmp Is3
23 | Not3:
24 | mov counter,0
25 | Is3:
26 | cmp counter,3
27 | jne Increment
28 | mov eax,1
29 | jmp done
30 | Increment:
31 | add esi,TYPE DWORD
32 | loop TraverseArray
33 | mov eax,0
34 | done:
35 | ret
36 | FindThrees ENDP
37 | END
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/board.inc:
--------------------------------------------------------------------------------
1 | ; Include file for the ChessBoard Program (board.inc)
2 | INCLUDE Irvine32.inc
3 |
4 | DrawRow PROTO,
5 | rowNum:BYTE ; row number
6 |
7 | DrawSquare PROTO,
8 | bgColour:BYTE ; square colour
9 |
10 | DrawBoard PROTO
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/inputs.inc:
--------------------------------------------------------------------------------
1 | ; Include file for the DifferentInputs Program (inputs.inc)
2 | INCLUDE Irvine32.inc
3 |
4 | DifferentInputs PROTO,
5 | input1:DWORD,
6 | input2:DWORD,
7 | input3:DWORD
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/largest.inc:
--------------------------------------------------------------------------------
1 | ; Include file for the FindLargest Program (largest.inc)
2 |
3 | INCLUDE Irvine32.inc
4 |
5 | FindLargest PROTO,
6 | ptrSDWORDArray:PTR SDWORD, ; points to the array
7 | arraySize:DWORD ; size of the array
8 |
9 | DisplayLargest PROTO,
10 | ptrPrompt:PTR BYTE, ; prompt string
11 | result:DWORD ; the largest element in the array
--------------------------------------------------------------------------------
/Intel-Assembly-Language-Programming-Exercises/threes.inc:
--------------------------------------------------------------------------------
1 | ; Include file for the FindThrees Program (threes.inc)
2 | INCLUDE Irvine32.inc
3 |
4 | FindThrees PROTO,
5 | arrayPtr:PTR DWORD,
6 | arraySize:DWORD
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Intel-Assembly-Language-Programming-Exercises
2 |
3 | This project contains solutions to programming exercises from [Assembly Language for x86 Processors (7th Edition) by Kip Irvine](https://www.amazon.com/Assembly-Language-x86-Processors-7th/dp/0133769402). Each solution has been documented to the best of my ability, but please let me know if you find any issues or have any feedback.
4 |
5 | ## Getting Started
6 |
7 | ### Prerequisites
8 |
9 | [Click here](http://kipirvine.com/asm/gettingstartedvs2015/Irvine.zip) to download the Irvine32 library used in the programs. Unzip the downloaded file into a directory named Irvine on Drive C.
10 | When installing Visual Studio, be sure to select Visual C++ under the *Programming Languages* category. If you forget to do this, you can always rerun the install file and modify the existing installation.
11 |
12 | ### Installing
13 |
14 | Step 1: Start Visual Studio and select **File** > **Open** > **Open from Source Control**.
15 |
16 | Step 2: When the Team Explorer opens select **Clone** under **Local Git Repositories**. Enter the following URL:
17 |
18 | ```
19 | https://github.com/avivbrook/Intel-Assembly-Language-Programming-Exercises.git
20 | ```
21 |
22 | Step 3: Click **Clone** and then double click **Intel-Assembly-Language-Programming-Exercises.sln** in the Solution Explorer.
23 |
24 | Step 4: Select all the asm files using shift-click. Right-click and select **Properties**. Go to **Configuration Properties** > **General** and set **Excluded from Build** to **Yes**. To run one of the programs, simply right-click the specific file you want to run and change **Excluded from Build** to **No**.
25 |
26 | Step 5: Right-click the project (**Intel-Assembly-Language-Programming-Exercises**) in the Solution Explorer and select **Properties**. Go to **Microsoft Macro Assembler** > **General** and set **Include Paths** to **C:\Irvine**.
27 |
28 | Step 6: In the same window, go to **Microsoft Macro Assembler** > **Listing File** and set **Assembled Code Listing File** to **$(ProjectName).lst**.
29 |
30 | Step 7: Go to **Linker** > **General** and set **Additional Library Directories** to **C:\Irvine**.
31 |
32 | Step 8: Go to **Linker** > **Input** and add **irvine32.lib;** to the beginning of **Additional Dependencies** so that the final value will be **irvine32.lib;kernel32.lib;...etc...**.
33 |
34 | Step 9: Go to **Linker** > **Debugging** and set **Generate Debug Info** to **Yes (/DEBUG)**.
35 |
36 | Step 10: Go to **Linker** > **System** and set **SubSystem** to **Console (/SUBSYSTEM:CONSOLE)**.
37 |
38 | Step 11: Go to **Linker** > **Advanced** and set **Randomized Base Address** to **No (/DYNAMICBASE:NO)** and **Image Has Safe Exception Handlers** to **No (/SAFESEH:NO)**.
39 |
40 | Step 12: Click **Apply** and **OK** to close the window.
41 |
42 | Try pressing F10 or F11 to enter debugging mode. If everything's working fine, congratulations -- the project works!
43 |
44 | ## Author
45 |
46 | * **Aviv Brook** - *Based on exercises from Kip Irvine's book.* - [avivbrook](https://github.com/avivbrook)
--------------------------------------------------------------------------------