Learning MIPS & SPIM

3y ago
24 Views
2 Downloads
577.97 KB
23 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Nora Drum
Transcription

Learning MIPS & SPIM MIPS assembly is a low-level programming language The best way to learn any programming language is to writecode We will get you started by going through a few exampleprograms and explaining the key concepts Tip: Start by copying existing programs and modifying themincrementally making sure you understand the behavior ateach step Tip: The best way to understand and remember a construct orkeyword is to experiment with it in code, not by readingabout it

MIPS Assembly Code Layout Typical Program Layout.text#code section.globl main#starting point: must be globalmain:# user program code.data#data section# user program data

MIPS Memory Usage as viewed in SPIM0x7fffffff0x7fffeffc0x10010000reservedstack segmentdata segmenttext segment(instructions)0x00400000reserved0x00000000

MIPS Assembler Directives Top-level Directives: .text indicates that following items are stored in the user text segment, typically instructions .data indicates that following data items are stored in the data segment .globl sym declare that symbol sym is global and can be referenced from other files

MIPS Assembler Directives Common Data Definitions: .word w1, , wn store n 32-bit quantities in successive memory words .half h1, , hn store n 16-bit quantities in successive memory halfwords .byte b1, , bn store n 8-bit quantities in successive memory bytes .ascii str store the string in memory but do not null-terminate it strings are represented in double-quotes “str” special characters, eg. \n, \t, follow C convention .asciiz str store the string in memory and null-terminate it

MIPS Assembler Directives Common Data Definitions: .float f1, , fn store n floating point single precision numbers in successive memory locations .double d1, , dn store n floating point double precision numbers in successive memory locations .space n reserves n successive bytes of space .align n align the next datum on a 2n byte boundary. For example, .align 2 aligns next value on a word boundary. .align 0 turns off automatic alignment of .half, .word, etc. till next .data directive

MIPS: Software Conventionsfor Registers0zero constant 016 s0 callee saves1at.2v0 results from callee23 s73v1 returned to caller24 t84a0 arguments to callee25 t95a126 k0 reserved for OS kernel6a227 k17a328 gp pointer to global area8t0reserved for assemblerfrom caller: caller savestemporarytemporary (cont’d)29 sp stack pointer.30 fpframe pointer15 t731 rareturn Addresscaller saves

Pseudoinstructions Pseudoinstructions do not correspond to real MIPSinstructions. Instead, the assembler, would translatepseudoinstructions to real instructions (one on moreinstructions). Pseudoinstructions not only make it easier toprogram, it can also add clarity to the program, bymaking the intention of the programmer more clear.

Pseudoinstructions Here's a list of useful pseudo-instructions. mov t0, t1: Copy contents of register t1 to register t0. li s0, immed: Load immediate into to register s0. The way this is translated depends on whether immed is 16 bits or 32bits. la s0, addr: Load address into to register s0. lw t0, address: Load a word at address into register t0 Similar pseudo-instructions exist for sw, etc.

Pseudoinstructions Translating Some Pseudoinstructionsmov t0, s0addi t0, s0, 0li rs, smalladdi rs, zero, smallli rs, biglui rs, upper(big) ori rs, rs, lower(big)la rs, biglui rs, upper(big) ori rs, rs, lower(big) where small means a quantity that can be represented using 16 bits, andbig means a 32 bit quantity. upper( big ) is the upper 16 bits of a 32 bitquantity. lower( big ) is the lower 16 bits of the 32 bit quantity.upper( big ) and lower(big) are not real instructions. If you were to do thetranslation, you'd have to break it up yourself to figure out those quantities.

Pseudoinstructions As you look through the branch instructions,you see beq and bne, but not bge (branch ongreater than or equal), bgt (branch on greaterthan), ble (branch on less than or equal), blt(branch on less than). There are no branchinstructions for relational operators!

Pseudoinstructions Here's the table for translating pseudoinstructions. bge t0, s0, LABEL slt at, t0, s0beq at, zero, LABEL bgt t0, s0, LABEL slt at, s0, t0bne at, zero, LABEL ble t0, s0, LABEL slt at, s0, t0beq at, zero, LABEL blt t0, s0, LABEL slt at, t0, s0bne at, zero, LABEL

System Calls System Calls (syscall) OS-like services Method Load system call code into register v0Load arguments into registers a0 a3call system with SPIM instruction syscallAfter call, return value is in register v0 Frequently used system calls

System Call CodesServiceCode (put in v0)ArgumentsResultprint int1 a0 integerprint float2 f12 floatprint double3 f12 doubleprint string4 a0 addr. of stringread int5int in v0read float6float in f0read double7double in f0read string8 a0 buffer, a1 lengthsbrk9 a0 amountexit10addr in v0

QtSPIM QtSpim is software that will help you to simulate the executionof MIPS assembly programs.It does a context and syntax check while loading an assemblyprogram.In addition, it adds in necessary overhead instructions asneeded, and updates register and memory content as eachinstruction is executed.Download the source from the SourceForge.org link at:http://pages.cs.wisc.edu/ larus/spim.htmlAlternatively, you can go directly iles/Versions for Windows, Linux, and Macs are all available

QtSPIM QtSPIM window is divided into different sections:1.2.The Register tabs display the content of all registers.Buttons across the top are used to load and run a simulation 3.Functionality is described in Figure 2.The Text tab displays the MIPS instructions loaded intomemory to be executed. From left-to-right, the memory address of an instruction,the contents of the address in hex, the actual MIPS instructionswhere register numbers are used, the MIPS assembly that youwrote, and any comments you made in your code are displayed.4.The Data tab displays memory addresses and their values inthe data and stack segments of the memory.5.The Information Console lists the actions performed by the simulator.

