Added VERY old code. Very cringy to look at, but hey, we all had to start somewhere...

This commit is contained in:
2018-01-08 23:37:31 -08:00
parent 7b18f6a807
commit df19ed7631
141 changed files with 26107 additions and 0 deletions

View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASM_Project", "Assignment1.vcxproj", "{4164AA65-1EF9-4E69-899B-D1BED776070B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.ActiveCfg = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.Build.0 = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.ActiveCfg = Release|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<MASM Include="main.asm" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4164AA65-1EF9-4E69-899B-D1BED776070B}</ProjectGuid>
<ProjectName>ASM_Project</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
<Link>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

View File

@@ -0,0 +1,59 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TITLE Assignment 1 (main.asm)
;Author: Corwin Perren
;Date: 1/19/2014
;Description:
; This program will request two numbers from the user, perform common
; mathematical calculations on them, and print the results
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE Irvine32.inc
.data
ProgramTitle BYTE "CS 271 - Assignment 1",0dh,0ah,0
CreatorName BYTE "Creator: Corwin Peren",0dh,0ah,0
Prompt1 BYTE "Please enter the first number: ",0
Prompt2 BYTE "Please enter the second number: ",0
SumMessage BYTE "Sum: ",0
DifMessage BYTE "Difference: ",0
ProdMessage BYTE "Product: ",0
QuotMessage BYTE "Quotient: ",0
RemainMessage BYTE "Remainder: ",0
TermMessage BYTE "Computations Complete...",0dh,0ah,0
FirstNumber DWORD ?
SecondNumber DWORD ?
FinalSum DWORD ?
FinalDif DWORD ?
FinalProd DWORD ?
FinalQuot DWORD ?
FinalRemain DWORD ?
.code
NineToFive PROC uses EAX
mov eax, 9
call WriteInt
mov eax, 8
call WriteInt
mov eax, 7
call WriteInt
mov eax, 6
call WriteInt
mov eax, 5
call WriteInt
ret
NineToFive ENDP
main PROC
call NineToFive
exit
main ENDP
END main

View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASM_Project", "Assignement 2.vcxproj", "{4164AA65-1EF9-4E69-899B-D1BED776070B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.ActiveCfg = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.Build.0 = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.ActiveCfg = Release|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<MASM Include="main.asm" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4164AA65-1EF9-4E69-899B-D1BED776070B}</ProjectGuid>
<ProjectName>ASM_Project</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
<Link>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>

