Skip to content

Commit c33acb7

Browse files
committedJul 11, 2023
Adding 6. Conditional Branches
1 parent e978ee4 commit c33acb7

File tree

4 files changed

+242
-0
lines changed

4 files changed

+242
-0
lines changed
 

Diff for: ‎Assembly64.sln

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Flags", "Episode5\Flags\Fla
2525
EndProject
2626
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Episode 5", "Episode 5", "{5A70F316-4DFE-4502-9A21-51B2BD05D446}"
2727
EndProject
28+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConditionalJumps", "Episode6\ConditionalJumps\ConditionalJumps.vcxproj", "{4DD40142-837D-4461-BA3F-0A805A2A057A}"
29+
EndProject
30+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Episode 6", "Episode 6", "{F3695239-C1C4-487E-A513-9D53EDECD849}"
31+
EndProject
2832
Global
2933
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3034
Debug|x64 = Debug|x64
@@ -55,6 +59,10 @@ Global
5559
{03695492-74FF-4903-BE0B-6B46CFABA571}.Debug|x64.Build.0 = Debug|x64
5660
{03695492-74FF-4903-BE0B-6B46CFABA571}.Release|x64.ActiveCfg = Release|x64
5761
{03695492-74FF-4903-BE0B-6B46CFABA571}.Release|x64.Build.0 = Release|x64
62+
{4DD40142-837D-4461-BA3F-0A805A2A057A}.Debug|x64.ActiveCfg = Debug|x64
63+
{4DD40142-837D-4461-BA3F-0A805A2A057A}.Debug|x64.Build.0 = Debug|x64
64+
{4DD40142-837D-4461-BA3F-0A805A2A057A}.Release|x64.ActiveCfg = Release|x64
65+
{4DD40142-837D-4461-BA3F-0A805A2A057A}.Release|x64.Build.0 = Release|x64
5866
EndGlobalSection
5967
GlobalSection(SolutionProperties) = preSolution
6068
HideSolutionNode = FALSE
@@ -66,6 +74,7 @@ Global
6674
{58E5588C-DC09-4951-B8B0-3EF2BABD38F4} = {95ABA174-1152-401A-9D3E-9D6CDE2B9228}
6775
{49E26C62-F111-4C69-AC6A-784B219B9ADE} = {BDAB1C19-10D8-42C3-B247-7EBF52866D78}
6876
{03695492-74FF-4903-BE0B-6B46CFABA571} = {5A70F316-4DFE-4502-9A21-51B2BD05D446}
77+
{4DD40142-837D-4461-BA3F-0A805A2A057A} = {F3695239-C1C4-487E-A513-9D53EDECD849}
6978
EndGlobalSection
7079
GlobalSection(ExtensibilityGlobals) = postSolution
7180
SolutionGuid = {74B06FA8-487D-4545-8B72-13DF56D10686}

Diff for: ‎Episode6/ConditionalJumps/ConditionalJumps.vcxproj

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|x64">
9+
<Configuration>Release</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<VCProjectVersion>16.0</VCProjectVersion>
15+
<Keyword>Win32Proj</Keyword>
16+
<ProjectGuid>{4dd40142-837d-4461-ba3f-0a805a2a057a}</ProjectGuid>
17+
<RootNamespace>ConditionalJumps</RootNamespace>
18+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
22+
<ConfigurationType>Application</ConfigurationType>
23+
<UseDebugLibraries>true</UseDebugLibraries>
24+
<PlatformToolset>v143</PlatformToolset>
25+
<CharacterSet>Unicode</CharacterSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>false</UseDebugLibraries>
30+
<PlatformToolset>v143</PlatformToolset>
31+
<WholeProgramOptimization>true</WholeProgramOptimization>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
35+
<ImportGroup Label="ExtensionSettings">
36+
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
37+
</ImportGroup>
38+
<ImportGroup Label="Shared">
39+
</ImportGroup>
40+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
41+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
42+
</ImportGroup>
43+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
44+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
45+
</ImportGroup>
46+
<PropertyGroup Label="UserMacros" />
47+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
48+
<ClCompile>
49+
<WarningLevel>Level3</WarningLevel>
50+
<SDLCheck>true</SDLCheck>
51+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
52+
<ConformanceMode>true</ConformanceMode>
53+
</ClCompile>
54+
<Link>
55+
<SubSystem>Console</SubSystem>
56+
<GenerateDebugInformation>true</GenerateDebugInformation>
57+
<EntryPointSymbol>main</EntryPointSymbol>
58+
</Link>
59+
</ItemDefinitionGroup>
60+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
61+
<ClCompile>
62+
<WarningLevel>Level3</WarningLevel>
63+
<FunctionLevelLinking>true</FunctionLevelLinking>
64+
<IntrinsicFunctions>true</IntrinsicFunctions>
65+
<SDLCheck>true</SDLCheck>
66+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
67+
<ConformanceMode>true</ConformanceMode>
68+
</ClCompile>
69+
<Link>
70+
<SubSystem>Console</SubSystem>
71+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
72+
<OptimizeReferences>true</OptimizeReferences>
73+
<GenerateDebugInformation>true</GenerateDebugInformation>
74+
<EntryPointSymbol>main</EntryPointSymbol>
75+
</Link>
76+
</ItemDefinitionGroup>
77+
<ItemGroup>
78+
<MASM Include="main.asm" />
79+
</ItemGroup>
80+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
81+
<ImportGroup Label="ExtensionTargets">
82+
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
83+
</ImportGroup>
84+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<MASM Include="main.asm" />
5+
</ItemGroup>
6+
</Project>

