Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
SPIM Tutorial CSE 410 Computer Systems. Introduction SPIM: MIPS simulator –Reads/executes assembly source programs Does not execute binaries Download.
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker.
Chapter 2 — Instructions: Language of the Computer — 1 Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Assembly Code Example Selection Sort.
SPRING 2015 QtSpim Demo & Tutorial. 2 By DGP Outline How to write your own MIPS assembly language program How to use QtSpim simulator.
SPIM and MIPS programming
Computer Architecture CSCE 350
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Function Continued
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
MIPS Assembly Language Programming
1 Computer Architecture MIPS Simulator and Assembly language.
Assembly Language Working with the CPU.
Lecture 8: MIPS Instruction Set
ECE 0142 Recitation #5.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
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.
MIPS Assembler Programming
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
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.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
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.
The MIPS Processor Computer Organization The MIPS Processor Appendix A.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Compiling examples in MIPS
Lecture 3 Translation.
Computer Architecture & Operations I
Lecture 6: Assembly Programs
Introduction to Lab #1 José Nelson Amaral.
Lecture 7: MARS, Computer Arithmetic
MIPS Coding Continued.
MIPS instructions.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
The University of Adelaide, School of Computer Science
MIPS coding.
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Lecture 4: MIPS Instruction Set
Computer Programming Machine and Assembly.
MIPS coding.
Lecture 7: Examples, MARS, Arithmetic
MIPS coding.
Review.
MIPS Coding.
MIPS function continued
MIPS Functions.
COMS 361 Computer Organization
Review.
MIPS Coding Continued.
MIPS coding.
10/6: Lecture Topics C Brainteaser More on Procedure Call
MIPS Assembly Language Programming Computer Architecture
Program Assembly.
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
MIPS Functions.
Conditional Branching (beq)
Presentation transcript:

Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec, 0x11110087 .byte 65, 79, 253 .text # CODE segment .globl main # declaring “main” as global main: li $v0, 4 # syscall for print_string la $a0, city # argument in $a0 syscall la $t0, num # get address of first number lw $s0, 0($t0) # s0 = 2210 lw $s1, 4($t0) # s1 = 2341 add $s0, $s0, $s1 # s0 = 2210+2341 li $v0, 1 # syscall for print_int move $a0, $s0 # argument in $a0 syscall .end main

General format of MIPS programs Xspim on our machines automatically loads some assembly code that takes care of calling “main” Need to write code that looks roughly like the following: .data # DATA segment lab1: .byte ……… lab2: .asciiz …… # some static data .float ……… lab3: .double ……... .text # CODE segment .globl main # declaring “main” as global main: <your part of the code> … ... .end main

If-then-else in MIPS What does the following C code looks like in MIPS assembly language: if (a < b) { a = a + 1; b = b - 1; } else { a = a * 2; b = b / 2; } Assume $s0 contains a, and $s1 contains b.

If-then-else (cont.) # if (a < b) slt $t0, $s0, $s1 beq $t0, $zero, else_label # a = a + 1, b = b - 1 addi $s0, $s0, 1 subi $s1, $s1, 1 j end_label # else a = a * 2, b = b / 2 else_label: sll $s0, $s0, 1 sra $s1, $s1, 1 # end of if-then-else end: <statements following if-then-else>

From C Program to Machine Language Stages in the transformation: C program Compiler Assembly Language program Assembler Object : Machine Language Module Library routines Machine Lang Linker Executable (Machine Language) Loader Memory