View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASM_Project", "Project 2.vcxproj", "{4164AA65-1EF9-4E69-899B-D1BED776070B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.ActiveCfg = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.Build.0 = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.ActiveCfg = Release|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,268 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TITLE Assignment 2 (main.asm)
;Author: Corwin Perren
;Date: 1/28/2014
;Description:
; This program will calculate and display the nth iteration of the fibonacci
; sequence for n values between 1 and 46
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE Irvine32.inc
.data
ProgramTitle BYTE "CS 271 - Assignment 2",0
ProgrammersName BYTE "Programmed By: Corwin Perren",0
NamePrompt BYTE "By what name may I call you?",0
NamePrompt2 BYTE "Your name: ", 0
NameResponse BYTE "Welcome, ", 0
NameResponse2 BYTE ".", 0
FibPrompt BYTE "How many values of the fibonacci sequence would you like to calculate?", 0
FibPrompt2 BYTE "Enter a value from 1 to 46: ", 0
FibPromptIncorrect BYTE "Value was not between 1 and 46. Please try again.", 0
TabString BYTE 9, 0
ExtraTab DWORD 1346269
TryAgainMessage BYTE "Would you like to run the program again?", 0
TryAgainMessage2 BYTE "Answer (y/n): ", 0
IncorrectTryMessage BYTE "Please enter y or n....", 0
TermMessage BYTE "Goodbye, ", 0
TermMessage2 BYTE ".", 0
FibMax DWORD 46
FibMin DWORD 1
UserName BYTE 25 dup(0)
KeyAnswer BYTE 2 dup(0)
NumFib DWORD ?
FibVal DWORD 1
FibVal2 DWORD 1
CurCol DWORD 0
ColMax DWORD 5
Yep BYTE "y", 0
Nope BYTE "n", 0
.code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Simple procedure for printing a tab to the screen
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
InsertTab PROC
mov edx,OFFSET TabString ;Moves the tab character into the buffer
call WriteString ;Writes the tab to the screen
ret ;Returns out of the procedure
InsertTab ENDP
main PROC
call Clrscr ;Clears the screen
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Write title and programmers name to screen
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov edx,OFFSET ProgramTitle ;Gets title ready to print
call WriteString ;Prints title
call Crlf ;Prints a new line
mov edx,OFFSET ProgrammersName ;Gets programmers name ready to print
call WriteString ;Prints programmers name
call Crlf ;Prints newline
call Crlf ;Prints newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Prompt user for their name
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov edx,OFFSET NamePrompt ;Gets username prompt ready
call WriteString ;Prints username prompt
call Crlf ;Prints newline
mov edx,OFFSET NamePrompt2 ;Gets second half of username prompt ready
call WriteString ;Prints username prompt part 2
mov edx,OFFSET UserName ;Moves offset for username storage var into edx
mov ecx,SIZEOF UserName ;Sets max number of characters to read in
call ReadString ;Reads in username string from user
call Crlf ;Prints newline
call Crlf ;Prints newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Write user welcome message, with their name
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DoAgain:
call Clrscr ;Clears the screen to clean up output
mov edx,OFFSET NameResponse ;Gets the welcome message part 1 ready to print
call WriteString ;Prints welcome message part 1
mov edx,OFFSET UserName ;Gets username ready to print
call WriteString ;Prints username
mov edx,OFFSET NameResponse2 ;Gets welcome message part 2 redy to print
call WriteString ;Prints welcome message part 2
call Crlf ;Prints a new line
call Crlf ;Prints a new line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Prompt user for number of fibonacci to calculate
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov edx,OFFSET FibPrompt ;Gets prompt for fibonacci number ready
call WriteString ;Prints fib prompt
call Crlf ;Prints a new line
jmp EnterNumber ;Jumps to enter number label to begin input
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This prompt shows when the number enterred is not within 1 to 46
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IncorrectInput:
call Crlf ;Prints a new line
mov edx,OFFSET FibPromptIncorrect ;Gets incorrect range prompt ready to print
call WriteString ;Prints incorrect range prompt
call Crlf ;Prints a new line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Main prompt and read-in of fibonacci value from user
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EnterNumber:
mov edx,OFFSET FibPrompt2 ;Get main number entry prompt ready to print
call WriteString ;Prints main input prompt
call ReadInt ;Reads in int from user
cmp eax, FibMin ;Checks if input is less than 1
jl IncorrectInput ;Jumps to incorrect input if true
cmp eax, FibMax ;Checks if input is greater than 46
jg IncorrectInput ;Jumps to incorrect input if true
mov NumFib, eax ;Copies number to variable if in correct range
call Crlf ;Prints a new line
mov FibVal, 1 ;Reset fib start vals
mov FibVal2, 1 ;Reset fib start vals
mov CurCol, 0 ;Reset current column position
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This section prints the first fibonacci sequence value
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov eax, FibVal ;Gets first value of fibonacci sequence ready to print (1)
call WriteInt ;Writes value to screen
cmp NumFib, 1 ;Checks if only this one value should be displayed
je FibDone ;If true, jump to end of program
inc CurCol ;Increment column index
call InsertTab ;Prints tab for column alignment
call InsertTab ;Prints tab for column alignment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This section prints the second fibonacci sequence value
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Call WriteInt ;Prints the second value of the fibonacci sequence (also 1)
cmp NumFib, 2 ;Checks if only these two should be displayed
je FibDone ;If true, jump to end of program
inc CurCol ;Otherwise, increment column index
call InsertTab ;Prints tab for column alignment
call InsertTab ;Prints tab for column alignment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Setup of registers for the impending loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ecx, NumFib ;Sets loop ecx value
sub ecx, 2 ;Subtracts two because of the first two have already been printed
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Main fibonacci calculation and print loop
;PSEUDO
;newval = FibVal2 + Fibval
;print newval
;FibVal = FibVal2
;FibVal2 = newval;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CalcFib:
mov eax, FibVal2 ;Moves most recent fibonacci value into one reg
add eax, FibVal ;Adds second to last to most recent
call WriteInt ;Prints this fibonacci value to screen
push FibVal2 ;Moves old most recent to temp spot for move
pop FibVal ;Replaces second to last old val
mov FibVal2, eax ;Moves new most recent val to FibVal2
call InsertTab ;Prints tab for column alignment
cmp eax, ExtraTab ;Check if output val requires extra tab on output
jl OneExtra ;Jump to extra tab output label if necessary
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Return jump point for extra tab printing to make output alignment nice
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MidCalcFib:
inc CurCol ;Increment column index
mov edx, CurCol ;Place index in reg for compare
cmp edx, ColMax ;Compare current col index with max
jne CalcFibLoop ;Jump to rest of loop if newline not needed
call Crlf ;Prints newline when needed
mov CurCol, 0 ;Resets current column index
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Jump location used for avoiding printing a newline from above
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CalcFibLoop:
loop CalcFib ;Loops fib calc sequence until ecx counter 0
jmp TryAgain ;Jumps to program end if loop done
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Jump location used for printing on screen tabs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
OneExtra:
call InsertTab ;Calls procedure to input tab when necessary
jmp MidCalcFib ;Jumps back to where it was called
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This section deals with jumping if the user wants to calculate more values
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IncorrectTry:
call Crlf ;Prints a new line
mov edx,OFFSET IncorrectTryMessage ;Gets ready to print the incorrect try message
call Writestring ;Prints the incorrect try message
TryAgain:
call Crlf ;Prints a new line
call Crlf ;Prints a new line
mov edx,OFFSET TryAgainMessage ;Gets ready to print the try again message
call WriteString ;Prints the try again message
call Crlf ;Prints a new line
mov edx,OFFSET TryAgainMessage2 ;Gets ready to print the try again message part 2
call WriteString ;Prints the try again message 2
mov edx,OFFSET KeyAnswer ;Assigns edx to offset of keyanswer for keyboard input
mov ecx,SIZEOF KeyAnswer ;Sets number of characters to read in
call ReadString ;Reads in keyboard input
INVOKE Str_compare,OFFSET KeyAnswer,OFFSET Yep ;Uses a multi-input irvine procedure to do a string comparison
je DoAgain ;Jump to DoAgain if the user answered 'y'
INVOKE Str_compare,OFFSET KeyAnswer,OFFSET Nope ;Uses a multi-input irvine procedure to do a string comparison
je FibDone ;Jumps to end if user answered 'n'
jmp IncorrectTry ;Jumps to an incorrect input section if user enterred wrong values
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Section to show the termination message
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FibDone:
call Crlf ;Prints a new line
call Crlf ;Prints a new line
mov edx,OFFSET TermMessage ;Gets termination message part 1 ready to print
call WriteString ;Prints termination message
mov edx,OFFSET UserName ;Gets username ready to print
call WriteString ;Prints username
mov edx,OFFSET TermMessage2 ;Gets termination message part 2 ready to print
call WriteString ;Prints termination messag part 2
call Crlf ;Prints a new line
exit ;Ends main program
main ENDP
END main

View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASM_Project", "Assignment3.vcxproj", "{4164AA65-1EF9-4E69-899B-D1BED776070B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.ActiveCfg = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.Build.0 = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.ActiveCfg = Release|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<MASM Include="main.asm" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4164AA65-1EF9-4E69-899B-D1BED776070B}</ProjectGuid>
<ProjectName>ASM_Project</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
<Link>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

View File

@@ -0,0 +1,441 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TITLE Assignment 5 (main.asm)
;Author: Corwin Perren
;Date: 3/3/2014
;Description:
; This program runs all three programs from assignment 5 from a menu screen
; These programs include an array reverser, frequency table generator, and
; prime number generator
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE Irvine32.inc
.data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Variables to change for testing program capabilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SieveArray BYTE 1000000 dup(?)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Globally relevant vars
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ProgramTitle BYTE "CS 271 - Assignment 5",0
ProgrammerName BYTE "Written by: Corwin Perren",0
SelectInstructions BYTE "Please enter 1-4 to run desired program.", 0
MenuItem1 BYTE "1: Reverse Array In Place (Chapter 4, Exercise 5)",0
MenuItem2 BYTE "2: Frequency Table (Chapter 9, Exercise 6)",0
MenuItem3 BYTE "3: Sieve of Eratosthenes (Chapter 9, Exercise 7)",0
MenuItem4 BYTE "4: Exit",0
Selection BYTE "Selection: ",0
IncorrectNumberEntry BYTE "You did not enter 1-4. Press enter to try again.", 0
ReturnToSelect BYTE "Program Complete. Press enter to return to selection screen.", 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Vars for Prog 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ArrayToReverse BYTE 1,2,3,4,5,6,7,8,9,10, 11, 12, 13, 14
PressEnter BYTE "Press enter to reverse the currently reversed array. Enter 1 to quit.", 0
OriginalArray BYTE "Original Array:", 0
ReversedArray BYTE "Reversed Array:", 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Vars for Prog 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
StringEntry BYTE "Please enter a string to create a frequency table for.", 0
StringThing BYTE "Your string: ", 0
StringArray BYTE 256 dup(?)
FrequencyTable DWORD 256 dup(?)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Vars for Prog 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EnterPrimes1 BYTE "Press enter to calculate primes up to ", 0
EnterPrimes2 BYTE ".", 0
.code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for writing string with newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Write_String_NL PROC uses EDX,
StringPtr:Ptr BYTE ;Varible to store string offset pointer
mov edx, StringPtr ;Moves the string to the proper register
call WriteString ;Prints the string
call Crlf ;Prints a new line
ret ;Return from procedure
Write_String_NL ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for writing string without newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Write_String PROC uses EDX,
StringPtr:Ptr BYTE ;Variable to store string offset pointer
mov edx, StringPtr ;Moves the string to the proper registers
call WriteString ;Prints the string
ret
Write_String ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for printing program title and programmer name
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintTitle PROC
INVOKE Write_String_NL, OFFSET ProgramTitle ;Prints the program title
INVOKE Write_String_NL, OFFSET ProgrammerName ;prints the programmer's name
call Crlf ;Prints a new line
INVOKE Write_String_NL, OFFSET SelectInstructions ;Prints the selection screen instructions
call Crlf ;Prints a new line
INVOKE Write_String_NL, OFFSET MenuItem1 ;Prints menu item 1
INVOKE Write_String_NL, OFFSET MenuItem2 ;Prints menu item 2
INVOKE Write_String_NL, OFFSET MenuItem3 ;Prints menu item 3
INVOKE Write_String_NL, OFFSET MenuItem4 ;Prints menu item 4
INVOKE Write_String, OFFSET Selection ;Print selction prompt
ret
PrintTitle ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to fill array with zeros using stosb
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FillWithZeros PROC
mov al, 0 ;Set al with value we want to fill array with
cld ;Clear Direction Flag
mov edi, OFFSET SieveArray ;Point edi to array
mov ecx, LENGTHOF SieveArray ;Set counter so instruction knows when to end
dec ecx ;Subtract one because it's starting at zero instead of one
rep stosb ;Repeats the fill operation until the array is full
ret ;Returns from function
FillWithZeros ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to mark multiples of primes with ones
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MarkMultiples PROC
mov esi, OFFSET SieveArray ;Move into esi to get easy access
mov BYTE PTR [esi], 1 ;Mark zero as non-prime
mov BYTE PTR [esi+1], 1 ;Mark one as non-prime
mov eax, 2 ;Set cursor position
mov ebx, 2 ;Multiplication value
jmp Inner
Outer:
pop eax ;Pop eax if we got here so the stack gets aligned and we know where we are
LookForOne:
inc eax ;Go up by one
cmp BYTE PTR [esi+eax], 1 ;Check to see if the new value at that position of the array has been marked
je LookForOne ;If so, increment again to find an unmarked one
cmp eax, LENGTHOF SieveArray ;Once an unmarked is found, make sure it's not outside our array size
jg MultEnd ;If it's out of array bounds, we're done so exit
mov ebx, 2 ;Otherwise, get ready to mark multiples of current prime starting with two times the prime
Inner:
push eax ;Save our original prime we're using
mul ebx ;Multiply prime by scaler
cmp eax, LENGTHOF SieveArray ;Make sure new value is not out of array size
jg Outer ;If it is, we're done with this prime
mov BYTE PTR [esi+eax], 1 ;Otherwise, mark the multiple with a one
inc ebx ;Increase our scaler
pop eax ;Restore the prime we're on
jmp Inner ;Re-do for next scaler
MultEnd:
ret ;Return from procedure
MarkMultiples ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to print out unmarked values in array, which are primes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintPrimes PROC
mov esi, OFFSET SieveArray ;Load array into esi to get ready to print
mov eax, 0 ;Set our cursor to zero
LookForZeros:
inc eax ;Move cursor forward one
cmp eax, LENGTHOF SieveArray ;Check if cursor is out of array bounds
jg PrintExit ;If so, exit because we are done
cmp BYTE PTR [esi+eax], 1 ;If we're in bounds, check if the position is marked
je LookForZeros ;If so, don't print and look at the next position
call WriteDec ;If unmarked, print the prime number sotred here
call Crlf ;Print a new line to make things look nice
jmp LookForZeros ;Continue for the next array position
PrintExit:
ret ;Return from procedure
PrintPrimes ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to run program 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program3 PROC
call ClrScr ;Clears the screen
INVOKE Write_String, OFFSET EnterPrimes1 ;Prints prompt part one
mov eax, LENGTHOF SieveArray ;Moves number of primes to calculate to print
call WriteDec ;Prints number of primes to calculate
INVOKE Write_String_NL, OFFSET EnterPrimes2 ;Prints end of prompt line
call ReadInt ;Waits for any key
call FillWithZeros ;Fills the sieve array with zeros using stosb method
call MarkMultiples ;Marks positions that are multiples of primes
call PrintPrimes ;Prints remaining prime numbers
ret ;Returns from procedure
Program3 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to determine the character frequency of a string
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Get_Frequencies PROC InputString:PTR BYTE, OutputTable:PTR DWORD
mov esi, InputString ;Moves string to parse into esi
mov edi, OutputTable ;Moves output table into edi
FreqLoop:
mov eax, 0 ;Zeros eax to make things work right
mov al, BYTE PTR [esi] ;Moves ascii decimal value into eax
mov ecx, eax ;Saves current decimal value
mov ebx, 4 ;Multiply eax by four because it's stored in DWORD and not BYTE array
mul ebx ;Actual multiplication
add DWORD PTR [edi+eax], 1 ;Increments frequency table position by one for this character
cmp ecx, 0 ;Checks if we've hit the NUL character
je FreqDone ;Exit if it's found because we're done
inc esi ;Otherwise, move to the next string array position
jmp FreqLoop ;Do above again for next character
FreqDone:
ret ;Return from procedure
Get_Frequencies ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to read in string from user
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GetNewString PROC StringPtr:PTR BYTE
mov edx, StringPtr ;Move string array into edx for read in
mov ecx, 256 ;Read in a max of 256 characters
call ReadString ;Read in string from user
ret ;Exit from procedure
GetNewString ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to print out the frequency table
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintFreqTable PROC TablePtr:PTR DWORD
mov esi, TablePtr ;Move frequency table into esi
mov ecx, 256 ;Set number of elements
mov ebx, 4 ;Set size of storage elements
call DumpMem ;Dump memory for the array
ret
PrintFreqTable ENDP
ZeroProg2 PROC
mov eax, 0 ;Set al with value we want to fill array with
cld ;Clear Direction Flag
mov edi, OFFSET StringArray ;Point edi to array
mov ecx, 256 ;Set counter so instruction knows when to end
dec ecx ;Subtract one because it's starting at zero instead of one
rep stosb ;Repeats the fill operation until the array is full
mov eax, 0 ;Set al with value we want to fill array with
cld ;Clear Direction Flag
mov edi, OFFSET FrequencyTable ;Point edi to array
mov ecx, 1024 ;Set counter so instruction knows when to end
dec ecx ;Subtract one because it's starting at zero instead of one
rep stosb ;Repeats the fill operation until the array is full
ret ;Returns from function
ZeroProg2 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to run program 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program2 PROC
call ClrScr ;Clear the screen
call ZeroProg2 ;Zeros string and freq table array
INVOKE Write_String_NL, OFFSET StringEntry ;Prompts the user to enter a string
INVOKE Write_String, OFFSET StringThing ;Line prompt for above
INVOKE GetNewString, OFFSET StringArray ;Reads in user string
INVOKE Get_Frequencies, OFFSET StringArray, OFFSET FrequencyTable ;Runs frequency procedure on input string
INVOKE PrintFreqTable, OFFSET FrequencyTable ;Prints out the new frequency table
ret ;Returns from procedure
Program2 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to run program 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program1 PROC
call ClrScr ;Clears the screen
INVOKE Write_String_NL, OFFSET OriginalArray ;Prints header for original array
mov eax, TYPE ArrayToReverse ;Moves the array type into eax
cmp eax, 1 ;Checks if it's a BYTE array
je ITSBYTE ;Jumps to BYTE section if so
cmp eax, 2 ;Checks if WORD array
je ITSWORD ;Jumps to WORD section if so
cmp eax, 4 ;Check if DWORD array
je ITSDWORD ;Jumps to DWORD section if so
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Run for BYTE Array
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ITSBYTE:
mov esi, OFFSET ArrayToReverse ;Moves array into esi
mov ecx, LENGTHOF ArrayToReverse ;Moves number of elements in array into ecx
mov ebx, TYPE ArrayToReverse ;Moves type of array into ebx
call DumpMem ;Shows original array
mov esi, OFFSET ArrayToReverse ;Re-moves array into esi
mov edi, OFFSET ArrayToReverse + SIZEOF ArrayToReverse - TYPE ArrayToReverse ;Moves the pointer to the last value of the array into edi
mov eax, LENGTHOF ArrayToReverse ;Moves number of elements in array into eax
mov edx, 0 ;Sets remainder to zero by default
mov ebx, 2 ;Moves two into ebx
div ebx ;Divides number of elements by two
mov ecx, eax ;Puts that number into our loop counter
ReverseBYTE:
mov bl, [esi] ;Move data at beginning cursor to tmp storage
mov dl, [edi] ;Move data at end cursor to tmp storage
mov [esi], dl ;Move end data to beginning
mov [edi], bl ;Move beginning data to end
add esi, TYPE ArrayToReverse ;Move beginning cursor forward
sub edi, TYPE ArrayToReverse ;Move ending cursor back
loop ReverseBYTE ;Loop until count expired
jmp Prog1Ret ;Jump to procedure end when done
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Run for WORD Array
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ITSWORD:
mov esi, OFFSET ArrayToReverse ;Moves array into esi
mov ecx, LENGTHOF ArrayToReverse ;Moves number of elements in array into ecx
mov ebx, TYPE ArrayToReverse ;Moves type of array into ebx
call DumpMem ;Shows original array
mov esi, OFFSET ArrayToReverse ;Re-moves array into esi
mov edi, OFFSET ArrayToReverse + SIZEOF ArrayToReverse - TYPE ArrayToReverse ;Moves the pointer to the last value of the array into edi
mov eax, LENGTHOF ArrayToReverse ;Moves number of elements in array into eax
mov edx, 0 ;Sets remainder to zero by default
mov ebx, 2 ;Moves two into ebx
div ebx ;Divides number of elements by two
mov ecx, eax ;Puts that number into our loop counter
ReverseWORD:
mov bx, [esi] ;Move data at beginning cursor to tmp storage
mov dx, [edi] ;Move data at end cursor to tmp storage
mov [esi], dx ;Move end data to beginning
mov [edi], bx ;Move beginning data to end
add esi, TYPE ArrayToReverse ;Move beginning cursor forward
sub edi, TYPE ArrayToReverse ;Move ending cursor back
loop ReverseWORD ;Loop until count expired
jmp Prog1Ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Run for DWORD Array
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ITSDWORD:
mov esi, OFFSET ArrayToReverse ;Moves array into esi
mov ecx, LENGTHOF ArrayToReverse ;Moves number of elements in array into ecx
mov ebx, TYPE ArrayToReverse ;Moves type of array into ebx
call DumpMem ;Shows original array
mov esi, OFFSET ArrayToReverse ;Re-moves array into esi
mov edi, OFFSET ArrayToReverse + SIZEOF ArrayToReverse - TYPE ArrayToReverse ;Moves the pointer to the last value of the array into edi
mov eax, LENGTHOF ArrayToReverse ;Moves number of elements in array into eax
mov edx, 0 ;Sets remainder to zero by default
mov ebx, 2 ;Moves two into ebx
div ebx ;Divides number of elements by two
mov ecx, eax ;Puts that number into our loop counter
ReverseDWORD:
mov ebx, [esi] ;Move data at beginning cursor to tmp storage
mov edx, [edi] ;Move data at end cursor to tmp storage
mov [esi], edx ;Move end data to beginning
mov [edi], ebx ;Move beginning data to end
add esi, TYPE ArrayToReverse ;Move beginning cursor forward
sub edi, TYPE ArrayToReverse ;Move ending cursor back
loop ReverseWORD ;Loop until count expired
Prog1Ret:
call Crlf ;Print a new line
call Crlf ;Print a second new line
INVOKE Write_String_NL, OFFSET ReversedArray ;Print header to say this is the reversed array
mov esi, OFFSET ArrayToReverse ;Move array into esi
mov ecx, LENGTHOF ArrayToReverse ;Set number of elements
mov ebx, TYPE ArrayToReverse ;Set size of elements
call DumpMem ;Display array
ret ;Return from procedure
Program1 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Main Procedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main PROC
MainTitle:
call ClrScr ;Clear screen
call PrintTitle ;Print the title screen
call ReadInt ;Read in user selection
cmp eax, 1 ;Check if user selected entry item 1
je Prog1Jmp ;If so, jump to that program
cmp eax, 2 ;Check if user selected entry item 2
je Prog2Jmp ;If so, jump to that program
cmp eax, 3 ;Check if user selected entry item 3
je Prog3Jmp ;If so, jump to that program
cmp eax, 4 ;Check if user selected exit
je MainExit ;If so, jump to end of program
call ClrScr ;Clear screeen
INVOKE Write_String_NL, OFFSET IncorrectNumberEntry ;Scold user for not entering one to four
call ReadInt ;Wait for enter key
jmp MainTitle ;Jump back to main screen
Prog1Jmp:
call Program1 ;Call array reverse program
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
Prog2Jmp:
call Program2 ;Call String frequency program
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
Prog3Jmp:
call Program3 ;Call prime generator program
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
MainExit:
exit
main ENDP
END main

View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASM_Project", "Assignment3.vcxproj", "{4164AA65-1EF9-4E69-899B-D1BED776070B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.ActiveCfg = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.Build.0 = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.ActiveCfg = Release|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<MASM Include="Assignment4_perrenc.asm" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4164AA65-1EF9-4E69-899B-D1BED776070B}</ProjectGuid>
<ProjectName>ASM_Project</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
<Link>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

View File

@@ -0,0 +1,254 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TITLE Assignment 3 (main.asm)
;Author: Corwin Perren
;Date: 2/05/2014
;Description:
; This program greets a user by name, takes in ten integers, sums
; non-negative ones, and computers the average of that sum before saying
; goodbye to the user
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE Irvine32.inc
.data
ProgramTitle BYTE "CS 271 - Assignment 3",0
ProgrammerName BYTE "Written by: Corwin Perren",0
NamePrompt BYTE "By what name may I call you?",0
NamePrompt2 BYTE "Your name: ", 0
NameResponse BYTE "Welcome, ", 0
NameResponse2 BYTE ".", 0
EnterNumPrompt BYTE "Please enter ten numbers between 0 and 100.", 0
TooGreat BYTE "The number you entered was too large, please try again.", 0
IncorrectInputMessage BYTE "You did not enter a valid number.", 0
ListingPrint BYTE "Number ", 0
ListingPrint2 BYTE ":", 0
NoPosMessage BYTE "No Positive Integers Entered...", 0
NumPosMessage BYTE "Number of Positive Integers: ", 0
SumMessage BYTE "Sum of Positive Integers: ", 0
AvgMessage BYTE "Average of Positive Integers: ", 0
TermMessage BYTE "Goodbye, ", 0
TermMessage2 BYTE ".", 0
TESTMessage BYTE "Equal to Zero", 0
NumEntries DWORD 10
MaxEntryVal DWORD 100
StorArray DWORD 10 dup(0)
UserName BYTE 25 dup(0)
NumPos DWORD 0
FinalSum DWORD 0
FinalAvg DWORD 0
.code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for writing string with newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Write_String_NL PROC uses EDX,
StringPtr:Ptr BYTE ;Varible to store string offset pointer
mov edx, StringPtr ;Moves the string to the proper register
call WriteString ;Prints the string
call Crlf ;Prints a new line
ret
Write_String_NL ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for writing string without newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Write_String PROC uses EDX,
StringPtr:Ptr BYTE ;Variable to store string offset pointer
mov edx, StringPtr ;Moves the string to the proper registers
call WriteString ;Prints the string
ret
Write_String ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for printing program title and programmer name
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintTitle PROC
INVOKE Write_String_NL, OFFSET ProgramTitle ;Prints the program title
INVOKE Write_String_NL, OFFSET ProgrammerName ;prints the programmer's name'
call Crlf ;Prints a new line
ret
PrintTitle ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for getting user's name and greeting them
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MeetAndGreet PROC
INVOKE Write_String_NL, OFFSET NamePrompt ;Gets username prompt ready
INVOKE Write_String, OFFSET NamePrompt2 ;Gets second half of username prompt ready
mov edx,OFFSET UserName ;Moves offset for username storage var into edx
mov ecx,SIZEOF UserName ;Sets max number of characters to read in
call ReadString ;Reads in username string from user
call Clrscr ;Clears the screen to clean up output
INVOKE Write_String, OFFSET NameResponse ;Prints the first part of the welcome message
INVOKE Write_String, OFFSET UserName ;Prints the user's name
INVOKE Write_String_NL, OFFSET NameResponse2 ;Prints teh second half of the welcome message
call Crlf ;Prints a new line
ret
MeetAndGreet ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for printing what the user may enter
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintEnterNumPrompt PROC
INVOKE Write_String_NL, OFFSET EnterNumPrompt ;Gets welcome message part 2 redy to print
ret
PrintEnterNumPrompt ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for retreiving integer inputs from user
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GetNumbers PROC
mov ecx, NumEntries ;Sets loop count variable
mov esi, OFFSET StorArray ;Puts storage array into esi reg
jmp EnterNum ;Jump to beginning of number entry
IncorrectInput:
INVOKE Write_String_NL, OFFSET IncorrectInputMessage ;Displays incorrect input message
jmp EnterNum ;Jumps to beginning of number entry
GreaterThanMax:
INVOKE Write_String_NL, OFFSET TooGreat ;Displays number to great message
EnterNum:
INVOKE Write_String, OFFSET ListingPrint ;Prints number entry listing
mov eax, NumEntries ;Moves total entries to eax
inc eax ;Increments by one to start at 1 rather than 0
sub eax, ecx ;Subracts current loop var to determine count val
call WriteInt ;Writes for number entry listing
INVOKE Write_String, OFFSET ListingPrint2 ;Finishes priting number entry listing
call ReadInt ;Reads in int from user
jo IncorrectInput ;Re-do previous if incorrect input
cmp eax, MaxEntryVal ;Check if number too great
jg GreaterThanMax ;Jump if number too great
mov [esi], eax ;Move number if valid into array
add esi, 4 ;Increment array pointer
loop EnterNum ;Loop unti ecx equals 0
ret
GetNumbers ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for determining number of positive integers, summing them, and
;calculating their average
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CalcStuff PROC
mov ecx, NumEntries ;Puts loop counter in
mov esi, OFFSET StorArray ;Gets array ready to loop through
mov eax, 0 ;Makes sum register zero
ArrayLoop:
mov edx, [esi] ;Read out one array value
add esi, 4 ;Increment array pointer
cmp edx, 0 ;Check if negative
jl ArrayLoopEnd ;Jump to ignore if negative
add eax, edx ;If non-negative, add to sum reg
inc NumPos ;Increment number of positive found
ArrayLoopEnd:
loop ArrayLoop ;Loop until array empty
cmp NumPos, 0 ;Check if any positive found
jne MoreThanZero ;Jump if there are positive integers
Invoke Write_String_NL, OFFSET NoPosMessage ;Write no positive intergers message
jmp QuickEnd ;End program because no positive integers
MoreThanZero:
mov FinalSum, eax ;Move positive integers sum to variable
mov edx, 0 ;Zero upper of numerator
mov ebx, NumPos ;Put value in lower of numerator
div ebx ;Divide sum by number of positive integers
mov FinalAvg, eax ;Take result which is average and store in varible
call Crlf ;Print a new line
ret
CalcStuff ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Prints the number of positive integers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintNumPos PROC
Invoke Write_String, OFFSET NumPosMessage ;Print string for number of positive integers
mov eax, NumPos ;Move varaible into printing register
call WriteInt ;Print number of positive integers
call Crlf ;Print a new line
ret
PrintNumPos ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Prints the sum of the positive integers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintSumOf PROC
Invoke Write_String, OFFSET SumMessage ;Print the message for the sum
mov eax, FinalSum ;Move sum into printing register
call WriteInt ;Print sum
call Crlf ;Print new line
ret
PrintSumOf ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Prints the average of the positive integers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintAverageOf PROC
Invoke Write_String, OFFSET AvgMessage ;Print message for the average
mov eax, FinalAvg ;Move average into printing register
call WriteInt ;Print the average
call Crlf ;Print a new line
ret
PrintAverageOf ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for printing the termination message
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintTerm PROC
Invoke Write_String, OFFSET TermMessage ;Print the first part of the termination message
Invoke Write_String, OFFSET UserName ;Print the user's name
Invoke Write_String_NL, OFFSET TermMessage2 ;Print the second part of the termination message
ret
PrintTerm ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Main Procedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main PROC
call PrintTitle ;Prints title
call MeetAndGreet ;Greets user by name
call PrintEnterNumPrompt ;Print prompt for program use
call GetNumbers ;Retrieves user integer entries
call CalcStuff ;Performs math on numbers entered
call PrintNumPos ;Prints number of positive integers
call PrintSumOf ;Prints sum of positive integers
call PrintAverageOf ;Prints average of positive integers
QuickEnd::
call PrintTerm ;Prints termination message
exit
main ENDP
END main

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASM_Project", "Assignment5.vcxproj", "{4164AA65-1EF9-4E69-899B-D1BED776070B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.ActiveCfg = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.Build.0 = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.ActiveCfg = Release|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<MASM Include="CS271_proj5_perrenc.asm" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4164AA65-1EF9-4E69-899B-D1BED776070B}</ProjectGuid>
<ProjectName>ASM_Project</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
<Link>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>

View File

@@ -0,0 +1,441 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TITLE Assignment 5 (main.asm)
;Author: Corwin Perren
;Date: 3/3/2014
;Description:
; This program runs all three programs from assignment 5 from a menu screen
; These programs include an array reverser, frequency table generator, and
; prime number generator
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE Irvine32.inc
.data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Variables to change for testing program capabilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SieveArray BYTE 5000 dup(?)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Globally relevant vars
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ProgramTitle BYTE "CS 271 - Assignment 5",0
ProgrammerName BYTE "Written by: Corwin Perren",0
SelectInstructions BYTE "Please enter 1-4 to run desired program.", 0
MenuItem1 BYTE "1: Reverse Array In Place (Chapter 4, Exercise 5)",0
MenuItem2 BYTE "2: Frequency Table (Chapter 9, Exercise 6)",0
MenuItem3 BYTE "3: Sieve of Eratosthenes (Chapter 9, Exercise 7)",0
MenuItem4 BYTE "4: Exit",0
Selection BYTE "Selection: ",0
IncorrectNumberEntry BYTE "You did not enter 1-4. Press enter to try again.", 0
ReturnToSelect BYTE "Program Complete. Press enter to return to selection screen.", 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Vars for Prog 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ArrayToReverse BYTE 1,2,3,4,5,6,7,8,9,10, 11, 12, 13, 14
PressEnter BYTE "Press enter to reverse the currently reversed array. Enter 1 to quit.", 0
OriginalArray BYTE "Original Array:", 0
ReversedArray BYTE "Reversed Array:", 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Vars for Prog 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
StringEntry BYTE "Please enter a string to create a frequency table for.", 0
StringThing BYTE "Your string: ", 0
StringArray BYTE 256 dup(?)
FrequencyTable DWORD 256 dup(?)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Vars for Prog 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EnterPrimes1 BYTE "Press enter to calculate primes up to ", 0
EnterPrimes2 BYTE ".", 0
.code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for writing string with newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Write_String_NL PROC uses EDX,
StringPtr:Ptr BYTE ;Varible to store string offset pointer
mov edx, StringPtr ;Moves the string to the proper register
call WriteString ;Prints the string
call Crlf ;Prints a new line
ret ;Return from procedure
Write_String_NL ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for writing string without newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Write_String PROC uses EDX,
StringPtr:Ptr BYTE ;Variable to store string offset pointer
mov edx, StringPtr ;Moves the string to the proper registers
call WriteString ;Prints the string
ret
Write_String ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for printing program title and programmer name
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintTitle PROC
INVOKE Write_String_NL, OFFSET ProgramTitle ;Prints the program title
INVOKE Write_String_NL, OFFSET ProgrammerName ;prints the programmer's name
call Crlf ;Prints a new line
INVOKE Write_String_NL, OFFSET SelectInstructions ;Prints the selection screen instructions
call Crlf ;Prints a new line
INVOKE Write_String_NL, OFFSET MenuItem1 ;Prints menu item 1
INVOKE Write_String_NL, OFFSET MenuItem2 ;Prints menu item 2
INVOKE Write_String_NL, OFFSET MenuItem3 ;Prints menu item 3
INVOKE Write_String_NL, OFFSET MenuItem4 ;Prints menu item 4
INVOKE Write_String, OFFSET Selection ;Print selction prompt
ret
PrintTitle ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to fill array with zeros using stosb
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FillWithZeros PROC
mov al, 0 ;Set al with value we want to fill array with
cld ;Clear Direction Flag
mov edi, OFFSET SieveArray ;Point edi to array
mov ecx, LENGTHOF SieveArray ;Set counter so instruction knows when to end
dec ecx ;Subtract one because it's starting at zero instead of one
rep stosb ;Repeats the fill operation until the array is full
ret ;Returns from function
FillWithZeros ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to mark multiples of primes with ones
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MarkMultiples PROC
mov esi, OFFSET SieveArray ;Move into esi to get easy access
mov BYTE PTR [esi], 1 ;Mark zero as non-prime
mov BYTE PTR [esi+1], 1 ;Mark one as non-prime
mov eax, 2 ;Set cursor position
mov ebx, 2 ;Multiplication value
jmp Inner
Outer:
pop eax ;Pop eax if we got here so the stack gets aligned and we know where we are
LookForOne:
inc eax ;Go up by one
cmp BYTE PTR [esi+eax], 1 ;Check to see if the new value at that position of the array has been marked
je LookForOne ;If so, increment again to find an unmarked one
cmp eax, LENGTHOF SieveArray ;Once an unmarked is found, make sure it's not outside our array size
jg MultEnd ;If it's out of array bounds, we're done so exit
mov ebx, 2 ;Otherwise, get ready to mark multiples of current prime starting with two times the prime
Inner:
push eax ;Save our original prime we're using
mul ebx ;Multiply prime by scaler
cmp eax, LENGTHOF SieveArray ;Make sure new value is not out of array size
jg Outer ;If it is, we're done with this prime
mov BYTE PTR [esi+eax], 1 ;Otherwise, mark the multiple with a one
inc ebx ;Increase our scaler
pop eax ;Restore the prime we're on
jmp Inner ;Re-do for next scaler
MultEnd:
ret ;Return from procedure
MarkMultiples ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to print out unmarked values in array, which are primes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintPrimes PROC
mov esi, OFFSET SieveArray ;Load array into esi to get ready to print
mov eax, 0 ;Set our cursor to zero
LookForZeros:
inc eax ;Move cursor forward one
cmp eax, LENGTHOF SieveArray ;Check if cursor is out of array bounds
jg PrintExit ;If so, exit because we are done
cmp BYTE PTR [esi+eax], 1 ;If we're in bounds, check if the position is marked
je LookForZeros ;If so, don't print and look at the next position
call WriteDec ;If unmarked, print the prime number sotred here
call Crlf ;Print a new line to make things look nice
jmp LookForZeros ;Continue for the next array position
PrintExit:
ret ;Return from procedure
PrintPrimes ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to run program 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program3 PROC
call ClrScr ;Clears the screen
INVOKE Write_String, OFFSET EnterPrimes1 ;Prints prompt part one
mov eax, LENGTHOF SieveArray ;Moves number of primes to calculate to print
call WriteDec ;Prints number of primes to calculate
INVOKE Write_String_NL, OFFSET EnterPrimes2 ;Prints end of prompt line
call ReadInt ;Waits for any key
call FillWithZeros ;Fills the sieve array with zeros using stosb method
call MarkMultiples ;Marks positions that are multiples of primes
call PrintPrimes ;Prints remaining prime numbers
ret ;Returns from procedure
Program3 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to determine the character frequency of a string
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Get_Frequencies PROC InputString:PTR BYTE, OutputTable:PTR DWORD
mov esi, InputString ;Moves string to parse into esi
mov edi, OutputTable ;Moves output table into edi
FreqLoop:
mov eax, 0 ;Zeros eax to make things work right
mov al, BYTE PTR [esi] ;Moves ascii decimal value into eax
mov ecx, eax ;Saves current decimal value
mov ebx, 4 ;Multiply eax by four because it's stored in DWORD and not BYTE array
mul ebx ;Actual multiplication
add DWORD PTR [edi+eax], 1 ;Increments frequency table position by one for this character
cmp ecx, 0 ;Checks if we've hit the NUL character
je FreqDone ;Exit if it's found because we're done
inc esi ;Otherwise, move to the next string array position
jmp FreqLoop ;Do above again for next character
FreqDone:
ret ;Return from procedure
Get_Frequencies ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to read in string from user
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GetNewString PROC StringPtr:PTR BYTE
mov edx, StringPtr ;Move string array into edx for read in
mov ecx, 256 ;Read in a max of 256 characters
call ReadString ;Read in string from user
ret ;Exit from procedure
GetNewString ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to print out the frequency table
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintFreqTable PROC TablePtr:PTR DWORD
mov esi, TablePtr ;Move frequency table into esi
mov ecx, 256 ;Set number of elements
mov ebx, 4 ;Set size of storage elements
call DumpMem ;Dump memory for the array
ret
PrintFreqTable ENDP
ZeroProg2 PROC
mov eax, 0 ;Set al with value we want to fill array with
cld ;Clear Direction Flag
mov edi, OFFSET StringArray ;Point edi to array
mov ecx, 256 ;Set counter so instruction knows when to end
dec ecx ;Subtract one because it's starting at zero instead of one
rep stosb ;Repeats the fill operation until the array is full
mov eax, 0 ;Set al with value we want to fill array with
cld ;Clear Direction Flag
mov edi, OFFSET FrequencyTable ;Point edi to array
mov ecx, 1024 ;Set counter so instruction knows when to end
dec ecx ;Subtract one because it's starting at zero instead of one
rep stosb ;Repeats the fill operation until the array is full
ret ;Returns from function
ZeroProg2 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to run program 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program2 PROC
call ClrScr ;Clear the screen
call ZeroProg2 ;Zeros string and freq table array
INVOKE Write_String_NL, OFFSET StringEntry ;Prompts the user to enter a string
INVOKE Write_String, OFFSET StringThing ;Line prompt for above
INVOKE GetNewString, OFFSET StringArray ;Reads in user string
INVOKE Get_Frequencies, OFFSET StringArray, OFFSET FrequencyTable ;Runs frequency procedure on input string
INVOKE PrintFreqTable, OFFSET FrequencyTable ;Prints out the new frequency table
ret ;Returns from procedure
Program2 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure to run program 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program1 PROC
call ClrScr ;Clears the screen
INVOKE Write_String_NL, OFFSET OriginalArray ;Prints header for original array
mov eax, TYPE ArrayToReverse ;Moves the array type into eax
cmp eax, 1 ;Checks if it's a BYTE array
je ITSBYTE ;Jumps to BYTE section if so
cmp eax, 2 ;Checks if WORD array
je ITSWORD ;Jumps to WORD section if so
cmp eax, 4 ;Check if DWORD array
je ITSDWORD ;Jumps to DWORD section if so
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Run for BYTE Array
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ITSBYTE:
mov esi, OFFSET ArrayToReverse ;Moves array into esi
mov ecx, LENGTHOF ArrayToReverse ;Moves number of elements in array into ecx
mov ebx, TYPE ArrayToReverse ;Moves type of array into ebx
call DumpMem ;Shows original array
mov esi, OFFSET ArrayToReverse ;Re-moves array into esi
mov edi, OFFSET ArrayToReverse + SIZEOF ArrayToReverse - TYPE ArrayToReverse ;Moves the pointer to the last value of the array into edi
mov eax, LENGTHOF ArrayToReverse ;Moves number of elements in array into eax
mov edx, 0 ;Sets remainder to zero by default
mov ebx, 2 ;Moves two into ebx
div ebx ;Divides number of elements by two
mov ecx, eax ;Puts that number into our loop counter
ReverseBYTE:
mov bl, [esi] ;Move data at beginning cursor to tmp storage
mov dl, [edi] ;Move data at end cursor to tmp storage
mov [esi], dl ;Move end data to beginning
mov [edi], bl ;Move beginning data to end
add esi, TYPE ArrayToReverse ;Move beginning cursor forward
sub edi, TYPE ArrayToReverse ;Move ending cursor back
loop ReverseBYTE ;Loop until count expired
jmp Prog1Ret ;Jump to procedure end when done
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Run for WORD Array
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ITSWORD:
mov esi, OFFSET ArrayToReverse ;Moves array into esi
mov ecx, LENGTHOF ArrayToReverse ;Moves number of elements in array into ecx
mov ebx, TYPE ArrayToReverse ;Moves type of array into ebx
call DumpMem ;Shows original array
mov esi, OFFSET ArrayToReverse ;Re-moves array into esi
mov edi, OFFSET ArrayToReverse + SIZEOF ArrayToReverse - TYPE ArrayToReverse ;Moves the pointer to the last value of the array into edi
mov eax, LENGTHOF ArrayToReverse ;Moves number of elements in array into eax
mov edx, 0 ;Sets remainder to zero by default
mov ebx, 2 ;Moves two into ebx
div ebx ;Divides number of elements by two
mov ecx, eax ;Puts that number into our loop counter
ReverseWORD:
mov bx, [esi] ;Move data at beginning cursor to tmp storage
mov dx, [edi] ;Move data at end cursor to tmp storage
mov [esi], dx ;Move end data to beginning
mov [edi], bx ;Move beginning data to end
add esi, TYPE ArrayToReverse ;Move beginning cursor forward
sub edi, TYPE ArrayToReverse ;Move ending cursor back
loop ReverseWORD ;Loop until count expired
jmp Prog1Ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Run for DWORD Array
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ITSDWORD:
mov esi, OFFSET ArrayToReverse ;Moves array into esi
mov ecx, LENGTHOF ArrayToReverse ;Moves number of elements in array into ecx
mov ebx, TYPE ArrayToReverse ;Moves type of array into ebx
call DumpMem ;Shows original array
mov esi, OFFSET ArrayToReverse ;Re-moves array into esi
mov edi, OFFSET ArrayToReverse + SIZEOF ArrayToReverse - TYPE ArrayToReverse ;Moves the pointer to the last value of the array into edi
mov eax, LENGTHOF ArrayToReverse ;Moves number of elements in array into eax
mov edx, 0 ;Sets remainder to zero by default
mov ebx, 2 ;Moves two into ebx
div ebx ;Divides number of elements by two
mov ecx, eax ;Puts that number into our loop counter
ReverseDWORD:
mov ebx, [esi] ;Move data at beginning cursor to tmp storage
mov edx, [edi] ;Move data at end cursor to tmp storage
mov [esi], edx ;Move end data to beginning
mov [edi], ebx ;Move beginning data to end
add esi, TYPE ArrayToReverse ;Move beginning cursor forward
sub edi, TYPE ArrayToReverse ;Move ending cursor back
loop ReverseWORD ;Loop until count expired
Prog1Ret:
call Crlf ;Print a new line
call Crlf ;Print a second new line
INVOKE Write_String_NL, OFFSET ReversedArray ;Print header to say this is the reversed array
mov esi, OFFSET ArrayToReverse ;Move array into esi
mov ecx, LENGTHOF ArrayToReverse ;Set number of elements
mov ebx, TYPE ArrayToReverse ;Set size of elements
call DumpMem ;Display array
ret ;Return from procedure
Program1 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Main Procedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main PROC
MainTitle:
call ClrScr ;Clear screen
call PrintTitle ;Print the title screen
call ReadInt ;Read in user selection
cmp eax, 1 ;Check if user selected entry item 1
je Prog1Jmp ;If so, jump to that program
cmp eax, 2 ;Check if user selected entry item 2
je Prog2Jmp ;If so, jump to that program
cmp eax, 3 ;Check if user selected entry item 3
je Prog3Jmp ;If so, jump to that program
cmp eax, 4 ;Check if user selected exit
je MainExit ;If so, jump to end of program
call ClrScr ;Clear screeen
INVOKE Write_String_NL, OFFSET IncorrectNumberEntry ;Scold user for not entering one to four
call ReadInt ;Wait for enter key
jmp MainTitle ;Jump back to main screen
Prog1Jmp:
call Program1 ;Call array reverse program
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
Prog2Jmp:
call Program2 ;Call String frequency program
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
Prog3Jmp:
call Program3 ;Call prime generator program
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
MainExit:
exit
main ENDP
END main

View File

@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASM_Project", "Assignment6.vcxproj", "{4164AA65-1EF9-4E69-899B-D1BED776070B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.ActiveCfg = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Debug|Win32.Build.0 = Debug|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.ActiveCfg = Release|Win32
{4164AA65-1EF9-4E69-899B-D1BED776070B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<MASM Include="CS271_proj6_perrenc.asm" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4164AA65-1EF9-4E69-899B-D1BED776070B}</ProjectGuid>
<ProjectName>ASM_Project</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
<Link>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<AdditionalLibraryDirectories>c:\Irvine;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalDependencies>user32.lib;irvine32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<MASM>
<IncludePaths>c:\Irvine</IncludePaths>
</MASM>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>

View File

@@ -0,0 +1,632 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TITLE Assignment 6 (main.asm)
;Author: Corwin Perren
;Date: 3/13/2014
;Description:
; This program runs all five programs from assignment 6 from a menu screen
; These programs include a letter matrix generator, array row sum calculator,
; a floating point comparator, circle area computer, and quadratic formula
; calculator
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE Irvine32.inc
.data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Program Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Global Relevant Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ProgramTitle BYTE "CS 271 - Assignment 6",0
ProgrammerName BYTE "Written by: Corwin Perren",0
SelectInstructions BYTE "Please enter 1-6 to run desired program.", 0
MenuItem1 BYTE "1: Letter Matrix Generator (Chapter 9, Exercise 10)",0
MenuItem2 BYTE "2: Two Dimensional Array Row Summer (Chapter 9, Exercise 12)",0
MenuItem3 BYTE "3: Floating Point Comparator (Chapter 12, Exercise 1)",0
MenuItem4 BYTE "4: Area of Circle Calculator (Chapter 12, Exercise 5)",0
MenuItem5 BYTE "5: Quadratic Formula Calculator (Chapter 12, Exercise 6)",0
MenuItem6 BYTE "6: Exit",0
Selection BYTE "Selection: ",0
IncorrectNumberEntry BYTE "You did not enter 1-7. Press enter to try again.", 0
ReturnToSelect BYTE "Program Complete. Press enter to return to selection screen.", 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Letter Matrix Generator Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
NumVowels DWORD 6
VowelArray BYTE "AEIOUY"
NumConsonants DWORD 20
ConsonantArray BYTE "BCDFGHJKLMNPQRSTVWXZ"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Two Dimensional Array Row Summer Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CurrentArrayContents BYTE "Array Contents:",0
TableRow1 BYTE "1 2 3 4 5",0 ;For printing to display only
TableRow2 BYTE "6 7 8 9 10",0 ;For printing to display only
TableRow3 BYTE "11 12 13 14 15",0 ;For printing to display only
TableRow4 BYTE "16 17 18 19 20",0 ;For printing to display only
TableRow5 BYTE "21 22 23 24 25",0 ;For printing to display only
SummerPleaseEnterIndex BYTE "Enter a row to sum between 1 and 5.",0
SummerIndexPrompt BYTE "Row: ",0
TableArrayIndex DWORD ?
TableArrayBYTE BYTE 1,2,3,4,5 ;Row 1
TableArrayRowSizeBYTE = ($-TableArrayBYTE) ;Size of single row
BYTE 6,7,8,9,10 ;Row 2
BYTE 11,12,13,14,15 ;Row 3
BYTE 16,17,18,19,20 ;Row 4
BYTE 21,22,23,24,25 ;Row 5
TableArrayWORD WORD 1,2,3,4,5 ;Row 1
TableArrayRowSizeWORD = ($-TableArrayWORD) ;Size of single row
WORD 6,7,8,9,10 ;Row 2
WORD 11,12,13,14,15 ;Row 3
WORD 16,17,18,19,20 ;Row 4
WORD 21,22,23,24,25 ;Row 5
TableArrayDWORD DWORD 1,2,3,4,5 ;Row 1
TableArrayRowSizeDWORD = ($-TableArrayDWORD) ;Size of single row
DWORD 6,7,8,9,10 ;Row 2
DWORD 11,12,13,14,15 ;Row 3
DWORD 16,17,18,19,20 ;Row 4
DWORD 21,22,23,24,25 ;Row 5
SummerBYTE BYTE "Sum using BYTE array: ",0
SummerWORD BYTE "Sum using WORD array: ",0
SummerDWORD BYTE"Sum using DWORD array: ",0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Floating Point Comparator Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EnterTwoFloat BYTE "Please enter two floating point numbers to compare.",0
Float1Prompt BYTE "First Number : ", 0
Float2Prompt BYTE "Second Number: ", 0
FirstLargerThanFloat BYTE "The first value you entered was larger than the second.", 0
SecondLargerThanFloat BYTE "The second value you entered was larger than the first.", 0
EqualFloat BYTE "The numbers you entered were equal",0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Area of Circle Calculator Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EnterRadius BYTE "Enter the radius of a circle to calculate it's area.",0
RadiusPrompt BYTE "Radius: ",0
CircleAreaCalculated BYTE "The area for this circle is: ",0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Quadratic Formula Calculator Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PleaseEnterCoeff BYTE "Please enter coefficients a, b, and c for a quadratic forumula in the form", 10, 13, "ax",253," + bx + c = 0 to calculate it's real roots.",0
RootsNonRealMsg BYTE "These coefficients result in non-real roots. Exiting.",0
Root1Msg BYTE "Root1: ",0
Root2Msg BYTE "Root2: ",0
CoeffA BYTE "a: ",0
CoeffB BYTE "b: ",0
CoeffC BYTE "c: ",0
Stores2 DWORD 2
Stores4 DWORD 4
FloatA REAL10 ?
FloatB REAL10 ?
FloatC REAL10 ?
AfterRootTaken REAL10 ?
Root1 REAL10 ?
Root2 REAL10 ?
.code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Globally Useful Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for writing string with newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Write_String_NL PROC uses EDX,
StringPtr:Ptr BYTE ;Varible to store string offset pointer
mov edx, StringPtr ;Moves the string to the proper register
call WriteString ;Prints the string
call Crlf ;Prints a new line
ret ;Return from procedure
Write_String_NL ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for writing string without newline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Write_String PROC uses EDX,
StringPtr:Ptr BYTE ;Variable to store string offset pointer
mov edx, StringPtr ;Moves the string to the proper registers
call WriteString ;Prints the string
ret
Write_String ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for printing program title and programmer name
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintTitle PROC
INVOKE Write_String_NL, OFFSET ProgramTitle ;Prints the program title
INVOKE Write_String_NL, OFFSET ProgrammerName ;prints the programmer's name
call Crlf ;Prints a new line
INVOKE Write_String_NL, OFFSET SelectInstructions ;Prints the selection screen instructions
call Crlf ;Prints a new line
INVOKE Write_String_NL, OFFSET MenuItem1 ;Prints menu item 1
INVOKE Write_String_NL, OFFSET MenuItem2 ;Prints menu item 2
INVOKE Write_String_NL, OFFSET MenuItem3 ;Prints menu item 3
INVOKE Write_String_NL, OFFSET MenuItem4 ;Prints menu item 4
INVOKE Write_String_NL, OFFSET MenuItem5 ;Prints menu item 2
INVOKE Write_String_NL, OFFSET MenuItem6 ;Prints menu item 3
INVOKE Write_String, OFFSET Selection ;Print selction prompt
ret
PrintTitle ENDP
ClearFPU PROC
FFREE ST(0)
FFREE ST(1)
FFREE ST(2)
FFREE ST(3)
FFREE ST(4)
FFREE ST(5)
FFREE ST(6)
FFREE ST(7)
ret
ClearFPU ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Letter Matrix Generator Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure returns a random consonant
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GetRandomConsonant PROC uses EBX
mov EAX, NumConsonants ;Set up range for random generator
mov EBX, offset ConsonantArray ;Move ConsonantArray into ebp for dereferencing
call RandomRange ;Get random number within range
add EBX, EAX ;Point to element in ebp
mov AL, [EBX] ;Store pointed to value in AL
ret ;Return from procedure
GetRandomConsonant ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure returns a random vowel
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GetRandomVowel PROC uses EBX
mov EAX, NumVowels ;Set up range for random generator
mov EBX, offset VowelArray ;Move VowelArray into ebp for dereferencing
call RandomRange ;Get random number within range
add EBX, EAX ;Point to element in ebp
mov AL, [EBX] ;Store pointed to value in AL
ret ;Return from procedure
GetRandomVowel ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure prints the matrixes in proper rows with random chars
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintMatrix PROC uses EAX ECX EDX
mov ECX, 4 ;Move column count into ECX
PrintLineLoop:
mov EDX, 4 ;Move row count into EDX
call CrLf ;Print new line
PrintShortLoop:
mov EAX, 2 ;Put in range for RandomRange of 2 (0-1)
call RandomRange ;Get random 0 to 1
cmp EAX, 0 ;Check if zero
jnz GetConsonant ;If one, print consonant
call GetRandomVowel ;Get Vowel from generator
jmp WriteCharToMatrix ;Go print the character
GetConsonant:
call GetRandomConsonant ;Get consonant from generator
WriteCharToMatrix:
call WriteChar ;Print current character
dec EDX ;Move forward one column
jnz PrintShortLoop ;Repeat column print until at column end
dec ECX ;Move down one row
jnz PrintLineLoop ;Print out column on new row
call CrLf ;Print a new line
ret ;Return from procedure
PrintMatrix ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure for running program1 functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program1 PROC
call ClrScr
call Randomize ;Seeds the random number generator
mov ECX, 5 ;Set loop counter to 5 to display matrix five times
Program1Loop:
call PrintMatrix ;Call procedure to print out one matrix
loop Program1Loop ;Continue printing until 5 arrays are one screen
ret ;Return from Program1 procedure
Program1 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Two Dimensional Array Row Summer Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure calculates the sum for a row using stack passed parameters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Calc_Row_Sum PROC
mov ebp, esp ;Get access to the stack
mov ebx, [ebp+4] ;Save users selected row index
dec ebx ;Remove one to make math simpler
mov edx, [ebp+8] ;Save table type
mov ecx, [ebp+12] ;Setup counter with row length
mov esi, [ebp+16] ;Move array into array reg
cmp edx, 1 ;Check if it's a BYTE
je RowSumBYTE ;Jump if BYTE
cmp edx, 2 ;Check if it's a WORD
je RowSumWORD ;Jump if WORD
cmp edx, 4 ;Check if DWORD
je RowSumDWORD ;Jump if DWORD
RowSumBYTE:
mov eax, ecx ;Move row length into eax
mul ebx ;Mutiply by row index
add esi, eax ;Add this offset to esi
mov eax, 0 ;Zero accumulator
RowSumBYTELoop:
add al, [esi] ;Add value to al
inc esi ;Move to the next value in the array
loop RowSumBYTELoop ;Loop until row finished
jmp CalcRowSumEnd ;Jump when finished
RowSumWORD:
push edx ;Save EDX to stack
mov eax, ecx ;Set up multiplication of 2
mul ebx ;Multiply user index by two (Now if WORD format)
add esi, eax ;Move cursor to index location using offset
pop edx ;Return EDX to reg
mov ebx, edx ;Store TYPE in EBX
mov edx, 0 ;Zero upper half for multiplication
mov eax, ecx ;Set lower half to row size
div ebx ;Divide by TYPE
mov ecx, eax ;Set this number in the loop count reg
mov eax, 0 ;Zero accumulator
RowSumWORDLoop:
add ax, [esi] ;Add value to ax
add esi, 2 ;Move to the next value in the array
loop RowSumWORDLoop ;Loop until row finished
jmp CalcRowSumEnd ;Jump when finished
RowSumDWORD:
push edx ;Save EDX to stack
mov eax, ecx ;Set up multiplication of 4
mul ebx ;Multiply user index by four (Now in DWORD format)
add esi, eax ;Move cursor to index location using offset
pop edx ;Return EDX to reg
mov ebx, edx ;Store TYPE in EBX
mov edx, 0 ;Zero upper half for multiplication
mov eax, ecx ;Set lower half to row size
div ebx ;Divide by TYPE
mov ecx, eax ;Set this number in the loop count reg
mov eax, 0 ;Zero accumulator
RowSumDWORDLoop:
add eax, [esi] ;Add value to ax
add esi, 4 ;Move to the next value in the array
loop RowSumDWORDLoop ;Loop until row finished
CalcRowSumEnd:
ret ;Return from procedure
Calc_Row_Sum ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Program2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program2 PROC
call ClrScr ;Clears the screen
INVOKE Write_String_NL, OFFSET CurrentArrayContents ;Prints out array contents header
INVOKE Write_String_NL, OFFSET TableRow1 ;Prints table row 1
INVOKE Write_String_NL, OFFSET TableRow2 ;Prints table row 2
INVOKE Write_String_NL, OFFSET TableRow3 ;Prints table row 3
INVOKE Write_String_NL, OFFSET TableRow4 ;Prints table row 4
INVOKE Write_String_NL, OFFSET TableRow5 ;Prints table row 5
INVOKE Write_String_NL, OFFSET SummerPleaseEnterIndex ;Asks user to enter index value
INVOKE Write_String, OFFSET SummerIndexPrompt ;Row prompt for niceity
call ReadInt ;Read in Index from user
mov TableArrayIndex, EAX ;Moves user selection into variable
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Using BYTES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
push OFFSET TableArrayBYTE ;Pushes the offset for the table array (32-bit)
mov eax, 0 ;Clears the eax register
mov eax, TableArrayRowSizeBYTE ;Moves the table array row size into eax
push eax ;Pushes that number onto the stack (32-bit)
mov eax, 0 ;Clears the eax register
mov eax, TYPE TableArrayBYTE ;Moves the type of table array into eax
push eax ;Pushes the type of the array onto the stack (32-bit)
push TableArrayIndex ;Pushes the index selected by the user onto the stack (32-bit)
call Calc_Row_Sum ;Calculates sum for row and prints it
INVOKE Write_String, OFFSET SummerBYTE ;Prints out what array was used to sum
call WriteInt ;Writes to display
call Crlf ;Prints a new line
add esp, 16 ;Cleanup the stack (4 times 32-bit)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Using WORDS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
push OFFSET TableArrayWORD ;Pushes the offset for the table array (32-bit)
mov eax, 0 ;Clears the eax register
mov eax, TableArrayRowSizeWORD ;Moves the table array row size into eax
push eax ;Pushes that number onto the stack (32-bit)
mov eax, 0 ;Clears the eax register
mov eax, TYPE TableArrayWORD ;Moves the type of table array into eax
push eax ;Pushes the type of the array onto the stack (32-bit)
push TableArrayIndex ;Pushes the index selected by the user onto the stack (32-bit)
call Calc_Row_Sum ;Calculates sum for row and prints it
INVOKE Write_String, OFFSET SummerWORD ;Prints out what array was used to sum
call WriteInt ;Writes sum to display
call Crlf ;Prints a new line
add esp, 16 ;Cleanup the stack (4 times 32-bit)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Using DWORDS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
push OFFSET TableArrayDWORD ;Pushes the offset for the table array (32-bit)
mov eax, 0 ;Clears the eax register
mov eax, TableArrayRowSizeDWORD ;Moves the table array row size into eax
push eax ;Pushes that number onto the stack (32-bit)
mov eax, 0 ;Clears the eax register
mov eax, TYPE TableArrayDWORD ;Moves the type of table array into eax
push eax ;Pushes the type of the array onto the stack (32-bit)
push TableArrayIndex ;Pushes the index selected by the user onto the stack (32-bit)
call Calc_Row_Sum ;Calculates sum for row and prints it
INVOKE Write_String, OFFSET SummerDWORD ;Prints out what array was used to sum
call WriteInt ;Writes sum to the screen
add esp, 16 ;Cleanup the stack (4 times 32-bit)
ret ;Return from Program2 procedure
Program2 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Floating Point Comparator Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure runs program 3 functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program3 PROC
call ClrScr
INVOKE Write_String_NL, OFFSET EnterTwoFloat ;Prompt to enter two floating point numbers
INVOKE Write_String, OFFSET Float1Prompt ;Prompt for first val
call ReadFloat ;Read in value
INVOKE Write_String, OFFSET Float2Prompt ;Prompt for second val
call ReadFloat ;Read in value
call CRLF ;Print newline
FCOMI ST(0), ST(1) ;Compare second value entered to first
ja SecondWasGreater ;If the second is above the first, it's greater so jump
INVOKE Write_String_NL, OFFSET FirstLargerThanFloat ;Otherwise, the first was greater and we print a message saying so
jmp Prog3Ending ;Then we jump to program end
SecondWasGreater:
INVOKE Write_String_NL, OFFSET SecondLargerThanFloat ;In the case the second is greater than the first, we will print that instead
Prog3Ending:
ret ;Return from Program3 procedure
Program3 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Area of Circle Calculator Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure runs program 4 functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program4 PROC
call ClrScr ;Clear the screen
INVOKE Write_String_NL, OFFSET EnterRadius ;Prompt the user to enter the radius
INVOKE Write_String, OFFSET RadiusPrompt ;Provide nice header
FLDPI ;Load pi onto floating point unit stack
call ReadFloat ;Read in float from user
fld ST(0) ;Load a second radius onto floating point stack
FMULP ;Mulitply and pop
FMULP ;Multiply and pop
INVOKE Write_String, OFFSET CircleAreaCalculated ;Print header for final value
call WriteFloat ;Write calculated value to screen
FFREE ST(0) ;Free FPU stack
ret ;Return from Program4 procedure
Program4 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Quadratic Formula Calculator Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure reads in float coefficients from user
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GetCoefficients PROC
INVOKE Write_String_NL, OFFSET PleaseEnterCoeff ;Asks user to enter coefficients
call Crlf ;Prints a new line
INVOKE Write_String, OFFSET CoeffA ;Asks for a
call ReadFloat ;Reads in a
INVOKE Write_String, OFFSET CoeffB ;Asks for b
call ReadFloat ;Reads in b
INVOKE Write_String, OFFSET CoeffC ;Asks for c
call ReadFloat ;Reads in c
FSTP FloatC ;Store coeff c in var
FSTP FloatB ;Store coeff b in var
FSTP FloatA ;Store coeff a in var
ret ;Return from procedure
GetCoefficients ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Procedure runs program5 functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Program5 PROC
call ClrScr ;Clear the screen
call GetCoefficients ;Reading in coefficients from user
FLD FLoatB ;Load b
FMUL ST(0), ST(0) ;Square b
FLD FloatA ;Load a
FLD FloatC ;Load c
FIMUL Stores4 ;Multiply c by 4
FMULP ST(1), ST(0) ;End result is 4*a*c
FSUBP ST(1), ST(0) ;End result is b^2-4ac
FLDZ ;Load zero onto stack for comparison
FCOMIP ST(0), ST(1) ;Check if roots are going to be real or not
ja NonRealRoots ;Jump to message if roots are non-real and exit
FSQRT ;Take square root as it's real
FSTP AfterRootTaken ;Store for use later on other root
FLD FloatB ;Load b
FCHS ;Negate b
FLD AfterRootTaken ;Load rooted val
FSUB ;Subtract rooted val from negated b (-b - sqrt(b^2-4ac))
FLD FloatA ;Load a
FIMUL Stores2 ;Multiply a by 2
FDIV ;Divide numerator by denominator
FSTP Root1 ;Store first root value
FLD FloatB ;Load b
FCHS ;Negate b
FLD AfterRootTaken ;Load rooted val
FADD ;Add rooted val from negated b (-b - sqrt(b^2-4ac))
FLD FloatA ;Load a
FIMUL Stores2 ;Multiply a by 2
FDIV ;Divide numerator by denominator
FSTP Root2 ;Store second root value
call Crlf
INVOKE Write_String, OFFSET Root1Msg ;Print Root1 Header
FLD Root1 ;Load root1 into register
call WriteFloat ;Print root1
FFREE ST(0) ;Free FPU register
call Crlf ;Print new line
INVOKE Write_String, OFFSET Root2Msg ;Print root2 header
FLD Root2 ;Load root2 into register
call WriteFloat ;Print root2
FFREE ST(0) ;Free FPU register
call Crlf ;Print a new line
jmp Program5Ending ;Jump to program end
NonRealRoots:
FFREE ST(0) ;Free up register so it can be used again
INVOKE Write_String_NL, OFFSET RootsNonRealMsg ;Print message saying there are no real roots
Program5Ending:
ret ;Return from Program5 procedure
Program5 ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Program Main Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Main Procedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main PROC
FINIT ;Initialize floating point unit
MainTitle:
call ClrScr ;Clear screen
call PrintTitle ;Print the title screen
call ReadInt ;Read in user selection
cmp eax, 1 ;Check if user selected entry item 1
je Prog1Jmp ;If so, jump to that program
cmp eax, 2 ;Check if user selected entry item 2
je Prog2Jmp ;If so, jump to that program
cmp eax, 3 ;Check if user selected entry item 3
je Prog3Jmp ;If so, jump to that program
cmp eax, 4 ;Check if user selected entry item 4
je Prog4Jmp ;If so, jump to that program
cmp eax, 5 ;Check if user selected entry item 5
je Prog5Jmp ;If so, jump to that program
cmp eax, 6 ;Check if user selected exit
je MainExit ;If so, jump to end of program
call ClrScr ;Clear screeen
INVOKE Write_String_NL, OFFSET IncorrectNumberEntry ;Scold user for not entering one to six
call ReadInt ;Wait for enter key
jmp MainTitle ;Jump back to main screen
Prog1Jmp:
call Program1 ;Call program1
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
Prog2Jmp:
call Program2 ;Call program2
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
Prog3Jmp:
call ClearFPU ;Empties FPU Registers to keep things from crashing
call Program3 ;Call program3
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
Prog4Jmp:
call ClearFPU ;Empties FPU Registers to keep things from crashing
call Program4 ;Call program4
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
Prog5Jmp:
call ClearFPU ;Empties FPU Registers to keep things from crashing
call Program5 ;Call program5
call Crlf ;Print new line
INVOKE Write_String_NL, OFFSET ReturnToSelect ;Print hit enter to return to screen
call ReadInt ;Wait for enter
jmp MainTitle ;Jump to main screen
MainExit:
exit
main ENDP
END main