Hi! Welcome to my guide to CASL/COMET II Assembly Laguage. The main reason why you'll study this is because you want to pass the Japanese Information Technology Standards Examination (JITSE)/ Philippine National Information Technology Standards (PhilNITS). Well, this guide can help you know the fundamentals. If you have difficulties learning it (after reading), I suggest that you simulate it. However, this thing requires you to have JAVA installed in your computer. If you have good background in Assembler programming, you'll easily grasp the idea as this is common problem in assembly language programming.
OK! Let's begin. But first, read the pre-requisite of this guide. I want you to study about them, I won't be spoon-feeding the ingredients. I'll just give you an insight to the fundamentals. Please study:
Number systems
Bits, Nibbles, Bytes, Words, Double Words
Bit Shifts & Number Compliments
Program Logic Formulation
If you're familiar with it already, then OK. If not, I suggest you study about it.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BASIC CASL/COMET
By Richie Ryan R. Reyes, E.C.E. (Electronics and Communications
Engineer)
ECE#0033195 / FE01-0084
Registers
Well, as this is just a guide I'll describe register in a way that you'll get the idea easily. In my own words, Registers are fixed variables of fixed size. They are intact, and need not to be assigned. In CASL/COMET, these registers are 1-word length. 1 word = 16 bits. Think of them as variables already defined as 16 bits length. Please refer to my example.
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Bits from 0-7 are lower ordered bit and bits from 8-15 are higher order bits.
The 15th bit is the sign bit. This determines if the number is positive or
negative (as per IEEE standards).
Now, these registers can contain any combinations of bits, as assigned or as modified by an instruction. Let's take this example (now you'll see why you need to be familiar with the number systems).
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 |
We then calculate it, having a value of 2^6 + 2^5 + 2^3 + 2^0.
We can represent the contents of the register in different number systems.
In binary, the contents of the register will be 0000000001101001
In decimal, the contents of the register will be 105
In octal, the contents of the register will be 151
In hexa-decimal (or hex), the contents of the register will be 0069
In CASL/COMET, we'll be using Decimal, Binary and Hexa most of the time.
These are the kinds of registers used in CASL/COMET:
GR (General Purpose Registers)
In this AL (Assembly Language), there are 8 GRs, GR0 to GR7, all of 16 bits
length.
SP (Stack Pointer)
This register keeps track of the upper tier address of the stack. SP is
16-bit length.
PR (Program Register)
This register keeps the address of the next instruction. It works the same
as the Instruction Pointer in other AL. PR is 16-bit length.
FR (Flag Register)
The flag register is like a status register. They are used when making
conditional jumps. FR consist of 3 bits: I also mentioned this on this blog
ウェブ開発者
OF (Overflow Flag)
Whenever the result of an operation exceeds the value of the register, it is
set to 1. Else it is normally 0.
SF (Sign Flag)
Whenever the result of an operation makes the 15th bit 1(or could be from
other operations) of the register, it is (SF) set to 1. Else it is normally 0.
ZF (Zero Flag)
Whenever the result of an operation zeroes all bits of the register, it is
set to 1. Else it is normally 0.
The flag register is arranged in this manner: OF-SF-ZF
Let's go to the program Instructions.
Instruction Format
Most of instructions will be in this format:
[Instruction] [Destination], [Source]
[Instruction] is the instruction you want to perform
[Destination] the destination regsiter
, is a separator for registers or numerical values.
[Source] is the source register or numerical value.
EXAMPLE:
LD GR1, GR2 (Loads the contents of GR2 to GR1)
AND GR1, GR2 (ANDs the GR1 to GR2 and stores the result in GR1)
ASSIGNING VALUE TO REGISTER
LD - load
moves the contents of source to destination.
Format:
LD Destination, Source
EXAMPLE:
Instruction | Result |
LD GR2,=1111 | GR2 =0457 |
LD GR2,=1 | GR2 =0001 |
LD GR2,=12 | GR2 =000C |
LD GR2,=16 | GR2 =0010 |
NOTE: INPUT IS DECIMAL, IT IS STORED AS THE CONVERTED NUMBER TO HEX
NOTE: IF YOU APPEND # BEFORE THE NUMBER, THE ASSEMBLER CONSIDER THE INPUT
AS HEX
NOTE: SOURCE CAN BE A REGISTER, DESTINATION CANNOT BE AN IMMEDIATE VALUE
EXAMPLE:
Instruction | Result |
LD GR2,=#8000 | GR2=8000 |
LD GR2,=#A020 | GR2=A020 |
AND
The logical Product
Format:
AND Destination, Source
Example:
LD GR2,=15
AND GR2,=1
RESULT: GR2 = 0001
LD GR2,=17
AND GR2,=16
RESULT: GR2 = 0010
NOTE: FIRST CONVERT ALL HEX TO BIN, THEN *operand* TO VALUE
THEN STORE RESULT IN GR2
LD GR2,=15 GR2 =000F
AND GR2,=1
RESULT: GR2 = 0001
REFERENCING CONTENTS
LEA/LAD
EXAMPLE
LD GR1,=1
LD GR2,=0
LAD GR2,0,GR1
RESULT:
GR2=0001
GR1=0001
Another Example:
LD GR1,=1
LD GR2,=0
LAD GR2,1,GR1 ;LOAD THE CONTENTS OF GR1 AND ADD 1 THEN STORE IN GR2
RESULT:
GR2=0001
GR1=0002
Conditions
CMPL/CMPA
NOTE: ALTHOUGH THIS IS USED TO COMPARE THE CONTENTS, TO RELATE IT BETTER
WHEN IT ALTER THE FLAGS, TREAT THIS AS IF YOU'RE SUBTRACTING SOURCE FROM
DESTINATION AND WILL NOT STORE THE RESULT TO THE DESTINATION.
IF IT RETURNS POSITIVE, SF = 0 AND ZF = 0;
IF IT RETURNS ZERO, SF = 0 AND ZF = 1;
IF IT RETURNS NEGATIVE, SF = 1 AND ZF = 0;
OVERFLOW FLAG (OF) IS ALWAYS ZERO, if no overflow occurred.
SHIFTING BITS:
LOGICAL SHIFT (KASAMA UNG SIGN BIT)
SLL (Shift Left Logical)
SRL (Shift Right Logical)
ARITHMETIC SHIFT (ZERO PAG GALING SA LEFTMOST
BIT, SIGN BIT FROM THE RIGHT MOST)
SLA (Shift Left Arithmetic)
SRA (Shift Right Arithmetic)
NOTE: THE VALUE OF THE LAST SHIFTED BITS WILL BE SET TO THE OVERFLOW
FLAG.
EXAMPLE:
LD GR2,=#8000
SLL GR2,1
RESULTS:
GR2 = #0000
OF = 1
HOWEVER
LD GR2,=#8000
SLL GR2,2
RESULTS:
GR2 = #0000
OF = 0
STACK
PUSH AND POP
PUSH PLACE THE CONTENTS OF REGISTER TO STACK
PUSH 0,GR1 PUSHES VALUE OF GR1 TO STACK
PUSH 1,GR1 PUSHES VALUE OF GR1+1 TO STACK
TAKE NOTE THAT 1 IS DECIMAL AND IS CONVERTED TO BIN WHEN ADDING. SO,
IF GR1=#000E AND WE
PUSH 32,GR1
THE RESULT IS
STACK POINTER IS DECREMENTED BY ONE. (DON'T WORRY, NDI
GINAGAMIT SA FLOW UNG STACK POINTER SO YOU NEED NOT TO WORRY ABOUT TOO MUCH
ADDRESSING, UNLESS YOU'RE UP MAKING EVIL THINGS LIKE VIRUSES. HOWEVER TO BECOME
A CONTROL FREAK, MASTER THE MANIPULATION OF THINGS THAT CAN’T BE EASILY ALTERED,
LIKE INSTRUCTION POINTER OR STACK POINTER)
GR1 = #000E
(ASSUME STACK BEFORE PUSH IS @ F000.)
(STACK POINTER NOW IS AT EFFF)
VALUE OF PLACE WHERE STACK POINTER IS POINTING
= #002E
POP SIMPLY TAKE THE VALUE FROM THE PRESENT STACK POINTER TO THE REGISTER
EX
FROM THE LAST EXAMPLE, THE VALUE 002E IS BEING POINTED
POP GR2
RESULTS:
STACK = EMPTY
GR1 = 000E
GR2 = 000E
FLAGS:
ZERO FLAG : (ZF)
PAG ZERO LAHAT NG BITS, VALUE IS 1.
PAG HINDI ZERO, VALUE IS ZERO.
IN SHORT: INDICATE NYA PAG WALANG LAMAN UNG NAPAGSTOREAN.
EXAMPLE:
LD GR2,=#FFFF (Zero Flag is 0, because the contents of register is not set
to zero)
LD GR2,=0 (Zero Flag is 1, because the contents of register is set to
zero)
ANOTHER EXAMPLE:
LD GR2,=#FFFF
LD GR1,=#EEEE
LD GR1,=#EEEE
SUBL GR2,GR1
RESULT:
GR2 = #1111
GR1 = #EEEE
ZF = 0
ANOTHER EXAMPLE:
LD GR2,=#FFFF
LD GR1,=#FFFF
SUBL GR2,GR1
RESULT:
GR2 = #0000
GR1 = #FFFF
ZF = 1
OVERFLOW (OF) = 0 IF NO OVERFLOW, 1 IF Overflow OCCURRED
THESE OPERANDS ALWAYS SET OF=0 WHEN EXECUTED
LD
AND
OR
XOR
CMPA
CMPL
OPERANDS WHERE SETTING IS PERFORMED
ADDA
SUBA
ADDL
SUBL
VALUE BEFORE EXECUTION IS STORED:
ST
LAD/LEA
JUMPS
PUSH
POP
CALL
RET
OF LESS IMPORTANCE (NOT USED IN FUNDAMENTAL IT EXAM DUE TO COMPLICATION)
SVC (CHECKING FOR ERROR CONTROL)
NOP (END OF OPERATION)
Stack Pointer
SP - stores the address on the top of the stack INITIALLY AT F000
push (sp ) -L 1
F000
0001
----
EFFF
POP (SP) +L 1
EFFF
0001
----
F000
DS (Define Storage)
DS DECLARES A VARIABLE OF FIXED WORD LENGTH, ST ASSIGNS VALUE TO A DECLARED
DS
EXAMPLE
GR1=#1111
LD GR2,=#1112
ST GR2,HULA
ADD GR1,HULA
DS HULA 1
DC – EQUIVALENT OF DEFINE SA ASSEMBLER
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EOF
Well, that's it. I hope you're on your way to learning CASL/COMET. The key to
mastering CASL/COMET assembly is LOTS of practice!
Don't worry if you don't understand half of the stuff I talked about here. Put
this thing aside and just make lots and lots
of little programs. If they don't work, debug them, even if that takes you all
night or longer. Than come back to this. And don't bother trying to find help.
There are only very few people who know CASL/COMET assembly, and if you can
figure it out yourself you learn more.
Remember, you don't have to start coding something big, as long as you code
_something_! And CASL/COMET so far is only used in the examinations. I doubt if
it would be really used in actual programming or commissioning. Don't expect to
learn everything in this tutorial within a few days, I would say that if you can
do it in 4 months or so you are doing great.
Quote:
The only good is knowledge and the only evil ignorance. - Socrates