Docsity
Docsity

Prüfungen vorbereiten
Prüfungen vorbereiten

Besser lernen dank der zahlreichen Ressourcen auf Docsity


Download-Punkte bekommen.
Download-Punkte bekommen.

Heimse Punkte ein, indem du anderen Studierenden hilfst oder erwirb Punkte mit einem Premium-Abo


Leitfäden und Tipps
Leitfäden und Tipps

Einführung in MIPS Programmierung, Skripte von Rechnerarchitektur

Einführung in MIPS Programmierung Mit Übungsaufgaben und Zusammenfassende Erklärungen für ein besseres Verständnis der Zusammenhänge

Art: Skripte

2021/2022

Hochgeladen am 05.05.2023

joel-fotso-simo
joel-fotso-simo 🇩🇪

1 dokument

1 / 79

Toggle sidebar

Diese Seite wird in der Vorschau nicht angezeigt

Lass dir nichts Wichtiges entgehen!

bg1
Fundamentals of Computer Systems
The MIPS Instruction Set
Stephen A. Edwards
and
Martha A. Kim
Columbia University
Spring 2012
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f

Unvollständige Textvorschau

Nur auf Docsity: Lade Einführung in MIPS Programmierung und mehr Skripte als PDF für Rechnerarchitektur herunter!

Fundamentals of Computer Systems

The MIPS Instruction Set

Stephen A. Edwards and Martha A. Kim

Columbia University

Spring 2012

Instruction Set Architectures MIPS The GCD Algorithm MIPS Registers Types of Instructions Computational Load and Store Jump and Branch Other Instruction Encoding Register-type Immediate-type Jump-type Assembler Pseudoinstructions

Higher-Level Constructs Expressions Conditionals Loops Arrays Strings & Hello World ASCII Subroutines Towers of Hanoi Example Factorial Example Memory Layout Differences in Other ISAs

Machine, Assembly, and C Code

00010000100001010000000000000111 00000000101001000001000000101010 00010100010000000000000000000011 00000000101001000010100000100011 00000100000000011111111111111100 00000000100001010010000000100011 00000100000000011111111111111010 00000000000001000001000000100001 00000011111000000000000000001000

beq $4, $5, 28 slt $2, $5, $ bne $2, $0, 12 subu $5, $5, $ bgez $0 - subu $4, $4, $ bgez $0 - addu $2, $0, $ jr $

Machine, Assembly, and C Code

00010000100001010000000000000111 00000000101001000001000000101010 00010100010000000000000000000011 00000000101001000010100000100011 00000100000000011111111111111100 00000000100001010010000000100011 00000100000000011111111111111010 00000000000001000001000000100001 00000011111000000000000000001000

beq $4, $5, 28 slt $2, $5, $ bne $2, $0, 12 subu $5, $5, $ bgez $0 - subu $4, $4, $ bgez $0 - addu $2, $0, $ jr $

gcd: beq $a0, $a1, .L slt $v0, $a1, $a bne $v0, $zero, .L subu $a1, $a1, $a b gcd .L1: subu $a0, $a0, $a b gcd .L2: move $v0, $a j $ra

Algorithms

al · go · rithm

a procedure for solving a mathematical problem (as of finding the greatest common divisor) in a finite number of steps that frequently involves repetition of an operation; broadly : a step-by-step procedure for solving a problem or accomplishing some end especially by a computer

Merriam-Webster

The Stored-Program Computer

John von Neumann, First Draft of a Report on the EDVAC ,

“Since the device is primarily a computer, it will have to perform the elementary operations of arithmetics most frequently. [...] It is therefore reasonable that it should contain specialized organs for just these operations.

“If the device is to be [...] as nearly as possible all purpose, then a distinction must be made between the specific instructions given for and defining a particular problem, and the general control organs which see to it that these instructions [...] are carried out. The former must be stored in some way [...] the latter are represented by definite operating parts of the device. “Any device which is to carry out long and complicated sequences of operations (specifically of calculations) must have a considerable memory.

Architecture vs. Microarchitecture

Architecture: The interface the hardware presents to the software

Microarchitecture: The detailed implemention of the architecture

MIPS

M icroprocessor without I nterlocked P ipeline S tages MIPS developed at Stanford by Hennessey et al. MIPS Computer Systems founded 1984. SGI acquired MIPS in 1992; spun it out in 1998 as MIPS Technologies.

The GCD Algorithm

Euclid, Elements , 300 BC.

The greatest common divisor of two numbers does not change if the smaller is subtracted from the larger.

  1. Call the two numbers a and b
  2. If a and b are equal, stop: a is the greatest common divisor
  3. Subtract the smaller from the larger
  4. Repeat steps 2–

The GCD Algorithm

Let’s be a little more explicit:

  1. Call the two numbers a and b
  2. If a equals b , go to step 8
  3. if a is less than b , go to step 6
  4. Subtract b from a a > b here
  5. Go to step 2
  6. Subtract a from b a < b here
  7. Go to step 2
  8. Declare a the greatest common divisor
  9. Go back to doing whatever you were doing before

Euclid’s Algorithm in MIPS Assembly

gcd: beq $a0, $a1, .L2 # if a = b, go to exit sgt $v0, $a1, $a0 # Is b > a? bne $v0, $zero, .L1 # Yes, goto .L

subu $a0, $a0, $a1 # Subtract b from a (b < a) b gcd # and repeat

.L1: subu $a1, $a1, $a0 # Subtract a from b (a < b) b gcd # and repeat

.L2: move $v0, $a0 # return a j $ra # Return to caller Operands: Registers, etc.

Euclid’s Algorithm in MIPS Assembly

gcd: beq $a0, $a1, .L2 # if a = b, go to exit sgt $v0, $a1, $a0 # Is b > a? bne $v0, $zero, .L1 # Yes, goto .L

subu $a0, $a0, $a1 # Subtract b from a (b < a) b gcd # and repeat

.L1: subu $a1, $a1, $a0 # Subtract a from b (a < b) b gcd # and repeat

.L2: move $v0, $a0 # return a j $ra # Return to caller Labels

Euclid’s Algorithm in MIPS Assembly

gcd: beq $a0, $a1, .L2 # if a = b, go to exit sgt $v0, $a1, $a0 # Is b > a? bne $v0, $zero, .L1 # Yes, goto .L

subu $a0, $a0, $a1 # Subtract b from a (b < a) b gcd # and repeat

.L1: subu $a1, $a1, $a0 # Subtract a from b (a < b) b gcd # and repeat

.L2: move $v0, $a0 # return a j $ra # Return to caller Arithmetic Instructions

Euclid’s Algorithm in MIPS Assembly

gcd: beq $a0, $a1, .L2 # if a = b, go to exit sgt $v0, $a1, $a0 # Is b > a? bne $v0, $zero, .L1 # Yes, goto .L

subu $a0, $a0, $a1 # Subtract b from a (b < a) b gcd # and repeat

.L1: subu $a1, $a1, $a0 # Subtract a from b (a < b) b gcd # and repeat

.L2: move $v0, $a0 # return a j $ra # Return to caller Control-transfer instructions