So I am looking at the instruction set (on Wikipedia) and seeing JZ and
JNZ. What advice should I take about implementing those?
You need to test the result of operations and set a flag. The JZ means "jump
if zero" and the JNZ means "jump if not zero". Other forms can say BZ for
"branch if zero" and BNZ for "branch if not zero".
In your add operation, for example, if the two integer values add up to be
zero (-1 added to +1 equals 0) then based on the result you set a flag.
The flag nomenclature is typically ?Z or Z? and indicates the flag state.
When it is ?Z the flag is raised (upper case letters) which means that
state is signaling. In this case -1 added to +1 equals 0 would cause ?Z
because the result is zero, and the flag now indicates that condition.
In the case of +5 added to +2 equals +7, the state would be ?z (lowered),
because the result was not zero.
Then for branching instructions, you test the condition of that flag, and
based on whatever the branching conditions you're setting are, you either
branch or don't branch.
If you have an x86 box with Windows, and can download Visual Studio express,
you'll find it very helpful. You can email me offline if you'd like some
assistance on stepping through x86 assembly. But, seeing the practical
results in a real, graphical debugger, which shows the register and flag
states change as you step through assembly instructions ... for the task
you're on about it would be most beneficial in my estimation.
Other common conditions:
?Z or ?z -- Zero
?O or ?o -- Overflow (adding 200 and 200 in an 8-bit quantity overflows)
?U or ?u -- Underflow (same thing with subtracting)
?P or ?p -- Parity (if the number of bits in the result was odd)
And other flags. Check out the EFLAGS register in the Intel IA-32 if you'd
like to see the ones used by the x86 CPU.
Best regards,
Rick C. Hodgin