More on mips programs
1 / 5

More on MIPS programs - PowerPoint PPT Presentation

  • Uploaded on

More on MIPS programs. SPIM does not support everything supported by a general MIPS assembler. For example, .end <function_name> doesn’t work Use j $ra

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'More on MIPS programs' - reeves

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
More on mips programs
More on MIPS programs

  • SPIM does not support everything supported by a general MIPS assembler. For example,

    • .end <function_name> doesn’t workUse j $ra

    • .macro doesn’t workDefine your own small functions if there is some code that you need to call pretty often.

  • Using multiple files

    • When? For large programs

    • Why? Organizes things easily Allows more than one person to work on the program

    • How? Simply load all the files into SPIM !!!

    • Remember There has to be exactly one function called main Labels have to be unique among all files Don’t use “hardcoded” addresses; use only labels

More on mips programs cont d
More on MIPS Programs (cont’d)

  • Printing multiple lines with a single syscall

    • Use .ascii instead of .asciiz for the initial strings

    • Eg. school: .ascii “University of” .ascii “Washington \n” .asciiz “Seattle \n” .text move $v0, 4 la $a0, school syscall

    • Output: University of Washington Seattle

  • Arrays in assembly language

    • There are no arrays in assembly language (of course!)

    • All you get is a pointer to the first element of the array(ie. address of the first element)

    • It’s up to the assembly program writer to treat the contents of the memory following the base address as an array

    • Need explicit offsets or address computation

  • “Pointer to a string”, “pointer to an array”

    • Simply the address of the first element

Stack architectures
Stack Architectures

  • Motivation : POSTFIX notation

  • What is Postfix?

    • A way of writing mathematical expressions

    • As powerful as the common notation (Infix)

    • Easier to implement

    • Infix : operation is specified in between the two operandsEg. (a x b) + (c + e / f)

    • POSTfix : operation is specified after all operandsEg. a b x e f / c + +

  • How are Postfix expressions evaluated?

    • Use the notion of a stack

    • Scan postfix expression from left to right

    • If you see an operand push it on the stack

    • If you see an operation pop operands from the stack apply operation to the oerands push result back onto stack

Jvm java virtual machine
JVM - Java Virtual Machine

  • An abstract computing machine

    • Has its own set of instructions, called bytecodes

    • No special hardware that provides these instructions

    • Can simulate this machine on any computer + : Platform Independence - : Slow

  • Instructions have only immediate operands

    • no registers!

  • What happens to variable operands ?

    • Programmer explicitly pushes operands onto the stack

    • Instructions use operands from the top of the stack

  • Example: Adding in JVM

    • c = a + b translates to something like


Jvm cont d
JVM (cont’d)

  • C code: x = 5; y = x - 1; if (x < y) goto label;

  • JVM code: ; x = 5; SIPUSH 5 ; get 5 ISTORE &x ; store at address of x ; y = x - 1 ILOAD &x ; load x onto stack for y=x-1 SIPUSH 1 ; 1 for y=x-1 ISUB ; subtract 1 from x ISTORE &y ; save the result in y ; if (x < y) goto label; ILOAD &x ; reload x ILOAD &y ; reload y ISUB ; subtract y from x IFLT label ; jump to label if top of stack contains something less than zero