SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
Computer Organization and Structure 2011



                              SPIM & MIPS
                              PROGRAMMING
                              Created and Presented by
                              Shu-Yang Lin, Hsun-Pei Wang,
                              Liang-Tsen Shen




                         Department of Information Management
                               National Taiwan University
OUTLINE

                                        Homework 2
                                        (Programming
                          MIPS –        Assignment)
                          Assembly
                SPIM –    Language
                Getting   Programming
 Introduction   Started
 to Assembly
 Language
ASSEMBLY LANGUAGE

Machine language
• Computer’s binary encoding

Assembly language
• Symbolic representation of a computer’s binary
  encoding
Assembler
• Translates assembly language into binary instructions
WHAT IS SPIM?


      MIPS32 simulator that reads and executes
      assembly language program written for
      SPIM.


      SPIM does NOT execute binary program.
REFERENCES OF SPIM

Official website of SPIM:
 http://spimsimulator.sourceforge.net/
Assemblers, Linkers, and the SPIM
 Simulator:http://pages.cs.wisc.edu/~larus/HP_Ap
 pA.pdf
MIPS Instruction
 Reference:http://www.mrc.uidaho.edu/mrc/peopl
 e/jff/digital/MIPSir.html
QTSPIM - INSTALLATION


      http://spimsimulator.sourceforge.net
                       /
QTSPIM - INSTALLATION



            Linux



           Windows


             Mac
QTSPIM - SCREENSHOT      Text Window




Register Window   Data Window




                           Console Window
MIPS ASSEMBLY LANGUAGE
                  Operation Code (Opcode)
MIPS ASSEMBLY LANGUAGE
MIPS Registers and Usage Convention
                                  n
 $zero            constant 0
 $v0, $v1         expression of a function
 $a0~$a3          argument 1~4
 $t0~$t9          temporary registers
 $s0~$s7          save registers
 $sp              stack pointer
 $fp              frame pointer
 $ra              return address
…
MIPS ASSEMBLY LANGUAGE
Some Data Types in MIPS
                      S

  .word, .half      • 32/16 bit integer

    .byte           • 8 bit integer

 .ascii, .asciiz    • string

 .double, .float    • floating point
MIPS SYSTEM CALLS

SPIM provides a small set of operating-system-
 like services through the system call instruction.
A program loads the system call code into
 register $v0 and arguments into registers $a0-
 $a3 (or $f12 for floating-point values).
System calls that return values put their results
 in register $v0 (or $f0 for floating-point results).
MIPS SYSTEM CALLS




                                         $v0




         FIGURE A.9.1 System services.
EXAMPLE – HELLO WORLD
C vs MIPS

int main()                    .data
{                             Mystr: .asciiz “Hello World¥n”
    printf(“Hello World¥”);
    return 0;                 .text
                              main:
}
                                      li $v0, 4
                                      la $a0, Mystr
                                      syscall
                                      li $v0, 10
                                      syscall
EXAMPLE – HELLO WORLD
MIPS Architecture
                e

                    .data
                    Mystr:     .asciiz “Hello World¥n”
                    Yourint:   .word 75
                    Hisarray: .word 100, 100, 100
                                .word 20 , 40 , 60
                                .word 1 , 2 , 3
                     .text
                    ……
EXAMPLE – HELLO WORLD
MIPS Architecture
                e

                    .data

                    .text
                    main:
                    # do anything you want
                    ……
                    # end of the program
                    li $v0, 10
                    syscall
MIPS SYSTEM CALLS - EXAMPLE
   Output: “the answer = 5’’

.data
    str:
    .asciiz "the   answer = "
.text
    li $v0, 4       # system call code for print_str
    la $a0, str     # address of string to print
    syscall         # print the string
    li $v0, 1       # system call code for print_int
    li $a0, 5       # integer to print
    syscall         # print it

                                                       FIGURE A.9.1 System
                                                            services.
