If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Tutorial: The basics of 80x86 assembly with MASM 5.0 II

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.

hey cheeseball i was having one doubt i studied all your programs which u have
written in your tutorial. in the program which prints "hello world" if we want to
print two strings ..( i tried that ) but they are comming side by side.
hey is there any escape character in assembly so that we can print the second
string in second line.???

and pls post something more about the assembly i am waiting for your tutorial part III

OOPS, forgot something VERY important, if you want to print a "newline" you have to do charecters 10 and character 13, this is for a newline and a carriage return (yes you have to do both). you can append this to your string by doing a

it does not matter which one you do first, you can also specify them as constants, but that is a little bit of a longer post. Sorry I haven't posted anything new, I have started on a "project" to kill my boredom and maybe make my resume look better.

There are code tags?? Wow....that is nice... What I am currently working on is a troubleshooting tool to keep me from taking 90 year old ladies into DOS to do pings, pull network config, system information, check DNS, pull the current IP, and stuff like that.....I have 4 modules in it and working decently ok right now.

remember it's off my head this would work also. U didn't need the "jmp close instruction" after the code in the 'No lablel' it's only wasted processor time and slows program down.
but I have to give to U Cheeseball keep it up and maybe U'll convert the C and C++ heathens%-<|> anyway good work