|
|
c m s c 311
s p r i n g 2 0 0 2 |
Note: the executable should be run as:
p2 -d 1000 -t 2000 < primary.input
Note: 1000 and 2000 could be replaced with other (reasonable)
values. Also there is no "greater than" sign at the very
end of the file (this may be removed when you read it)
You can still submit the project WITHOUT the primary input. However, it should minimally print out the addresses of the labels.
.data
newline: string "\n"
mesg: string "The current sum is: "
mesg2: string "Print: "
mesg3: string "The total is: "
arr2: bytes [3] 'f' 'u' 'n'
arr: words [10] 1 2 3 4 5 6 7 8 9 10
value: word 27
.text
jal printMesg # print message
addi $r26, $r0, 3
la $r27, arr2
addi $r27, $r27, 1 # address of 'u'
swi # print byte value -- 75 in base 16
jal printNew # print new line
jal printMesg
addi $r26, $r0, 3
la $r27, value
swi # prints 00 (MSB of value 27)
jal printNew # print new line
jal printMesg
addi $r26, $r0, 3 # reset $r26 so that it is correct interrupt
la $r27, value # reset $r27 because of subroutines
addi $r27, $r27, 3 # add 3 to address
swi # prints 1B (LSB of value 27)
jal printNew # print new line
addi $r1, $r1, 0 # r1 stores sum
addi $r2, $r2, 0 # r2 stores array index (times 4)
addi $r3, $r3, 40 # r3 stores limit
L1: beq $r2, $r3, DONE # jump to end of loop
lw $r4, arr($r2) # val = arr[ i ]
add $r1, $r1, $r4 # sum = sum + val
jal printCurr
jal printNew # print new line
addi $r2, $r2, 4 # skip to next index
j L1
DONE: addi $r26, $r0, 4
la $r27, mesg3
swi
addi $r26, $r0, 5
addi $r27, $r0, 1 # To print register 1, instead of register 27
swi # Print final value
jal printNew # print new line
j end # Skip over the subroutines below
printMesg:
addi $r26, $r0, 4
la $r27, mesg2
swi
jr $r31
printNew:
addi $r26, $r0, 4
la $r27, newline
swi
jr $r31
printCurr:
addi $r26, $r0, 4
la $r27, mesg
swi
addi $r26, $r0, 5
addi $r27, $r0, 1 # To print register 1, instead of register 27
swi
jr $r31
end:
.data
newline: string "\n"
mesg: string "The current sum is: "
mesg2: string "Print: "
mesg3: string "The total is: "
arr2: bytes [3] 'f' 'u' 'n'
arr: words [10] 1 2 3 4 5 6 7 8 9 10
value: word 27
.text
jal printMesg # print message
addi $r26, $r0, 3
la $r27, arr2
addi $r27, $r27, 1 # address of 'u'
swi # print byte value -- 75 in base 16
jal printNew # print new line
jal printMesg
addi $r26, $r0, 3
la $r27, value
swi # prints 00 (MSB of value 27)
jal printNew # print new line
jal printMesg
addi $r26, $r0, 3 # reset $r26 so that it is correct interrupt
la $r27, value # reset $r27 because of subroutines
addi $r27, $r27, 3 # add 3 to address
swi # prints 1B (LSB of value 27)
jal printNew # print new line
addi $r1, $r1, 0 # r1 stores sum
addi $r2, $r2, 0 # r2 stores array index (times 4)
addi $r3, $r3, 40 # r3 stores limit
L1: beq $r2, $r3, DONE # jump to end of loop
lw $r4, arr($r2) # val = arr[ i ]
add $r1, $r1, $r4 # sum = sum + val
jal printCurr
jal printNew # print new line
addi $r2, $r2, 4 # skip to next index
j L1
DONE: addi $r26, $r0, 4
la $r27, mesg3
swi
addi $r26, $r0, 5
add $r27, $r0, $r1
swi # Print final value
jal printNew # print new line
j end # Skip over the subroutines below
printMesg:
addi $r26, $r0, 4
la $r27, mesg2
swi
jr $r31
printNew:
addi $r26, $r0, 4
la $r27, newline
swi
jr $r31
printCurr:
addi $r26, $r0, 4
la $r27, mesg
swi
addi $r26, $r0, 5
add $r27, $r0, $r1
swi
jr $r31
end:
The only new instruction is: la which stands for "load address".
la $rd, LABEL is not a real MIPS instruction. The equivalent (for small addresses) is addi $rd, $r0, LABEL. For larger addresses, you may need to use lui and ori to place both parts of the address.
The output should look like:
Print: 75 Print: 00 Print: 1B The current sum is: 1 The current sum is: 3 The current sum is: 6 The current sum is: 10 The current sum is: 15 The current sum is: 21 The current sum is: 28 The current sum is: 36 The current sum is: 45 The current sum is: 55 The total is: 55
|
See the class syllabus for policies concerning email Last Modified: Sun Mar 3 22:54:00 EST 2002 |
|
|
|
|
|