home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.whtech.com
/
ftp.whtech.com.tar
/
ftp.whtech.com
/
Geneve
/
9640news
/
CAT14
/
ASMTTR1.ARK
< prev
next >
Wrap
Text File
|
2006-10-19
|
15KB
|
299 lines
?
TUTORIAL 1 - THE BEGINNING
by Mack McCormick
Here are the objectives of this first tutorial: 1. To introduce you to the
Hexadecimal and Binary Numbering systems. 2. To introduce you to the assembler
instruction format. 3. To introduce you to addressing modes. 4. First
program. Adding two numbers and displaying them on the screen. 5. How to
assemble.
Just a few words on Assembly language before we begin. It's not as difficult
as you may believe. You will be communicating with the microprocessor at the
first level above machine language, assembler. As you know, the machine
actually communicates in binary 0's and 1's, on or off. Assembler allows us to
talk to the machine in a language we can understand (Although I'm sure the
uninformed would disagree). With these tutorials I will assume no prior
knowledge of assembler or other number systems. Please bear with me, I won't
insult your intelligence and things will become more complex soon. Stick with
the tutorials. Read every book about assembler you can get your hands on. I
will publish a bibliography of books soon. Don't get discouraged! Compuserve
is a difficult medium thru which to provide assistance. I promise to answer
your questions and if I don't know the answer, I'll find someone else that can.
Please make this an interactive process, as we grow and learn with each other.
Numbering Systems
Hexadecimal (HEX) and binary are merely different base numbering
systems for counting. It's important we understand both of these systems in
addition to base 10 or the decimal system because assembler uses all three. I
will tell you up front that I use a calculator designed for these numbering
systems usually but we need to understand the principles also. If you want to
get a calculator, and I recommend that you do, there are several inexpensive
models on the market. I use the Casio solar powered fx-451 scientific
calculator for $35. It supports HEX, OCT, BIN, LOGICAL OPERATORS, and all
scientific functions. Works great! Craig Miller and others have also published
programs which will allow you to use your computer but this has the
disadvantage of requiring you to load another program every time you need to
make a calculation, a real pain.
Binary Number System
As already mentioned, binary is the native language for your computer.
Everything eventually gets converted to binary. Let's look at a decimal number
first. As you know decimal means powers of 10. Each number represents a power
of ten. For example 4175:
10^3=1000 4 X 1000=4000
10^2= 100 1 X 100= 100
10^1= 10 7 X 10= 70
10^0= 1 5 X 1= 5
______
4175
Binary numbers can be 1 or 0 only, hence base 2. The individual number is
called a bit. A group of eight of these is called a byte. To convert the binary
number 00001011 to decimal follow the same procedures you used with the decimal
number:
Ignore any leading zeros.
2^3=8 1 X 8=8
2^2=4 0 X 4=0
2^1=2 1 X 2=2
2^0=1 1 X 1=1
___
11
To make it easier to communicate with the computer we most often use HEX. From
now on I will use a > to indicate a number is in hex. Hex is base 16. That is
a number may be 0 thru 15. To represent numbers greater than 9 we use letters
of the alphabet. 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. Just remember to use >A for
10 and count to 15 ending with >F. Let's convert >394F to decimal:
16^3=4096 3 X 4096=12,288
16^2= 256 9 X 256= 2,304
16^1= 16 4 X 16= 64
16^0= 1 F X 1= 15
_________
14,671
The largest number you may represent in one byte is >FF or decimal 255. The
largest value in a word (two bytes) is >FFFF or 65,535. Enough on numbering
systems for now, we'll cover minus numbers (twos compliment) and additional
points as we encounter them in programs.
Assembler Instruction Syntax.
Like every computer language there are certain rules we must follow for
inputting instructions. Unlike BASIC, assembler will not give you a warning or
error until you assemble the program. Here's the general syntax:
LABEL OPCODE OPERAND COMMENT
labels must begin in the 1st column and may be up to 6 characters long. One or
more spaces follow. Next is the OPCODE. This is the actual instruction to be
performed followed by one or more spaces. Next are one or more operands or data
for the instruction to operate on followed by one or more spaces. Finally is
an optional comment which may extend to column 80. Each time we use a new
instruction I will fully explain it.
Addressing Modes.
There are five general addressing modes and one special addressing mode used
for assembler instructions. We will examine each one in detail as we encounter
them in a program. There is one type of addressing we need to look at now. We
are going to be operating on individual bits, bytes, and words of memory.
Think of the computers memory as a series of consecutive small pieces of memory
laid out end to end. We can address any single byte of memory by hanging a
label on it but frequently we must address a byte of memory some distance from
that label. Think of it like an array. To get to the 5th byte from the label
we could say LABEL+4. We used 4 instead of 5 because we must start counting
from 0. Think of it like OPTION BASE 0 in BASIC. Lot's more on this later.
First Program. I strongly recommend you enter the program manually by typing
it in instead of just cleaning it up using TI-Writer or Editor/Assembler. The
only way to gain experience programming is to practice.
I've place the program separately in DL3 to meke it easier to read. It's name
is PRO1.ASM.
Program explanation . These comments supplement the comments contained in the
program itself. Any statement with an * in column 1 is a comment and you may
enter anything else on that line. One fairly unique thing about the 9900
microprocessor in the TI-99 is the ability to designate your own workspace
registers anyplace in memory or more than one set at a time. Think of
registers as 32 consecutive bytes of memory that are used as your scratch paper
for calculations. Thirty-two bytes is of course 16 words of memory. Because
this is a 16 bit (1 word) machine (something many of your friends can't brag
about) that gives us 16 registers to use for our computations. We place an R
in front of the number to designate that we are refering to a register. For
example, R0 is register zero and R15 is register fifteen (really the 16th word
of memory because we started counting with zero.) Here's the detailed
explanation of the program:
DEF START
DEFines the entry point of the program so the computer may find it. Places the
name START in the Reference/Definition table. More on this next time.
REF VSBW,VMBW
REFerence refers to console routine the program will use. In the advanced
tutorials we'll create our own utilities.
WSREG BSS >20
WSREG is the label we decided on for our workspace registers. Could have been
any label 1 to 6 characters long. Block Starting Symbol (BSS) sets aside a
block of memory, unititialized for use as our workspace. >20 means set aside
>20 or 32 bytes (16 words) for R0 to R15.
X DATA 10
Initializes one word of memory to 10 (0010). Hangs the label X on that word.
START LWPI WSREG
Load Workspace Register Immediate (LWPI). Tells the computer to use the 32
bytes of memory for our workspace which begin at WSREG. START is the entry
point (beginning) of our program.
Logic for clear routine. Writes the space character >20 or 32 to the screen 768
times to the screen to clear it. R0 is the counter. R1 contains the space
character. We increment R0 to point to the next screen location and check it
against 767 to insure we haven't gone too far.
CLR R0
CLeaRs the contents of R0 to zero.
LI R1,>2000
Load Immediate R1 with >2000.
LOOP BLWP @VSBW
Branch and Link Workspace Pointer to the Video Single Byte Write Routine.
Brances to the console routine for writing single bytes of information to the
screen. R0 always contains the address on the screen to write to. Briefly,
there are 768 screen positions 24 rows X 32 Columns=768. This routine writes to
VDP RAM in the screen image table (SIT) which is 768 bytes long. Any ASCII
value you write to the SIT is displayed on the screen. For example to display
the number 3 at row one column one, R0 would have 0 in it (because we begin
counting at 0) and R1 would contain >3300 or 5100 in it. Note the number to be
written is in the left byte of the word. The VSBW routine always writes on the
Most Significant Byte and disregards the LSB. Here's the easy way to remember
it. R0 always contains the address in VDP RAM. R1 always contains the address
or data in CPU RAM.
INC R0
INCrement R0 by one. Add one to the contents of R0.
CI R0,767
Compare Immediate whats in R0 to 767.
JLE LOOP
Jump Less than or EQUAL to the label LOOP. IF R0<=767 THEN GOTO LOOP.
Logic for the addition routine. We add the two number together. Because only
ASCII numbers may be displayed on the screen we must add >30 to each byte
before we display it. In this case our number is 37. We must place a 3 and 7
on the screen. To do this we divide 37 by 10 resulting in a quotient of 3 and
remainder of 7. We add >30 to the 7 to make ASCII >37. We move this value to
the right most byte of our ANS word. We then divide 3 (old quotient) by 10
resulting in 0 quotient and 3 remainder. We again mask up by >30 and shift it
left 8 bits (1 byte) in the register. We then move this byte to the left (MSB)
of ANS. ANS looks like >3337 when we're finished.
A @Y,@X
Adds two words of memory. Places the sum in the second operand. May also use
registers (eg. A R0,R1). Adds whats at the word of memory with label Y to whats
at the word of memory label X.
DIV @TEN,R5
DIVides uses two registers. In this case R5 and R6. Divides whats in R6 by
whats at TEN or 10. The quotient is placed in R5 and the remainder at R6. That
is why we clear R5 before we divide.
MOV R6,@ANS
MOVe the contents of R6 to whats at the label ANS.
SLA R6,8
Shift Left Arithmetic. Shift the contents of R6 left 8 bits (1 byte) to the
MSB. Fills the shifted out positions with 0.
MOVB R6,@ANS
MOVe Byte moves the Most Significant Byte (MSB) or leftmost to the word at ANS
without disturbing the LSB of ANS.
Logic for display on the screen routine. R0 contains the position on the
screen to display the answer. Found by SCREEN ADDRESS=((ROW-1)*32)+(COLUMN-1).
In this case 366. R1 contains the address of the beginning of the data to write
to the screen. In this case R1 contains the address of ANS. R2 contains the
number of bytes to write beginning at the VDP address in R0 and the CPU address
in R1.
JMP $
Instructs the computer to JuMP to the current location of the program counter.
Same as 100 GOTO 100. This locks up the computer so you may see the result. If
you want to see how quickly the computer executes place an * in column 1 in
front of this instruction and reassemble.
Logic for the Return to the Calling Routine. Clears the GPL status byte at
>837C. Much more on this important byte later. Loads the workspace pointer back
to the GPL workspace and branches to the routine at >0070. END is a directive
to inform the assembler there are no more instructions.
How to Assemble.
If you have the Molesworth book refer to page 42 or page 30-36 in the
Editor/Assembler manual. Here's a brief step by step.
1. Select EDITOR/ASSEMBLER from the main menu. Place your editor assembler
disk A in drive 1.
2. Select 1-EDIT from the E/A menu.
3. Select 2-EDIT from the EDIT menu.
4. Enter your program just as shown. You may omit any comments if you desire.
5. Press FCTN ESCAPE twice to return to the EDIT title screen.
6. Select 3-SAVE. Answer Y to the VAR/80 prompt. Enter your source file name
such as DSK2.SOURCE. If you only have one drive place another disk in drive one
first and use DSK1 instead of DSK2.
7. Press FCTN ESCAPE to return to E/A title screen.
8. Select 2-ASSEMBLE. Answer Y to the load assembler question. Insure the E/A
disk A is in drive 1.
9. At the SOURCE FILE NAME enter the same file name you used in 6 above. ie.
DSK2.SOURCE, press enter.
10. At the OBJECT FILE NAME enter DSK2.OBJECT and press enter.
11. Press enter at the LIST FILE NAME. More on this feature next time.
12. At the OPTIONS prompt enter R. Press enter. R means you used R in front of
your register numbers in the source code. You may also enter CLST. C is
compressed object code (will not load from X/B loader). L is a source listing
if you entered a LIST FILE NAME at the prompt. S prints the symbols and
registers used in the program on your source list. T prints the full text
string in your source listing. More on these features later. Assembler
executing will appear followed by 0000 errors (you hope). Press enter.
13. Press 3-LOAD AND RUN.
14. At the FILE NAME prompt enter your OBJECT file name ie. DSK2.OBJECT. Press
enter. Press enter again to get to the PROGRAM NAME prompt.
15. This is the name we DEF in our program in this case START.
16 Your program will execute.
SUMMARY.
I realize this has been long but there has been much to cover to get started.
Don't get discouraged. We'll go at this together. I strongly recommend you
study these references in your Editor-Assembler manual and experiment on your
own. Until next time, "ASSEMBLER EXECUTING".
Page 20-36 Using the Editor-Assembler Cartridge.
Page 39 Sec 3.1 Registers
Page 46-48 Source Statement Format
Page 53 Predefined Symbols. ($)
Page 57-62 Sec 4.1.1, 4.1.4, 4.2, 4.4 Addressing.
Page 80 Add Instruction
Page 85 Add Immediate
Page 88 Divide
Page 90 Increment
Page 107 Branch
Page 115 Jump Less Than or Equal.
Page 143 Compare Immediate
Page 163 Load Immediate
Page 165 Load Workspace Pointer Immediate
Page 166 Move Word
Page 168 Move Byte
Page 200 Shift Left Arithmetic
Page 212 Block Starting Symbol
Page 225 Data
Page 227 DEF
Page 228 REF
Page 248 VSBW,VMBW
Page 329-330 Graphics Mode Tables
Page 394-396 Numbering Systems
Page 428-429 ASCII character set
Page 442 Other Returns
Download complete. Turn off Capture File.