1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
.data msg1: .asciiz "tak(18,12,6)is: "
.text .globl main main: li $v0,4 la $a0,msg1 syscall
addiu $sp,$sp,-28 sw $ra,24($sp) sw $fp,20($sp) addiu $fp,$sp,24
li $a0,18 li $a1,12 li $a2,6 move $a3,$a2 jal tak
move $a0,$v0 li $v0,1 syscall
lw $ra,24($sp) lw $fp,20($sp) addiu $sp,$sp,28
li $v0,10 syscall
tak: addiu $sp,$sp,-28 sw $ra,24($sp) sw $fp,20($sp) addiu $fp,$sp,24
sw $a0,4($fp) lw $v0,4($fp) sw $a1,8($fp) lw $v1,8($fp) sw $a2,12($fp) bgt $a0,$a1,endless move $v0,$a2 j end
endless: # lw $v1,4($fp) addiu $a0,$v1,-1 lw $a1,8($fp) lw $a2,12($fp) move $a3,$a2 jal tak sw $v0,16($fp) # lw $v1,8($fp) addiu $a0,$v1,-1 lw $a1,12($fp) lw $a2,4($fp) move $a3,$a2 jal tak sw $v0,20($fp) # lw $v1,12($fp) addiu $a0,$v1,-1 lw $a1,4($fp) lw $a2,8($fp) move $a3,$a2 jal tak move $a2,$v0 # lw $a0,16($fp) lw $a1,20($fp) move $a3,$a2 jal tak end: lw,$ra,24($sp) lw $fp,20($sp) addiu $sp,$sp,28 jr $ra
|