Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "More on MIPS programs n SPIM does not support everything supported by a general MIPS assembler. For example, –.end doesn’t work Use j $ra –.macro doesn’t."— Presentation transcript:

1 More on MIPS programs n SPIM does not support everything supported by a general MIPS assembler. For example, –.end doesn’t work Use j $ra –.macro doesn’t work Define your own small functions if there is some code that you need to call pretty often. n 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

2 More on MIPS Programs (cont’d) n 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 n 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 n “Pointer to a string”, “pointer to an array” –Simply the address of the first element

3 Stack Architectures n Motivation : POSTFIX notation n 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 operands Eg. (a x b) + (c + e / f) –POSTfix : operation is specified after all operands Eg. a b x e f / c + + n 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

4 JVM - Java Virtual Machine n 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 n Instructions have only immediate operands –no registers! n What happens to variable operands ? –Programmer explicitly pushes operands onto the stack –Instructions use operands from the top of the stack n Example: Adding in JVM – c = a + b translates to something like – ILOAD &a ILOAD &b IADD ISTORE &c

5 JVM (cont’d) n C code: x = 5; y = x - 1; if (x < y) goto label; n 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 SIPUSH1; 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 IFLTlabel; jump to label if top of stack contains something less than zero


Download ppt "More on MIPS programs n SPIM does not support everything supported by a general MIPS assembler. For example, –.end doesn’t work Use j $ra –.macro doesn’t."

Similar presentations


Ads by Google