MIPS assembly syntax Home Assignment 3 Assigned. Deadline 2016 February 14, Sunday.

Slides:



Advertisements
Similar presentations
SPIM and MIPS programming
Advertisements

Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Assembly Language Programming
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
1 Computer Architecture MIPS Simulator and Assembly language.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
Structure of a C program
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
SPIM : A MIPS Simulator Archi & Net Lab 이용석
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
Chapter 9: Arrays and Strings
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
On Textbook CD: SPIM Jen-Chang Liu, Simulation of a virtual machine Virtual machine (simulator) Differences between SPIM and real MIPS? No delayed.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
Introduction to Shell Script Programming
Introduction to Python
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Comp Sci vars & expns 1 Ch. 4 Variables and Expressions.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Lecture # 1 SPIM & MIPS Programming. SPIM SPIM is a MIPS32 simulator that reads and executes assembly language program written for SPIM. Platform -Unix,
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
Lecture 161 Lets examine a SPIM program in detail. io.asm This program is a simple routine which demonstrates input/output using assembly code. SPIM.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
The Assembly Process Computer Organization and Assembly Language: Module 10.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Home Assignment 5 Assigned. Deadline 2016 March 2, Wednesday.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
CS501 Advanced Computer Architecture Lecture 29 Dr.Noor Muhammad Sheikh.
Writing an Assembly-language program MIPS assembly language using MARS: MIPS Assembler and Runtime Simulator CS-2710 Dr. Mark L. Hornick 1.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CSC201: Computer Programming
Introduction to Lab #1 José Nelson Amaral.
Chapter 2, Part I Introduction to C Programming
ACOE301: Computer Architecture II Labs
MIPS assembly syntax Comments
INTRODUCTION ABOUT ASSEMBLY
MIPS coding.
Chapter 4 –Requirements for coding in Assembly Language
Requirements for coding in Assembly Language
COMS 361 Computer Organization
Focus of the Course Object-Oriented Software Development
Generalities for Assembly Language
MIPS Assembly Language Programming Computer Architecture
Computer Organization and Assembly Language
Conditional Control Structure
Some Assembly
Presentation transcript:

MIPS assembly syntax Home Assignment 3 Assigned. Deadline 2016 February 14, Sunday

MIPS assembly syntax Comments The character "#" (sharp sign) starts a comment;  Everything on the line from "#" to the right is ignored.  Sometimes you can use two or more in a row for emphasis, but only one is needed. ## Program to add two plus three - is a comment. It is ignored by the assembler and results in no machine instructions. Identifiers Identifiers are a sequence of alphanumeric characters, underbars (_), and dots (.) that do not begin with a number.

Directives A directive is a statement that tells the assembler something about what the programmer wants, but does not itself result in any machine instructions. .text: Subsequent items put in user text segment (machine code) .data: Subsequent items put in user data segment (binary rep of data in source file) .globl sym: Declares sym global and can be referenced from other files .asciiz str: Store the string str in memory and null- terminate it .byte b1…bn: Store the n values in successive memory bytes. .word w1…wn: Store the n 32-bit quantities in successive memory words

.text is a directive. This directive tells the assembler that the following lines are instructions and should produce machine instructions and put into the binary code text segment. ## Program to add two plus three.text.globl main main: ori $8, $0, 0x2 # put the number two into register 8 ori $9, $0, 3 # put the number three into register 9 add $10, $8, $9 # add register 8 and 9, put result in 10 ## End of file An example program.globl main is another directive. It says that the identifier main will be used outside of this source file (that is, used "globally") as the label of a particular location in main memory. The blank line is ignored. For simple programs.text and.globl could be omitted.

## Program to add two plus three.text.globl main main: ori $8, $0, 0x2 # put the number two into register 8 ori $9, $0, 3 # put the number three into register 9 add $10, $8, $9 # add register 8 and 9, put result in 10 ## End of file Labels Labels are declared by putting them at the beginning of a line followed by a colon, for example: main: ori $8,$0,0x2 main: symbolic address or a statement label. A symbolic address is a symbol (an identifier followed by a colon ``:'') that is the source code name for a location in memory. In this program, main stands for the address of the first machine instruction (which turns out to be 0x ).

Opcodes Instruction opcodes are reserved words that cannot be used as identifiers ori, add – are operation codes (opcodes) of assembly instructions..text.globl main main: ori $8, $0, 0x2 # put the number two into register 8 ori $9, $0, 3 # put the number three into register 9 add $10, $8, $9 # add register 8 and 9, put result in 10

Machine Instructions Each of the three lines following main: corresponds to one machine instruction. The line: ori $8,$0,0x2 is translated into a 32-bit machine instruction. The machine instruction, upon execution, puts a 32-bit two's complement positive 2 into register 8(details later). The instruction after that is translated into a machine instruction that (upon execution) puts a 3 into register 9. The final instruction is translated into a machine instruction that (upon execution) adds register 8 to register 9 and puts the 32-bit result into register 10..text.globl main main: ori $8, $0, 0x2 # put the number two into register 8 ori $9, $0, 3 # put the number three into register 9 add $10, $8, $9 # add register 8 and 9, put result in 10

.text.globl main main: ori $8, $0, 0x2 # put the number two into register 8 ori $9, $0, 3 # put the number three into register 9 add $10, $8, $9 # add register 8 and 9, put result in 10 Numbers Numbers are base 10 by default. If they are preceded by 0 x, they are interpreted as hexadecimal. 256 and 0x100 denote the same value. ori $8,$0,0x100 ori $8,$0,256

Strings, Data Strings are enclosed in double quotes (")..data string:.asciiz "Hello SPIM!\n\n".asciiz str - Stores the string str in memory and null-terminates it. Special characters in strings follow the C convention:  newline \n  tab \t  quote \".data is a directive. This directive tells the assembler that the subsequent items should be stored in the data segment of binary code.