Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "MIPS assembly syntax Home Assignment 3 Assigned. Deadline 2016 February 14, Sunday."— Presentation transcript:

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

2 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.

3 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

4 .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.

5 ## 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 0x00400000).

6 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

7 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

8 .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

9 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.


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

Similar presentations


Ads by Google