Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction...

24
Σελ. 1 Δρ. Πέτρος Παναγή Introduction into MIPS Assembly Language Dr. Petros Panayi From Appendix A of Computer Organization and Design

Transcript of Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction...

Page 1: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 1Δρ. Πέτρος Παναγή

Introduction intoMIPS Assembly Language

Dr. Petros Panayi

From Appendix Aof

Computer Organization and Design

Page 2: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 2Δρ. Πέτρος Παναγή

MIPS Arithmetic - Registers

Page 3: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 3Δρ. Πέτρος Παναγή

MIPS Arithmetic – Instruction Format

pseudoinstructions, appear as real instructions in assembly language programs. The hardware, however, knows nothing about pseudoinstructions, so the assembler translates them into equivalent sequences of actual machine instructions.

Page 4: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 4Δρ. Πέτρος Παναγή

Program sample#############################################################################Program Name : Read three integers from the user and check there status#Programmer : Petros Panayi Stud. ID:000000#Date Last Modif.: 7 Sep 2006############################################################################## Comments: This program requests three integers from the user and # prints on the console if they are positive, negative or zero#############################################################################

.data # data segmentquestion: .asciiz "Please enter an Integer value:"confimation_msg: .asciiz "Your values are "comma: .asciiz ", "##############################################################################

.text # text segment

.globl mainmain:

# διάβασε τρεις ακεραίους στο $t0, $t1 και $t2la $a0, question # Μήνυμα για είσοδο ακεραίου

li $v0, 4 # κώδικας συστήματος για τύπωση συμβολοσειράς...

# 7. Έξοδοςli $v0, 10 # Κλίση συστήματος εξόδου(exit system call)syscall

Page 5: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 5Δρ. Πέτρος Παναγή

PCSPIM System Calls = Operating-System-like services

$v0

Page 6: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 6Δρ. Πέτρος Παναγή

MIPS Arithmetic – Addition

Page 7: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 7Δρ. Πέτρος Παναγή

MIPS Arithmetic – Logic Operations

Page 8: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 8Δρ. Πέτρος Παναγή

MIPS Arithmetic – Multiplication

Page 9: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 9Δρ. Πέτρος Παναγή

MIPS Arithmetic - Division

Page 10: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 10Δρ. Πέτρος Παναγή

MIPS Shifting

Page 11: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 11Δρ. Πέτρος Παναγή

MIPS Loading Data

Page 12: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 12Δρ. Πέτρος Παναγή

MIPS Loading Data

Page 13: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 13Δρ. Πέτρος Παναγή

MIPS Moving Data Between Registers

Page 14: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 14Δρ. Πέτρος Παναγή

MIPS - Memory OrganizationBytes are nice, but most data items use larger "words"For MIPS, a word is 32 bits or 4 bytes.

232 bytes with byte addresses from 0 to 232-1230 words with byte addresses 0, 4, 8, ... 232-4Words are aligned

i.e., what are the least 2 significant bits of a word address?

048

12...

32 bits of data

32 bits of data

32 bits of data

32 bits of data

Registers hold 32 bits of data

Page 15: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 15Δρ. Πέτρος Παναγή

MIPS Branching

Page 16: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 16Δρ. Πέτρος Παναγή

MIPS Branching

Page 17: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 17Δρ. Πέτρος Παναγή

MIPS Jump

PC = target*4 or target <<2

The last two are used mainly in procedures call

Page 18: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 18Δρ. Πέτρος Παναγή

Άσκηση 1:

• Γράψετε ένα απλό πρόγραμμα που να διαβάζει από το πληκτρολόγιο ένα ακέραιο αριθμό Ν και να εκτυπώνει στην οθόνη το όνομα σας Ν φορές.

Page 19: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 19Δρ. Πέτρος Παναγή

MIPS - Procedures

Page 20: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 20Δρ. Πέτρος Παναγή

MIPS – Loop Example 1/2

Page 21: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 21Δρ. Πέτρος Παναγή

MIPS – Loop Example 2/2

Page 22: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 22Δρ. Πέτρος Παναγή

MIPS - Procedures

Page 23: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 23Δρ. Πέτρος Παναγή

MIPS - ProceduresThe stack frame consists of the memory between the frame pointer ($fp), which points to the first word of the frame, and the stack pointer ($sp), which points to the last word of the frame. The stackgrows down from higher memory addresses, so the frame pointer points above the stack pointer.The executing procedure uses the frame pointer to quicklyaccess values in its stack frame.

Page 24: Introduction into MIPS Assembly Language Dr. Petros Panayi ... · MIPS Arithmetic – Instruction Format pseudoinstructions, appear as real instructions in assembly language programs.

Σελ. 24Δρ. Πέτρος Παναγή

MIPS Arithmetic