29-04-2014, 04:55 PM
Instructions: Assembly Language
Assembly Language.pdf (Size: 344.06 KB / Downloads: 706)
Instructions and Instruction set
The language to command a computer architecture is comprised of instructions and the
vocabulary of that language is called the instruction set. The only way computers can rep-
resent information is based on high or low electric signals, i.e., transistors (electric switches)
being turned on or off. Being limited to those 2 alternatives, we represent information in com-
puters using bits (binary digits), which can have one of two values: 0 or 1. So, instructions
will be stored in and read by computers as sequences of bits. This is called machine language.
To make sure we don’t need to read and write programs using bits, every instruction will also
have a ”natural language” equivalent, called the assembly language notation. For example,
in C, we can use the expression c = a + b; or, in assembly language, we can use add c, a, b
and these instructions will be represented by a sequence of bits 000000 · · · 010001001 in the
computer.
MIPS R2000
The instruction set we will explore in class is the MIPS R2000 instruction set, named
after a company that designed the widely spread MIPS (Microprocessor without Interlocked
Pipeline Stages) architecture and its corresponding instruction set. MIPS R2000 is a 32-bit
based instruction set. So, one instruction is represented by 32 bits. In what follows, we will
discuss
• Arithmetic instructions
• Data transfer instructions
• Decision making (conditional branching) instructions
• Jump (unconditional branching) instructions
Registers
In a high-level programming language such as C, we can (virtually) declare as many variables
as we want. In a low-level programming language such as MIPS R2000, the operands of
our operations have to be tied to physical locations where information can be stored. We
cannot use locations in the main physical memory for this, as such would delay the CPU
significantly (indeed, if the CPU would have to access the main memory for every operand
in every instruction, the propagation delay of electric signals on the connection between the
CPU and the memory chip would slow things down significantly). Therefore, the MIPS
architecture provides for 32 special locations, built directly into the CPU, each of them able
to store 32 bits of information (1 word), called “registers”. A small number of registers
that can be accessed easily and quickly will allow the CPU to execute instructions very fast.
As a consequence, each of the three operands of a MIPS R2000 instruction is restricted to
one of the 32 registers.
Adding a constant
The add instruction we introduced earlier adds the contents of two registers. To add a
constant to the content of a register would require to first load the constant value from
memory into some register and then execute an add instruction to add the content of two
registers. This requires two instructions, including one data transfer between memory and
a register, which can be time consuming. Using the add immediate instruction.