QtSPIM Program Example A Simple Program#sample example 'add two numbers’.text.globl main# text section# call main by SPIMmain:#####la t0, valuelw t1, 0( t0)lw t2, 4( t0)add t3, t1, t2sw t3, 8( t0).datavalue: .word 10, 20, 0load address ‘value’ into t0load word 0(value) into t1load word 4(value) into t2add two numbers into t3store word t3 into 8( t0)# data section# data for addition

QtSPIM Example Program## Program adds 10 and 11.text.globlmain:orioriaddmain 8, 0,0xA 9, 0,0xB 10, 8, 9# text section# call main by SPIM####load “10" into register 8load “11" into register 9add registers 8 and 9, put resultin register 10

QtSPIM Example Program: swap2memoryWords.asm## Program to swap two memory words.data.word 7.word 3# load data.text.globl mainmain:luilwlwswsw s0, s1, s2, s2, s1,0x1001 # load data area start address 0x100100000( s0)4( s0)0( s0)4( s0)

QtSPIM Example Program: procCallsProg2.asm## Procedure call to swap two array words.text.globlmain:load parameters forswapsave returnaddress rain stackla a0, arrayaddi a1, 0, 0addi sp, sp, -4sw ra, 0( sp)jaljump andlink to swaprestorereturnaddressjump to ra##mainswaplwaddi ra, 0( sp) sp, sp, 4jr raequivalent C code:swap(int v[], int k)#{#int temp;#temp v[k];#v[k] v[k 1];#v[k 1] temp;#}# swap contents of elements a1# and a1 1 of the array that# starts at a0swap: add t1, a1, a1add t1, t1, t1add t1, a0, t1lw t0, 0( t1)lw t2, 4( t1)sw t2, 0( t1)sw t0, 4( t1)jr ra.dataarray: .word 5, 4, 3, 2, 1

QtSPIM Example Program: systemCalls.asm## Enter two integers in## console window## Sum is displayed.text.globl mainlw t1, 0( t0)lw t2, 4( t0)add t3, t1, t2sw t3, 8( t0)system call codefor print stringli v0, 4la a0, msg1syscallargument to print string callmain:la t0, valueli v0, 5syscallsw v0, 0( t0)system call codefor read intresult returned by callli v0, 5syscallsw v0, 4( t0)li v0, 1move a0, t3syscallsystem call codefor print intargument to print int callli v0, 10syscallsystem call codefor exit.datavalue: .word 0, 0, 0msg1: .asciiz “Sum “

Learning MIPS & SPIM MIPS assembly is a low-level programming language The best way to learn any programming language is to write code We will get you started by going through a few example programs and explaining the key concepts

Related Documents:

Spim is a self-contained simulator that runs MIPS32 programs. It reads and executes assembly language programs written for this processor. Spim also provides a simple debugger and minimal set of operating system services. Spim does not execute binary (compiled) programs. Spim implements both a terminal and windows interfaces.

Learning MIPS & SPIM MIPS assembly is a low-level programming language The best way to learn any programming language is to write code We will get you started by going through a few example programs and explaining the key concepts Tip: Start by copying existing programs and modifying them

bits, gọi là MIPS-64. MIPS xem xét trong môn học này là MIPS làm việc với các thanh ghi chỉ 32 bit, gọi là MIPS-32. ÞTrong phạm vi môn học này, MIPS dùng chung sẽ hiểu là MIPS-32 Tóm lại, chỉ có 3 loại toán hạng trong một lệnh của MIPS 1. Toán hạng thanh ghi (Register Operands) 2.

Table 1: How 2020 MIPS Final Scores Relate to 2022 MIPS Payment Adjustments Final Score Points MIPS Payment Adjustment 0.00 – 11.25 points Negative (-) MIPS payment adjustment of -9% 11.26 – 44.99 points Negative (-) MIPS payment adjustment, between 0% and -9%, on a linear sliding scale 45.00 points (Performance threshold 45.00 points)

Performance on EEMBC benchmarks aggregate for Consumer, Telecom, Office, Network, based on ARM1136J-S (Freescale i.MX31), ARM1026EJ-S, Tensilica Diamond 570T, T1050 and T1030, MIPS 20K, NECVR5000). MIPS M4K, MIPS 4Ke, MIPS 4Ks, MIPS 24K, ARM 968E-S, ARM 966E-S, ARM926EJ-S, ARM7TDMI-S scaled by ratio of Dhrystone MIPS within architecture family.

ACOs in MIPS receive advantages by being scored under the MIPS APM Scoring Standard, which gives ACOs favorable treatment for their commitment to value-base care. Based on the low bar set for 2019 reporting in MIPS, ACOs should easily avoid penalties under MIPS and will be eligible for MIPS bonuses and exceptional performance bonuses.

Chapter 1: Getting started with mips Remarks This section provides an overview of what mips is, and why a developer might want to use it. It should also mention any large subjects within mips, and link out to the related topics. Since the Documentation for mips is new, you may need to create initial versions of those related topics. Examples

ANSI A300 (Part 7), approved by industry consensus in 2006, contains many elements needed for an effective TVMP as required by this Standard. One key element is the “wire zone – border zone” concept. Supported by over 50 years of continuous research, wire zone – border zone is a proven method to manage vegetation on transmission rights-of-ways and is an industry accepted best practice .