•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 456,564 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,522 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 1122 | Replies: 1
![]() |
| |
•
•
Join Date: Sep 2007
Posts: 12
Reputation:
Rep Power: 2
Solved Threads: 0
my code is
[code]
however whenever I tried to print something inside the function it always gives me a bad address error, can someone please tell me why?? this is my code:
thanks
[code]
however whenever I tried to print something inside the function it always gives me a bad address error, can someone please tell me why?? this is my code:
largest : #Function prologue
subu $sp, $sp, 56
sw $a1, 44($sp)
sw $a0, 40($sp)
sw $ra, 36($sp)
sw $fp, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
addiu $fp, $sp, 56
lw $s0, 0($a0) # $t0 = first elements in the numbers array
li $s2, 1 # $t2 = 1
li $s3, 0 # $t3 = 0
iterate : #Loop Test
add $s1, $s2, $s2 # quadruple i to get offset for numbers[i]
add $s1, $s1, $s1
add $s5, $s1, $a0 # compute address of numbers[i]
lw $s7, 0($s5) # t7 = value stored at numbers[i]
addi $s2, $s2, 1 # $t2 ++
beq $s3, $a1, result # if $t3 equals to numElements then count result
addi $s3, $s3, 1 # $t3 ++
#Loop Body
slt $s4, $s0, $s7 # $t4 = 1 if $t0 is less than $t7
beq $s4, $zero, iterate # if $t5 not equal to zero then iterate again
lw $s0, 0($s5) # else $t0 = $t7
j iterate # iterate
result: add $v0, $s0, $zero # put the result of the largest number into $v0
#Function epilogue
lw $a1, 44($sp)
lw $a0, 40($sp)
lw $ra, 36($sp)
lw $fp, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addiu $sp, $sp, 56
jr $ra
average : #Function prologue
subu $sp, $sp, 56
sw $a1, 44($sp)
sw $a0, 40($sp)
sw $ra, 36($sp)
sw $fp, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
addiu $fp, $sp, 56
li $s2, 0 # $s2 = 0
iterate1 : #Loop Test
add $s1, $s2, $s2 # quadruple i to get offset for numbers[i]
add $s1, $s1, $s1
add $s5, $s1, $a0
lw $s0, 0($s5)
add $s4, $s4, $s0 # s4 = total addition of the array to numbers[i]
#LoopBody
addi $s2, $s2, 1 # $s2 ++
beq $s3, $a1, result1 # if $t3 equals to numElements then count result
addi $s3, $s3, 1 # $t3 ++
j iterate1 # iterate1
result1 : div $s4, $a1
addi $a2, $a1, 0
mfhi $a1
addi $a0, $a1,
mflo $a0
jal printAverage
#Function epilogue
lw $a1, 44($sp)
lw $a0, 40($sp)
lw $ra, 36($sp)
lw $fp, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addiu $sp, $sp, 56
jr $ra
thanks
![]() |
•
•
•
•
•
•
•
•
DaniWeb Assembly Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- getline function error (C++)
- HELP (error C2064: term does not evaluate to a function taking 1 arguments (C++)
- too many arguments to function error message. (C++)
- Image Resize Function Error (PHP)
- Function Error Message Help (C++)
- Keyboard Error Handling (C++)
- Sorting arrays of pointers with function? (C)
- Function with pointer? (C++)
Other Threads in the Assembly Forum
- Previous Thread: capturing string data from keyboard/input
- Next Thread: Pipelining and Stalling


Hybrid Mode