SlideShare a Scribd company logo
1 of 17
MIPS Architecture
Data Types and Literals
Data types:
Instructions are all 32 bits
byte(8 bits), halfword (2 bytes), word (4 bytes)
a character requires 1 byte of storage
an integer requires 1 word (4 bytes) of storage
Literals:
Numbers entered as is. e.g. 4
Characters enclosed in single quotes. e.g. 'b'
Strings enclosed in double quotes. e.g. "A string"
Registers
• 32 general-purpose registers
• register preceded by $ in assembly language
instruction
two formats for addressing:
– using register number e.g. $0 through $31
– using equivalent names e.g. $t1, $sp
• special registers Lo and Hi used to store result of
multiplication and division
– not directly addressable; contents accessed with special
instruction mfhi ("move from Hi") and mflo ("move from
Lo")
• stack grows from high memory to low memory
Register
Number
Alternative
Name
Description
0 zero the value 0
1 $at (assembler temporary) reserved by the assembler
2-3 $v0 - $v1 (values) from expression evaluation and function results
4-7 $a0 - $a3
(arguments) First four parameters for subroutine.
Not preserved across procedure calls
8-15 $t0 - $t7
(temporaries) Caller saved if needed. Subroutines can use
w/out saving.
Not preserved across procedure calls
16-23 $s0 - $s7
(saved values) - Call saved.
A subroutine using one of these must save original and
restore it before exiting.
Preserved across procedure calls
24-25 $t8 - $t9
(temporaries) Caller saved if needed. Subroutines can use
w/out saving.
These are in addition to $t0 - $t7 above.
Not preserved across procedure calls.
26-27 $k0 - $k1 reserved for use by the interrupt/trap handler
28 $gp
global pointer.
Points to the middle of the 64K block of memory in the static
data segment.
29 $sp
stack pointer
Points to last location on the stack.
30 $s8/$fp
saved value / frame pointer
Preserved across procedure calls
Program Structure
• Data Declarations
– placed in section of program identified with assembler
directive .data
– declares variable names used in program; storage
allocated in main memory (RAM)
• Code
– placed in section of text identified with assembler
directive .text
– contains program code (instructions)
– starting point for code e.g.excution given label main:
– ending point of main code should use exit system call
• Comments
• anything following # on a line
# This stuff would be considered a comment
Data Declarations
• format for declarations:
name: storage_type value(s)
create storage for variable of specified type with
given name and specified value
– value(s) usually gives initial value(s);
– for storage type .space, gives number of spaces to
be allocated
• Storage_type : word, byte,half word
Examples of Data Declarations
• var1: .word 3
# create a single integer variable with initial value 3
• array1: .byte 'a','b'
# create a 2-element character array with elements initialized # to a
and b
• array2: .space 40
# allocate 40 consecutive bytes, with storage uninitialized # could be
used as a 40-element character array, or a # 10-element integer array; a
comment should indicate which!
Load / Store Instructions
• Load / Store Instructions
– Memory access only allowed with load and store
instructions
– all other instructions use register operands
• load:
lw register_destination, Memory
# copy word (4 bytes) at source RAM location to
destination register.
lb register_destination, Memory
#copy byte at source RAM location to low-order byte
of destination register,and sign extended to higher-order
bytes
Store Word
sw register_source, Memory
#store word in source register into RAM
destination
sb register_source, Memory
#store byte (low-order) in source register into
RAM destination
load Immediate
li register_destination, value
#load immediate value into destination register
Example of Data Transfer Instruction
.data
var1: .word 23
.text
__start:
lw $t0, var1
li $t1, 5
sw $t1, var1
Arithmetic Instructions
• most use 3 operands
• all operands are registers; no RAM or indirect addressing
• operand size is word (4 bytes)
• add $t0,$t1,$t2 # $t0 = $t1 + $t2
add as signed (2's complement) integers
• sub $t2,$t3,$t4 # $t2 = $t3 - $t4
• addi $t2,$t3, 5 # $t2 = $t3 + 5 "add immediate" (no
sub immediate)
• addu $t1,$t6,$t7 # $t1 = $t6 + $t7; add as unsigned
integers
• subu $t1,$t6,$t7 # $t1 = $t6 + $t7; subtract as unsigned
integers
Control Structures
• Branches
• comparison for conditional branches is built into
instruction
• b target # unconditional branch to program label target
• beq $t0,$t1,target # branch to target if $t0 = $t1
• blt $t0,$t1,target # branch to target if $t0 < $t1
• ble $t0,$t1,target # branch to target if $t0 <= $t1
• bgt $t0,$t1,target # branch to target if $t0 > $t1
• bge $t0,$t1,target # branch to target if $t0 >= $t1
• bne $t0,$t1,target # branch to target if $t0 <> $t1
• j target
# unconditional jump to program label target
• jr $t3
# jump to address contained in $t3 ("jump
register")
MIPS Architecture

More Related Content

What's hot

Computer architecture register transfer languages rtl
Computer architecture register transfer languages rtlComputer architecture register transfer languages rtl
Computer architecture register transfer languages rtlMazin Alwaaly
 
Computer instruction
Computer instructionComputer instruction
Computer instructionSanjeev Patel
 
Computer organization &amp; architecture chapter-1
Computer organization &amp; architecture chapter-1Computer organization &amp; architecture chapter-1
Computer organization &amp; architecture chapter-1Shah Rukh Rayaz
 
RISC (reduced instruction set computer)
RISC (reduced instruction set computer)RISC (reduced instruction set computer)
RISC (reduced instruction set computer)LokmanArman
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Gaditek
 
x86 architecture
x86 architecturex86 architecture
x86 architecturei i
 
MIPS Assembly Language I
MIPS Assembly Language IMIPS Assembly Language I
MIPS Assembly Language ILiEdo
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formatsMazin Alwaaly
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference InstructionsRabin BK
 
Instruction Execution Cycle
Instruction Execution CycleInstruction Execution Cycle
Instruction Execution Cycleutsav_shah
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle pptsheetal singh
 

What's hot (20)

Computer architecture register transfer languages rtl
Computer architecture register transfer languages rtlComputer architecture register transfer languages rtl
Computer architecture register transfer languages rtl
 
Computer instruction
Computer instructionComputer instruction
Computer instruction
 
Computer organization &amp; architecture chapter-1
Computer organization &amp; architecture chapter-1Computer organization &amp; architecture chapter-1
Computer organization &amp; architecture chapter-1
 
RISC (reduced instruction set computer)
RISC (reduced instruction set computer)RISC (reduced instruction set computer)
RISC (reduced instruction set computer)
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
 
x86 architecture
x86 architecturex86 architecture
x86 architecture
 
MIPS Assembly Language I
MIPS Assembly Language IMIPS Assembly Language I
MIPS Assembly Language I
 
Co notes3 sem
Co notes3 semCo notes3 sem
Co notes3 sem
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formats
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference Instructions
 
Instruction cycle
Instruction cycleInstruction cycle
Instruction cycle
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference Instructions
 
Instruction Execution Cycle
Instruction Execution CycleInstruction Execution Cycle
Instruction Execution Cycle
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
 
Lecture 3 instruction set
Lecture 3  instruction setLecture 3  instruction set
Lecture 3 instruction set
 
CO by Rakesh Roshan
CO by Rakesh RoshanCO by Rakesh Roshan
CO by Rakesh Roshan
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instruction codes
Instruction codesInstruction codes
Instruction codes
 
Instruction format
Instruction formatInstruction format
Instruction format
 
1.1.2 HEXADECIMAL
1.1.2 HEXADECIMAL1.1.2 HEXADECIMAL
1.1.2 HEXADECIMAL
 

Similar to MIPS Architecture

Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12Rabia Khalid
 
Module 1-ppt System programming
Module 1-ppt System programmingModule 1-ppt System programming
Module 1-ppt System programmingvishnu sankar
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTKauserJahan6
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingRKarthickCSEKIOT
 
(246431835) instruction set principles (2) (1)
(246431835) instruction set principles (2) (1)(246431835) instruction set principles (2) (1)
(246431835) instruction set principles (2) (1)Alveena Saleem
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variablesyarkhosh
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
 
Set Similarity Search using a Distributed Prefix Tree Index
Set Similarity Search using a Distributed Prefix Tree IndexSet Similarity Search using a Distributed Prefix Tree Index
Set Similarity Search using a Distributed Prefix Tree IndexHPCC Systems
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 

Similar to MIPS Architecture (20)

Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12
 
Module 1-ppt System programming
Module 1-ppt System programmingModule 1-ppt System programming
Module 1-ppt System programming
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
 
C programming language
C programming languageC programming language
C programming language
 
Assembler
AssemblerAssembler
Assembler
 
(246431835) instruction set principles (2) (1)
(246431835) instruction set principles (2) (1)(246431835) instruction set principles (2) (1)
(246431835) instruction set principles (2) (1)
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variables
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
 
Theperlreview
TheperlreviewTheperlreview
Theperlreview
 
Wk1to4
Wk1to4Wk1to4
Wk1to4
 
test
testtest
test
 
C
CC
C
 
Theory1&amp;2
Theory1&amp;2Theory1&amp;2
Theory1&amp;2
 
Co&amp;al lecture-05
Co&amp;al lecture-05Co&amp;al lecture-05
Co&amp;al lecture-05
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Set Similarity Search using a Distributed Prefix Tree Index
Set Similarity Search using a Distributed Prefix Tree IndexSet Similarity Search using a Distributed Prefix Tree Index
Set Similarity Search using a Distributed Prefix Tree Index
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 

Recently uploaded

Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

MIPS Architecture

  • 2. Data Types and Literals Data types: Instructions are all 32 bits byte(8 bits), halfword (2 bytes), word (4 bytes) a character requires 1 byte of storage an integer requires 1 word (4 bytes) of storage Literals: Numbers entered as is. e.g. 4 Characters enclosed in single quotes. e.g. 'b' Strings enclosed in double quotes. e.g. "A string"
  • 3. Registers • 32 general-purpose registers • register preceded by $ in assembly language instruction two formats for addressing: – using register number e.g. $0 through $31 – using equivalent names e.g. $t1, $sp • special registers Lo and Hi used to store result of multiplication and division – not directly addressable; contents accessed with special instruction mfhi ("move from Hi") and mflo ("move from Lo") • stack grows from high memory to low memory
  • 4. Register Number Alternative Name Description 0 zero the value 0 1 $at (assembler temporary) reserved by the assembler 2-3 $v0 - $v1 (values) from expression evaluation and function results 4-7 $a0 - $a3 (arguments) First four parameters for subroutine. Not preserved across procedure calls 8-15 $t0 - $t7 (temporaries) Caller saved if needed. Subroutines can use w/out saving. Not preserved across procedure calls
  • 5. 16-23 $s0 - $s7 (saved values) - Call saved. A subroutine using one of these must save original and restore it before exiting. Preserved across procedure calls 24-25 $t8 - $t9 (temporaries) Caller saved if needed. Subroutines can use w/out saving. These are in addition to $t0 - $t7 above. Not preserved across procedure calls. 26-27 $k0 - $k1 reserved for use by the interrupt/trap handler 28 $gp global pointer. Points to the middle of the 64K block of memory in the static data segment. 29 $sp stack pointer Points to last location on the stack. 30 $s8/$fp saved value / frame pointer Preserved across procedure calls
  • 6. Program Structure • Data Declarations – placed in section of program identified with assembler directive .data – declares variable names used in program; storage allocated in main memory (RAM) • Code – placed in section of text identified with assembler directive .text – contains program code (instructions) – starting point for code e.g.excution given label main: – ending point of main code should use exit system call
  • 7. • Comments • anything following # on a line # This stuff would be considered a comment
  • 8. Data Declarations • format for declarations: name: storage_type value(s) create storage for variable of specified type with given name and specified value – value(s) usually gives initial value(s); – for storage type .space, gives number of spaces to be allocated • Storage_type : word, byte,half word
  • 9. Examples of Data Declarations • var1: .word 3 # create a single integer variable with initial value 3 • array1: .byte 'a','b' # create a 2-element character array with elements initialized # to a and b • array2: .space 40 # allocate 40 consecutive bytes, with storage uninitialized # could be used as a 40-element character array, or a # 10-element integer array; a comment should indicate which!
  • 10. Load / Store Instructions • Load / Store Instructions – Memory access only allowed with load and store instructions – all other instructions use register operands • load: lw register_destination, Memory # copy word (4 bytes) at source RAM location to destination register. lb register_destination, Memory #copy byte at source RAM location to low-order byte of destination register,and sign extended to higher-order bytes
  • 11. Store Word sw register_source, Memory #store word in source register into RAM destination sb register_source, Memory #store byte (low-order) in source register into RAM destination
  • 12. load Immediate li register_destination, value #load immediate value into destination register
  • 13. Example of Data Transfer Instruction .data var1: .word 23 .text __start: lw $t0, var1 li $t1, 5 sw $t1, var1
  • 14. Arithmetic Instructions • most use 3 operands • all operands are registers; no RAM or indirect addressing • operand size is word (4 bytes) • add $t0,$t1,$t2 # $t0 = $t1 + $t2 add as signed (2's complement) integers • sub $t2,$t3,$t4 # $t2 = $t3 - $t4 • addi $t2,$t3, 5 # $t2 = $t3 + 5 "add immediate" (no sub immediate) • addu $t1,$t6,$t7 # $t1 = $t6 + $t7; add as unsigned integers • subu $t1,$t6,$t7 # $t1 = $t6 + $t7; subtract as unsigned integers
  • 15. Control Structures • Branches • comparison for conditional branches is built into instruction • b target # unconditional branch to program label target • beq $t0,$t1,target # branch to target if $t0 = $t1 • blt $t0,$t1,target # branch to target if $t0 < $t1 • ble $t0,$t1,target # branch to target if $t0 <= $t1 • bgt $t0,$t1,target # branch to target if $t0 > $t1 • bge $t0,$t1,target # branch to target if $t0 >= $t1 • bne $t0,$t1,target # branch to target if $t0 <> $t1
  • 16. • j target # unconditional jump to program label target • jr $t3 # jump to address contained in $t3 ("jump register")