Operands =
the values used in a
computer instruction/operation
A M68000 instruction
can have:
No operands
1 operand
2 operands
Some CPUs has
machine instructions that takes
3 operands
"Kinds" of operands
All computer instructions
uses the following 3 "kinds" of
operands:
Constant operands (or "constants"):
Constant =
a fixed (constant) value
E.g.: 4,
-6,
'A'
Register operands:
Register operand =
the value stored in
a register of the CPU
Memory operands:
Memory operand =
a value stored in
the computer memory (= RAM)
The data type of operands used by an instruction
Machine instruction and data type:
Each machine instruction
will only operate on
operands of
specific data type (or size):
There are instructions that
only operate on
byte (integer) typed data
There are instructions that
only operate on
short (integer) typed data
There are instructions that
only operate on
int (integer) typed data
There are instructions that
only operate on
float typed data
There are instructions that
only operate on
double typed data
And so on
Data type,
size and
encoding of operands:
The data type will
determine
the size of the
data (= # bytes)
and the
encoding method used:
A byte typed data/value
is always an
8 bits (or 1 byte)binary number using
2's complement encoding
to represent its value
A short typed data/value
is always an
16 bits (or 2 bytes)binary number using
2's complement encoding
to represent its value
An int typed data/value
is always an
32 bits (or 4 bytes)binary number using
2's complement encoding
to represent its value
An float typed data/value
is always an
32 bits (or 4 bytes)binary number using
IEEE 754 code
to represent its value
An double typed data/value
is always an
64 bits (or 8 bytes)binary number using
IEEE 754 code
to represent its value
Very important fact about computer operations
Very important fact:
Computer instructions can
onlyoperate
on operands that
are the same data type !!!
In other words:
The CPU can
onlyadd:
2 bytes together, or
2 shorts or
2 ints
The CPUcannot add:
a byte and
a short, or
a byte and
a int, or
a short and
a int,
And so on.
Mixed typedoperations:
You must first
convertone of the values to the type
of the other value
first
(I.e.: perform a type conversion
operation !!!)
Then perform the
operation
(on 2 values of the
same data type !!!!)
!!!!
We will discuss mixed type
operation in
more detaillater
Data types used in this course
Data types used in
CS255 assembler programming:
We only uses
integer data types in
our assembler programs:
bytedata type:
A variable of
the bytedata type
stores a whole (number) value that
is represented by
8 bits (binary digits)
I.e.: A variable of
the bytedata type can
store a value between
−128 to 127
shortdata type:
A variable of
the shortdata type
stores a whole (number) value that
is represented by
16 bits (binary digits)
I.e.: A variable of
the shortdata type can
store a value between
−32768 to 32767
intdata type:
A variable of
the intdata type
stores a whole (number) value that
is represented by
32 bits (binary digits)
I.e.: A variable of
the intdata type can
store a value between
−231 to (231−1)
Comment:
Over the many years that I have taught this course,
I found that it is commonly believed by
students that an
int typed variable
stored a decimal number
This myth is probably
caused by the program statements
like:
int i = 3; // Student sees a decimal number 3
System.out.println( i ); // Prints: 3 (a decimal number !!)
The fact is:
An int typed variable
stores a binary representation
of a whole number
Example:
int i = 3; // will store: 00000000000000000000000000000011 in i
Where are the operands found in the computer ?
There are 2 places that you
can use to store/findoperands that are used
in assembler/machine instructions:
Computer memory (RAM):
Program variables are used as
operands in
computations performed
by assembler/program instructions
Program variables are stored
in the computer memory (RAM)
Registers:
Data registers are
used as temporary storage
for program variables during
computations:
Manycomputer instructions
(such as add,
subtract, etc)
requires that
one of the
operands be
stored inside a
data register
So when you performs computations
on some variable stored in
memory:
You must copy the
value of the
variable into a
data registerfirst !!!!
Address registers are
used as base pointers
(= references)
to accesscomplexprogram variables:
Accessing an
array element requires
a complex
computation that
must use
an address register
Accessing a
linked list element requires
multiplecomplex
computation that alsomust use
an address register
So when you want to access
an array element
or linked list element stored in
memory:
You must an
address register
in the process
(We will discusshow to
accessarray elements and
linked listlater in the course)