Diff for: ‎Episode6/ConditionalJumps/main.asm

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
.CODE
2+
3+
main PROC
4+
mov eax, 0
5+
6+
; Carry flag conditional jumps
7+
8+
call CarryFlagSet
9+
call CarryFlagNotSet
10+
11+
; Zero flag conditional jumps
12+
13+
call ZeroFlagSet
14+
call ZeroFlagNotSet
15+
16+
; Sign flag conditional jumps
17+
18+
call SignFlagSet
19+
call SignFlagNotSet
20+
21+
; Overflow flag conditional jumps
22+
23+
call OverflowFlagSet
24+
call OverflowFlagNotSet
25+
26+
; unconditional jump
27+
28+
call UnconditionalJump
29+
30+
mov eax, 0
31+
ret
32+
main ENDP
33+
34+
35+
CarryFlagSet PROC
36+
mov al, 255
37+
add al, 1
38+
jc Carry1
39+
jnc NoCarry1
40+
Carry1:
41+
ret
42+
NoCarry1:
43+
ret
44+
CarryFlagSet ENDP
45+
46+
47+
CarryFlagNotSet PROC
48+
mov al, 200
49+
add al, 1
50+
jc Carry2
51+
jnc NoCarry2
52+
Carry2:
53+
ret
54+
NoCarry2:
55+
ret
56+
CarryFlagNotSet ENDP
57+
58+
59+
ZeroFlagSet PROC
60+
mov rax, 1
61+
dec rax
62+
jz Zero1
63+
jnz NoZero1
64+
Zero1:
65+
ret
66+
NoZero1:
67+
ret
68+
ZeroFlagSet ENDP
69+
70+
71+
ZeroFlagNotSet PROC
72+
mov rax, 5
73+
dec rax
74+
jz Zero2
75+
jnz NoZero2
76+
Zero2:
77+
ret
78+
NoZero2:
79+
ret
80+
ZeroFlagNotSet ENDP
81+
82+
83+
SignFlagSet PROC
84+
mov rax, 1
85+
sub rax, 3
86+
js Sign1
87+
jns NoSign1
88+
Sign1:
89+
ret
90+
NoSign1:
91+
ret
92+
SignFlagSet ENDP
93+
94+
95+
SignFlagNotSet PROC
96+
mov rax, 6
97+
sub rax, 3
98+
js Sign2
99+
jns NoSign2
100+
Sign2:
101+
ret
102+
NoSign2:
103+
ret
104+
SignFlagNotSet ENDP
105+
106+
107+
OverflowFlagSet PROC
108+
mov al, 127
109+
add al, 1
110+
jo Overflow1
111+
jno NoOverflow1
112+
Overflow1:
113+
ret
114+
NoOverflow1:
115+
ret
116+
OverflowFlagSet ENDP
117+
118+
119+
OverflowFlagNotSet PROC
120+
mov al, 120
121+
add al, 1
122+
jo Overflow2
123+
jno NoOverflow2
124+
Overflow2:
125+
ret
126+
NoOverflow2:
127+
ret
128+
OverflowFlagNotSet ENDP
129+
130+
131+
UnconditionalJump PROC
132+
mov rax, 3
133+
decrement:
134+
dec rax
135+
jz exit
136+
jmp decrement
137+
; jnz decrement ; this would better (instead of jz + jmp)
138+
exit:
139+
ret
140+
UnconditionalJump ENDP
141+
142+
143+
END

0 commit comments

Comments
 (0)
Please sign in to comment.