Lesson no.1 The 4 basic registers
First I'd like to start with a brief explaination of variables in ASM. ASM is very diffrent from QB and high-level languages, as it doesn't use variable names. (well assemblers do in their way, but at a pure level there is no variable naming system) Of course, you can store data in the computers memory, but it wont be "tagged" with a variable name like i% or num1.
When fooling around with asm, you get many preset (variables) to temporarly hold critical data. The first four registers we will learn today are:
AX 16-bit register BX 16-bit register CX 16-bit register DX 16-bit register
Well you see AX, BX, CX and DX are all really integers (can have a value between -32766 to 32767) inside your CPU. You're probably thinking "4 integers! How am I ment to work with that many variables!" You see that's the art of ASM (ofcourse there are more than 4 registers but I'll introduce them later) you must challenge your self programming in it! If you don't want to be challenged and you just want to use other people's librarys, please stop now and spare yourself some precious time, ASM is not for everybody.
Lesson no.2 Some very basic commands
Before starting this section, read the HEX tutorial if you have no previous knowledge of using hexadecimal.
In order to give a register a value, you must "move" the value into the register. It's simpler than you think, here is an example:
MOV AX,1that command tells the CPU to assign register AX a value of &H1. So in other words ax% = &H1. Here's another example:
MOV CX,32That command tells the CPU to assign register CX a value of &H32. that mean cx% = &H32.
You can also assign values from one register to another like so:
MOV BX,DXThis give BX the value of DX. As you can see it's easier than you probably thought, Moving a value from one register to another, or assigning a value to a register takes a bit of time, but when I say a bit of time I mean 2 clocks* on a 80286 (really old processor) or 1 clock on a 486/Pentium.
To add a value to register you use the simple "add" code like so:
ADD AX,4This increases the value of AX by &H4. You can also add another register to an other register like you would when "mov"ing. Heres an example code :
MOV AX,3 MOV DX,AX ADD DX,4 ADD AX,DXWhat does the value of AX end up? Simple, &H7! Look at the code carefully if you don't agree with my calculations.
Well that's it for this artical, in part two we'll be discussing some more productive methods of using ASM.
* A Clock cycical is used to mesure time taken by the processor to process a command, to find the nanosecond taken you use this simple command : (1000Mhz/(n Mhz))=X nanoseconds Where n is the Mhz speed of the computer.
The author of this article can be contacted at: abionnnn@geocities.com
© Copyright Nightwolf Productions 1999