ASM in QBasic
Hello, and welcome to my first article in this small serie. As you know the future of
QBasic/QuickBasic relies on the extensive use of ASM. But the problem is that the QBasic
community doesn't have enough qualified programmers to "drive" this complicated machine.
Well, I want to change all that today. = ) Before you start reading this I must warn you,
this is pretty heavy stuff to start on, if you're only starting on QBasic now is the time
to back out. Don't say I didn't warn you ; ) And for ASM pros, don't read this either,
because I'll end up insulting your intelligence and you'll end up hating me. The first
thing you need to get to start ASMing is an assembler, a debugger, and a guide. You
probably have the last one (your reading it right now), but if you need to get the other
two, hop down to http://www.quickbasic.com/ and get yourself "The ATK V2.01" (If ChUcK put
it up there, if he didn't email me and I'll put it up there, in the mean time download the
atk v1.0). Got everything? Good. Here we go:
Lesson no.1 The 4 basic registers
First I'd like to start with a brief explaination of variables in ASM. ASM is very
different 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 meant to work with
that many variables!" You see that's the art of ASM (of course 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 libraries, 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,1
that command tells the CPU to assign register AX a value of &H1. So in other words
ax% = &H1. Here's another example:
MOV CX,32
That 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,DX
This 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,4
This increases the value of AX by &H4. You can also add another register to an other
register like you would when "mov"ing. Here's an example code :
MOV AX,3
MOV DX,AX
ADD DX,4
ADD AX,DX
What 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 article, 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 1999-2000 The QB Times.
This tutorial was taken from The QB Times with permission from the webmaster(s)
of the site. You may not take this article and place it on any other website.