Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 48

COMPUTER ORGANISATION

(TỔ CHỨC MÁY TÍNH)

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

Integer Data Declarations


MIPS: Introduction 4

String Data Declarations


• The C/C++ style new line, "\n", and tab, "\t" tab are
supported within in strings.
The C/C++ style new line, "\n", and tab, "\t" tab are
supported within in strings.
message: .asciiz "Hello World\n“
MIPS: Introduction 5

Floating-Point Data Declarations


• The following declarations are used to define the floating-
point variables "pi" to a 32-bit
• Floating-point value initialized to 3.14159 and "tao" to a 64-
bit floating-point values
initialized them to 6.28318.
MIPS: Introduction 6

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

• The initial header


( “.text”, “.globl main”,
“.ent main”, and
“main:”) will be the
same for
all QtSpim programs.
MIPS: Introduction 10

Instruction Set Overview


Pseudo-Instructions vs Bare-Instructions

• As part of the MIPS architecture, the assembly language


includes a number of pseudo-instructions.
• A bare-instruction is an instructed that is executed by
the CPU.
• A pseudo-instruction is an instruction that the
assembler, or simulator, will recognize but then
convert into one or more bare-instructions. This text will
focus primarily on the pseudo-instructions.
MIPS: Introduction 11

Instruction Set Overview


Notational Conventions (operands)
MIPS: Introduction 12

Instruction Set Overview


Load and Store Data
MIPS: Introduction 13

Instruction Set Overview


Load and Store Data
MIPS: Introduction 14

Instruction Set Overview


Move Data
Another set of
move
instructions are
used to move
the contents of
registers into or
out of the
special registers,
$hi and $lo.
MIPS: Introduction 15

Instruction Set Overview


Integer Arithmetic Operations
• The arithmetic operations include addition, subtraction,
multiplication, division, remainder (remainder after
division)
• logical AND, and logical OR.
MIPS: Introduction 16

Instruction Set Overview


Integer Arithmetic Operations
MIPS: Introduction 17

Instruction Set Overview


Integer Arithmetic Operations
MIPS: Introduction 18

1- Example 1 (Integer Arithmetic)


MIPS: Introduction 19

1- Example 1 (Integer Arithmetic)


MIPS: Introduction 20

1- Example 1 (Integer Arithmetic)


MIPS: Introduction 21

1- Example 1 (Integer Arithmetic)


MIPS: Introduction 22

Instruction Set Overview


Logical Operations
MIPS: Introduction 23

Instruction Set Overview


Logical Operations
MIPS: Introduction 24

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

2 – Example 2 (Sum of Squares)


MIPS: Introduction 28

2 – Example 2 (Sum of Squares)


MIPS: Introduction 29

2 – Example 2 (Sum of Squares)


MIPS: Introduction 30

Floating-Point Instructions
Floating-Point Register Usage

• The floating-point instructions are similar to the integer


instructions, however the floating-point register must be
used with the floating-point instructions.
• When single-precision (32-bit) floating-point operation is
performed, the specified 32- bit floating-point register is
used.
• When a double-precision (64-bit) floating-point operation is
performed, two 32-bit floating-point registers are used;
the specified 32-bit floating-point register and the next
numerically sequential register is used by the
instruction.
• For example, a double-precision operation using $f12 will
use automatically $f12 and $f13.
MIPS: Introduction 31

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

5 – Example 5 (Sum of Array)


The following example computes the sum and average for an array integer
values. The values are calculated and saved into memory variables.
MIPS: Introduction 45

5 – Example 5 (Sum of Array)


MIPS: Introduction 46

5 – Example 5 (Sum of Array)


MIPS: Introduction 47

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

You might also like