# The .data directive tells the assembler to put # everything that follows into the data segment. # Remember that the data segment begins as memory address # 0x1001 0000 .data # Everything in the data segment is packed as close as # possible, in the order that we list it. a: .word 0xFFFFFFFF # Allocate a word (4 bytes) # Attach the identifier "a" to the first byte # Initialize the word with 1111 ... 1111 # note that you can't use any mnemonic as an identifier, so # "b" is an illegal identifier (b is a MIPS mnemonic). c: .word 305419896 # decimal initialization # The variable c is allocated in memory immediately # after a. d0: .byte 0x0 # d0 is a byte d1: .byte 0x1 # note that qtspim on ice is little endian d2: .byte 0x2 # because ice runs on an x86 d3: .byte 0x3 e0: .half 0xABCD # e0, e1 are 2 byte quantities e1: .half 0x1234 # To allocate space for arrays and structs, use the # the space directive. array: .space 20 # Reserve 20 bytes (i.e. 5 words). The # label "array" is attached to the first byte. # The memory is uninitialized. # G is a pre-initialized array of 8 words g: .word 7 6 5 4 3 2 1 0 # You can also store arrays of chars and C-strings. s1: .ascii "How now," # s1 is a sequence of chars, # not null-terminated s2: .asciiz "hex cow?" # s2 is a null-terminated sequence # of chars, i.e. a C-string # MIPS words must always reside in memory at an address # that is divisible by 4. This is called an "alignment # restriction". # # If you reserve space using anything other than .word # or .space, as we did above by using .byte, .half, .ascii, # and .asciiz, then you might not use up a multiple of 4 bytes. # The align directive tells the assembler to add padding if # necessary so the next thing is placed beginning at # a 4-byte address. .align 2 h: .word 123456789 # == 0x075b cd15