First, you can find MASM.EXE and LINK.EXE at
http://users.ece.gatech.edu/~hamblen/489X/iotest/

This site has MASM 5.0 on it, which is plenty enough for what we are doing. Masm32 is a GREAT assembler, but has trouble with DOS apps, and we REALLY don't want to go into the Windows API in assembly, but if you want to learn to do that you can goto: http://spiff.tripnet.se/~iczelion as he has some of the best win32 programming guides I have ever seen.

Now that we have the EASY stuff over this tutorial will go into a small amount of detail and have a nifty code example of how to do conditional jumps (sort of like an IF then statement).

When we last left our coding we had learned how to call one procedure from another, this is useful, but please, do NOT try to make a loop like this, it WILL go infinate and it will freeze your machine. (just thought I would warn you). Since I like to code SAFELY I will not cover the actual LOOP instruction (yet), instead I shall cover conditional jumping which will allow you to make "safe" loops with little danger of going unbounded and locking the machine. First of all, we must understand that MASM allows us to label locations in the code (with debug we would have to jump to addresses not to a label). To specify a label type a label name followed by a colon so "start:" would be a label we can jump to.

Now let's go over all the possible logic for jumping. Here they are:


*************************************************
jmp-->always jump
jne-->Jump if not equal to
jnz-->same as jne
ja-->jump if greater than
jae-->jump if greater than or equal to
jb-->jump if less than
jbe-->jump if less than or equal to
jna-->jumps if the first number was NOT above
jnae--> jumps if The first number was NOT above or equal to
jnb-->jumps if the first number is not below
jnbe-->jumps if the first number is not below or equal to
jz-->jumps if the numbers are equal
je-->same as jz
jc-->Jump if carry flag is set (will not cover this one)

The jump can only be up to 127 bytes in either direction.
*************************************************
Now to understand how to code a jump, first of all we need to know how we are comparing, for this we use the 'cmp' instruction. The CMP instruction compares two values of equal size (either 8 bit registers, 16 bit registers, or two variables) and goes to the next instruction in the code (this will be the jump instruction). Now some code to show how this works. I am assuming the user has already downloaded (and learned to read) the interrupt list I gave the address for in the last tutorial.
.model small
.stack
.data
Message db "Press Y or N:$" ;Prompt for user
Uyes db "You pressed Y!$" ;Pressed y
Uno db "You pressed N!$" ;Pressed n
;###########################################################;Start of Code
;###########################################################
.code
start:
mov ax,03h ;clears screen (function 3h)
int 10h ;interrupt 10h

mov ax, SEG Message ;put segment of message into AX
mov ds, ax ;put this into DS
mov dx, OFFSET Message ;put offset of message into AX
mov ah,09h ;Function 9h of
int 21h ;Interrupt 21h

mov ah,01h ;function 01h of int21h,
int 21h ;get char from keyboard

cmp al, "Y" ;if ah Y then
je Yes ;Goto Yes label

cmp al, "N" ;if ah N then
je No ;Goto No Label
jne start ;if not Y or N then goto start

Yes:
mov ax,03h ;clears screen (function 3h)
int 10h ;interrupt 10h

mov ax, SEG Uyes ;segment of Uyes
mov ds, ax ;put segment into DS
mov dx, OFFSET Uyes ;put offset of Uyes into DX
mov ah,09h ;function 9h print string at DSX
int 21h ;call interrupt 21h
jmp close

No:
mov ax,03h ;clears screen (function 3h)
int 10h ;interrupt 10h

mov ax, SEG Uno ;segment of Uno
mov ds, ax ;put segment into DS
mov dx, OFFSET Uno ;put offset of Uno into DX
mov ah,09h ;function 9h print string at DSX
int 21h ;call interrupt 21h
jmp close



;###########################################################
;Close routine
;###########################################################
close:
mov ax,4c00h ;put 4c00h into ax, closing back to DOS
int 21h ;INT 21h, return to DOS

end start
I believe with the comments this code is pretty self explainatory. It basically prompts the user for a choice Y or N. If the user chooses an invalid choice, the program loops back to start.

Well until next time I guess I shall say goodbye, time for some sleep, and to get off work!
Cheeseball

PS: this code looks crappy in a forum, if you want an easier to READ version goto: www25.brinkster.com/cheeseball/asmtut2.htm