ASSEMBLER SYNTAX
Comment (#)

 Everything from the sharp sign to the end of the line is ignored.

Identifier (A sequence of alphanumeric characters, _ , and .)

 Identifier are a sequence of alphanumeric characters, underbars (_), and
  dots (.) that do not begin with a number.

 Instruction Opcode

 Instruction opcodes are reserved words that are not valid identifiers.

 Label

 Labels are declared by putting them at the beginning of a line followed by a
  colon.

                                                                      PAGE   18
HOMEWORK
HOMEWORK

 This is an individual assignment
 Plagiarism will be heavily punished
 Write the following three programs in MIPS assembly
  language. (Must run correctly on SPIM)

       Simple Calculator
       Star Pyramid
       Pascal Triangle
DOCUMENTATION (20%)

 Detailed documentation for each program is required
 The following parts must be included:
    Your name, student ID, and email address
    Explanation of the design or the flow of each program
    What you’ve learnt from writing the programs

 Problems or difficulties you’ve encountered during writing
  the programs are nice to be included in the document
PROBLEM 1. SIMPLE CALCULATOR
 Input:                                   Sample input / output
  • Two integer x, y
     ( x, y may be positive, negative or 
     zero)
  • An operator (+, ‐, *, /)
 Requirements:
  • Print  the correct answer.
  • Can do many calculations 
     iteratively
  • If the answer of division includes a 
     remainder please print it out
  • The file name is Calculator.s
PROBLEM 2: STAR PYRAMID

 Build a pyramid using stars(*) and white spaces given
  number of rows
  Example:
                       Space                    # of rows = 5
                           4   *
                       3   *   *   *
                      2 * *    *   * *
                     1 * * *   *   * * *
                     * * * *   *   * * * *
PROBLEM 2: STAR PYRAMID
 Input:
    Number of rows of the pyramid: N
     (N>0)                                  Sample Input
 Requirements:
    Print the correct answer
      (Number of white spaces and stars
      should be correct)
    File Name: StarPyramid.s              Sample Output
 Pyramid may seemed to be a little
  inclined caused by the default display
  settings of the console window in
  QtSPIM  will NOT affect your score
PROBLEM 3: DEFORMATION OF PASCAL
TRIANGLE
F(m ,n) = F(m-1 ,n-1)+ 2*F(m-1 ,n) (F(x, 0)=1
 for all x and F(0, y)=0 for y>0)
         0   1         2    3     4        5        …
     0   1   0         0    0     0        0        …
                 *2
     1   1   1         0    0     0        0        …
                  *2        *2
     2
         1   3         1    0     0        0        …
                  *2        *2        *2
     3
         1   7         5    1     0        0        …
     4         *2            *2       *2       *2
         1   15        17   7     1        0        …
PROBLEM 3: DEFORMATION OF PASCAL
TRIANGLE
Input:
   Two integers m, n (m=1~20, n=1~99)

Requirements:
   Output F(m ,n) = F(m-1 ,n-1)+
    2*F(m-1 ,n) (F(x, 0)=1 for all x
    and F(0, y)=0 for y>0)
   Print the correct answer
   Can do many calculations iteratively

   File Name: PascalDeform.s
HOW TO EXECUTE MY PROGRAM USING QTSPIM?

Write your own assembly program, and
save it as .s file

   Simulator  Clear Registers


      Simulator Reinitialize Simulator


          Open your .s file

             Simulator  Run / Continue
SUBMISSION
 Deadline: 11:59pm, 1 Nov. (Tue.)
 You must submit at least the following files:
    Calculator.s
    StarPyramid.s
    PascalDeform.s
    (Your student id)_hwX_document.doc/pdf/docx
 Please put all your files in a directory named by your student id
  in uppercase, and then compress it into one zipped file. (e.g.
  zip/tgz …)
 You should upload your zipped file HW#2 to
  https://filestork.net/suv6oro7 before the deadline.
 The file name should be like B99xxxxxx.zip, eg. B99705099.zip
 Rename your file for multiple uploads, eg. B99705099_v2.zip,
  B99705099_v3.zip …
Remember to rename your file
SUBMISSION         for multiple uploads!!!




        https://filestork.net/suv6oro7
                                     7
GRADING GUIDELINES

              Description             For Each Problem
                                            Problem
Program runs without error messages         10%
Program executes correctly                  60%
Documentation and description of
                                            20%
the program
Implementation Detail                       10%
CONTACT INFORMATION

TA Hours @ 管五 503-C
   Shu-Yang Lin (林書漾)    Fri. 10:00~12:00
   Hsun-Pei Wang (王珣沛)   Fri. 10:00~12:00
   Liang-Tsen Shen (沈亮岑) Mon. 10:00~12:00

Contact us if you have any problem
   林書漾 young@cmlab.csie.ntu.edu.tw
   王珣沛 garfieldduck@cmlab.csie.ntu.edu.tw
   沈亮岑 olga@cmlab.csie.ntu.edu.tw
DEADLINE

2011/11/1 (Tue.)
Late submission policy: 10% off from your total
 score each day after the deadline
THANK YOU FOR
YOUR ATTENTION
Any Questions?

Mais conteúdo relacionado

Destaque

Basic MIPS implementation
Basic MIPS implementationBasic MIPS implementation
Basic MIPS implementationkavitha2009
 
Chapter 1 Microeconomics Intro
Chapter 1 Microeconomics IntroChapter 1 Microeconomics Intro
Chapter 1 Microeconomics IntroNasriQ YaziD
 
Microeconomics: Introduction and basic concepts
Microeconomics: Introduction and basic conceptsMicroeconomics: Introduction and basic concepts
Microeconomics: Introduction and basic conceptsPie GS
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkVolker Hirsch
 

Destaque (6)

Mips 64
Mips 64Mips 64
Mips 64
 
Mips Assembly
Mips AssemblyMips Assembly
Mips Assembly
 
Basic MIPS implementation
Basic MIPS implementationBasic MIPS implementation
Basic MIPS implementation
 
Chapter 1 Microeconomics Intro
Chapter 1 Microeconomics IntroChapter 1 Microeconomics Intro
Chapter 1 Microeconomics Intro
 
Microeconomics: Introduction and basic concepts
Microeconomics: Introduction and basic conceptsMicroeconomics: Introduction and basic concepts
Microeconomics: Introduction and basic concepts
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of Work
 

Semelhante a Computer Organization and Structure 2011 MIPS Assembly Programming

Chapter 8 - Computer Networking a top-down Approach 7th
Chapter 8 - Computer Networking a top-down Approach 7thChapter 8 - Computer Networking a top-down Approach 7th
Chapter 8 - Computer Networking a top-down Approach 7thAndy Juan Sarango Veliz
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answersdebarghyamukherjee60
 
MIPS_Programming.pdf
MIPS_Programming.pdfMIPS_Programming.pdf
MIPS_Programming.pdfXxUnnathxX
 
Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Davide Carboni
 
An implementation of RSA policy
An implementation of RSA policyAn implementation of RSA policy
An implementation of RSA policySM NAZMUS SALEHIN
 
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...David Walker
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...Cyber Security Alliance
 
lab-assgn-practical-file-xii-cs.pdf
lab-assgn-practical-file-xii-cs.pdflab-assgn-practical-file-xii-cs.pdf
lab-assgn-practical-file-xii-cs.pdfJeevithaG22
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Ganesan Narayanasamy
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackironSource
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schoolsDan Bowen
 
CS150 Assignment 7 Cryptography Date assigned Monday.docx
CS150 Assignment 7 Cryptography  Date assigned Monday.docxCS150 Assignment 7 Cryptography  Date assigned Monday.docx
CS150 Assignment 7 Cryptography Date assigned Monday.docxfaithxdunce63732
 
Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackTomer Zait
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityDefconRussia
 
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...Hsien-Hsin Sean Lee, Ph.D.
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network securitypatisa
 

Semelhante a Computer Organization and Structure 2011 MIPS Assembly Programming (20)

Chapter 8 - Computer Networking a top-down Approach 7th
Chapter 8 - Computer Networking a top-down Approach 7thChapter 8 - Computer Networking a top-down Approach 7th
Chapter 8 - Computer Networking a top-down Approach 7th
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
 
Chapter 8 v6.0
Chapter 8 v6.0Chapter 8 v6.0
Chapter 8 v6.0
 
MIPS_Programming.pdf
MIPS_Programming.pdfMIPS_Programming.pdf
MIPS_Programming.pdf
 
Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?
 
An implementation of RSA policy
An implementation of RSA policyAn implementation of RSA policy
An implementation of RSA policy
 
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
 
lab-assgn-practical-file-xii-cs.pdf
lab-assgn-practical-file-xii-cs.pdflab-assgn-practical-file-xii-cs.pdf
lab-assgn-practical-file-xii-cs.pdf
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
MXNet Workshop
MXNet WorkshopMXNet Workshop
MXNet Workshop
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schools
 
CS150 Assignment 7 Cryptography Date assigned Monday.docx
CS150 Assignment 7 Cryptography  Date assigned Monday.docxCS150 Assignment 7 Cryptography  Date assigned Monday.docx
CS150 Assignment 7 Cryptography Date assigned Monday.docx
 
Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The Stack
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software security
 
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network security
 

Último

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Computer Organization and Structure 2011 MIPS Assembly Programming

  • 1. Computer Organization and Structure 2011 SPIM & MIPS PROGRAMMING Created and Presented by Shu-Yang Lin, Hsun-Pei Wang, Liang-Tsen Shen Department of Information Management National Taiwan University
  • 2. OUTLINE Homework 2 (Programming MIPS – Assignment) Assembly SPIM – Language Getting Programming Introduction Started to Assembly Language
  • 3. ASSEMBLY LANGUAGE Machine language • Computer’s binary encoding Assembly language • Symbolic representation of a computer’s binary encoding Assembler • Translates assembly language into binary instructions
  • 4. WHAT IS SPIM? MIPS32 simulator that reads and executes assembly language program written for SPIM. SPIM does NOT execute binary program.
  • 5. REFERENCES OF SPIM Official website of SPIM: http://spimsimulator.sourceforge.net/ Assemblers, Linkers, and the SPIM Simulator:http://pages.cs.wisc.edu/~larus/HP_Ap pA.pdf MIPS Instruction Reference:http://www.mrc.uidaho.edu/mrc/peopl e/jff/digital/MIPSir.html
  • 6. QTSPIM - INSTALLATION http://spimsimulator.sourceforge.net /
  • 7. QTSPIM - INSTALLATION Linux Windows Mac
  • 8. QTSPIM - SCREENSHOT Text Window Register Window Data Window Console Window
  • 9. MIPS ASSEMBLY LANGUAGE Operation Code (Opcode)
  • 10. MIPS ASSEMBLY LANGUAGE MIPS Registers and Usage Convention n  $zero constant 0  $v0, $v1 expression of a function  $a0~$a3 argument 1~4  $t0~$t9 temporary registers  $s0~$s7 save registers  $sp stack pointer  $fp frame pointer  $ra return address …
  • 11. MIPS ASSEMBLY LANGUAGE Some Data Types in MIPS S .word, .half • 32/16 bit integer .byte • 8 bit integer .ascii, .asciiz • string .double, .float • floating point
  • 12. MIPS SYSTEM CALLS SPIM provides a small set of operating-system- like services through the system call instruction. A program loads the system call code into register $v0 and arguments into registers $a0- $a3 (or $f12 for floating-point values). System calls that return values put their results in register $v0 (or $f0 for floating-point results).
  • 13. MIPS SYSTEM CALLS $v0 FIGURE A.9.1 System services.
  • 14. EXAMPLE – HELLO WORLD C vs MIPS int main() .data { Mystr: .asciiz “Hello World¥n” printf(“Hello World¥”); return 0; .text main: } li $v0, 4 la $a0, Mystr syscall li $v0, 10 syscall
  • 15. EXAMPLE – HELLO WORLD MIPS Architecture e .data Mystr: .asciiz “Hello World¥n” Yourint: .word 75 Hisarray: .word 100, 100, 100 .word 20 , 40 , 60 .word 1 , 2 , 3 .text ……
  • 16. EXAMPLE – HELLO WORLD MIPS Architecture e .data .text main: # do anything you want …… # end of the program li $v0, 10 syscall
  • 17. MIPS SYSTEM CALLS - EXAMPLE Output: “the answer = 5’’ .data str: .asciiz "the answer = " .text li $v0, 4 # system call code for print_str la $a0, str # address of string to print syscall # print the string li $v0, 1 # system call code for print_int li $a0, 5 # integer to print syscall # print it FIGURE A.9.1 System services.
  • 18. ASSEMBLER SYNTAX Comment (#)  Everything from the sharp sign to the end of the line is ignored. Identifier (A sequence of alphanumeric characters, _ , and .)  Identifier are a sequence of alphanumeric characters, underbars (_), and dots (.) that do not begin with a number. Instruction Opcode  Instruction opcodes are reserved words that are not valid identifiers. Label  Labels are declared by putting them at the beginning of a line followed by a colon. PAGE 18
  • 20. HOMEWORK  This is an individual assignment  Plagiarism will be heavily punished  Write the following three programs in MIPS assembly language. (Must run correctly on SPIM) Simple Calculator Star Pyramid Pascal Triangle
  • 21. DOCUMENTATION (20%)  Detailed documentation for each program is required  The following parts must be included:  Your name, student ID, and email address  Explanation of the design or the flow of each program  What you’ve learnt from writing the programs  Problems or difficulties you’ve encountered during writing the programs are nice to be included in the document
  • 22. PROBLEM 1. SIMPLE CALCULATOR  Input:  Sample input / output • Two integer x, y ( x, y may be positive, negative or  zero) • An operator (+, ‐, *, /)  Requirements: • Print  the correct answer. • Can do many calculations  iteratively • If the answer of division includes a  remainder please print it out • The file name is Calculator.s
  • 23. PROBLEM 2: STAR PYRAMID  Build a pyramid using stars(*) and white spaces given number of rows Example: Space # of rows = 5 4 * 3 * * * 2 * * * * * 1 * * * * * * * * * * * * * * * *
  • 24. PROBLEM 2: STAR PYRAMID  Input:  Number of rows of the pyramid: N (N>0) Sample Input  Requirements:  Print the correct answer (Number of white spaces and stars should be correct)  File Name: StarPyramid.s Sample Output  Pyramid may seemed to be a little inclined caused by the default display settings of the console window in QtSPIM  will NOT affect your score
  • 25. PROBLEM 3: DEFORMATION OF PASCAL TRIANGLE F(m ,n) = F(m-1 ,n-1)+ 2*F(m-1 ,n) (F(x, 0)=1 for all x and F(0, y)=0 for y>0) 0 1 2 3 4 5 … 0 1 0 0 0 0 0 … *2 1 1 1 0 0 0 0 … *2 *2 2 1 3 1 0 0 0 … *2 *2 *2 3 1 7 5 1 0 0 … 4 *2 *2 *2 *2 1 15 17 7 1 0 …
  • 26. PROBLEM 3: DEFORMATION OF PASCAL TRIANGLE Input:  Two integers m, n (m=1~20, n=1~99) Requirements:  Output F(m ,n) = F(m-1 ,n-1)+ 2*F(m-1 ,n) (F(x, 0)=1 for all x and F(0, y)=0 for y>0)  Print the correct answer  Can do many calculations iteratively  File Name: PascalDeform.s
  • 27. HOW TO EXECUTE MY PROGRAM USING QTSPIM? Write your own assembly program, and save it as .s file Simulator  Clear Registers Simulator Reinitialize Simulator Open your .s file Simulator  Run / Continue
  • 28. SUBMISSION  Deadline: 11:59pm, 1 Nov. (Tue.)  You must submit at least the following files:  Calculator.s  StarPyramid.s  PascalDeform.s  (Your student id)_hwX_document.doc/pdf/docx  Please put all your files in a directory named by your student id in uppercase, and then compress it into one zipped file. (e.g. zip/tgz …)  You should upload your zipped file HW#2 to https://filestork.net/suv6oro7 before the deadline.  The file name should be like B99xxxxxx.zip, eg. B99705099.zip  Rename your file for multiple uploads, eg. B99705099_v2.zip, B99705099_v3.zip …
  • 29. Remember to rename your file SUBMISSION for multiple uploads!!! https://filestork.net/suv6oro7 7
  • 30. GRADING GUIDELINES Description For Each Problem Problem Program runs without error messages 10% Program executes correctly 60% Documentation and description of 20% the program Implementation Detail 10%
  • 31. CONTACT INFORMATION TA Hours @ 管五 503-C  Shu-Yang Lin (林書漾) Fri. 10:00~12:00  Hsun-Pei Wang (王珣沛) Fri. 10:00~12:00  Liang-Tsen Shen (沈亮岑) Mon. 10:00~12:00 Contact us if you have any problem  林書漾 young@cmlab.csie.ntu.edu.tw  王珣沛 garfieldduck@cmlab.csie.ntu.edu.tw  沈亮岑 olga@cmlab.csie.ntu.edu.tw
  • 32. DEADLINE 2011/11/1 (Tue.) Late submission policy: 10% off from your total score each day after the deadline
  • 33. THANK YOU FOR YOUR ATTENTION Any Questions?