Professional Documents
Culture Documents
QTSpim 1
QTSpim 1
QtSpim
MIPS: Introduction 2
QtSpim Program
Data Declarations
The data type must be preceded with a "." (period). The general format is:
<variableName>: .<dataType> <initialValue>
MIPS: Introduction 3
Constants
• For example, to create some constants named TRUE and
FALSE and set them to 1 and 0
respectively:
MIPS: Introduction 7
Program Code
• The code must be preceded by the ".text" directive.
• The ".globl name" and ".ent name" directives are
required to define the name of the initial or main
procedure.
MIPS: Introduction 8
Labels
MIPS: Introduction 9
Program Template
Control Instructions
• For example, an IF-THEN-ELSE statement does not
exist as the assembly-language level.
• Assembly-language provided an unconditional branch
(or jump) and a conditional branch or an IF statement
that will jump to a target label or not jump.
• The control instructions refer to unconditional and
conditional branching. Branching is required for basic
conditional statements (i.e., IF statements) and looping.
MIPS: Introduction 25
Control Instructions
Unconditional Control Instructions
MIPS: Introduction 26
Control Instructions
Conditional Control Instructions
MIPS: Introduction 27
Floating-Point Instructions
Floating-Point Register Usage
Floating-Point Instructions
Floating-Point Data Movement
MIPS: Introduction 32
Floating-Point Instructions
Integer / Floating-Point Register Data Movement
MIPS: Introduction 33
Floating-Point Instructions
Integer / Floating-Point Conversion Instructions
MIPS: Introduction 34
Floating-Point Instructions
Floating-Point Arithmetic Operations
MIPS: Introduction 35
3 – Example 3 (Sphere)
MIPS: Introduction 36
3 – Example 3 (Sphere)
MIPS: Introduction 37
3 – Example 3 (Sphere)
MIPS: Introduction 38
4 – Example 4 (Conversion)
• The following is an example program to sum an array of
integer values and compute the average as a floating-
point value. This requires conversion of 32-bit integer
values into 32-bit floating-point values.
MIPS: Introduction 39
4 – Example 4 (Conversion)
MIPS: Introduction 40
4 – Example 4 (Conversion)
MIPS: Introduction 41
Addressing Modes
Direct Mode
MIPS: Introduction 42
Addressing Modes
Immediate Mode
MIPS: Introduction 43
Addressing Modes
Indirect Mode
The ()'s are
used to denote
an indirect
memory
access. An
indirect
memory access
means the CPU
will read the
provided
address and
then go to that
address to
access the
value located
there.
MIPS: Introduction 44
Exercise
Translate each of the following pseudocode expressions
into MIPS assembly language:
(a) t3 = t4 + t5 – t6; (j) If (t0 < 0) then t7 = 0 – t0 else t7 = t0;
(b) s3 = t2 / (s1 – 54321); (k) while ( t0 != 0) { s1 = s1 + t0; t2 = t2 +
(c) sp = sp –16; 4; t0 = Mem(t2) };
(d) cout << t3; (l) for ( t1 = 99; t1 > 0; t1=t1 -1) v0 = v0 +
(e) cin >> t0; t1;
(f) a0 = &array; (m) t0 = 2147483647 - 2147483648;
(g) t8 = Mem(a0); (n) s0 = -1 * s0;
(h) Mem(a0+ 16) = 32768; (o) s1 = s1 * a0;
(i) cout << “Hello World”; (p) s2 = srt(s02 + 56) / a3;
(q) s3 = s1 - s2 / s3;
(r) s4 = s4 * 8;
(s) s5 = * s5;
© IT - TDT Computer Organisation 48
Q&A