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

Post on 20-Oct-2019

9 views 0 download

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

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

Introduction intoMIPS Assembly Language

Dr. Petros Panayi

From Appendix Aof

Computer Organization and Design

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

MIPS Arithmetic - Registers

Σελ. 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.

Σελ. 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

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

PCSPIM System Calls = Operating-System-like services

$v0

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

MIPS Arithmetic – Addition

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

MIPS Arithmetic – Logic Operations

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

MIPS Arithmetic – Multiplication

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

MIPS Arithmetic - Division

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

MIPS Shifting

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

MIPS Loading Data

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

MIPS Loading Data

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

MIPS Moving Data Between Registers

Σελ. 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

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

MIPS Branching

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

MIPS Branching

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

MIPS Jump

PC = target*4 or target <<2

The last two are used mainly in procedures call

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

Άσκηση 1:

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

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

MIPS - Procedures

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

MIPS – Loop Example 1/2

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

MIPS – Loop Example 2/2

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

MIPS - Procedures

Σελ. 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.

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

MIPS Arithmetic