Hop ngu MIP

141 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
141
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Hop ngu MIP

  1. 1. .data EnterA : .asciiz "Nhap A " EnterB : .asciiz "Nhap B " Menu : .asciiz "----------------------------Menu------------------------nn1. Tong a va bn2. Hieu a va bn3. Tich a va bn4. Thuong a va bn5. Kiem tra a va b la so nguyen to ?n6. Kiem tra a va b la so hoan thien ?n7. Kiem tra a va b la so chinh phuong ?n8. Kiem tra a va b la so doi xung ?n0. Thoatn--------------------------------------------------------------------n" Chose: .asciiz "Chon " Tong : .asciiz "Tong : " Hieu : .asciiz "Hieu : " Tich : .asciiz "Tich : " Thuong : .asciiz "Thuong : " Result : .asciiz "Ket qua: " True_Nt_A : .asciiz "A la so nguyen to" False_Nt_A : .asciiz "A khong phai so nguyen to" True_Nt_B : .asciiz "nB la so nguyen to" False_Nt_B : .asciiz "nB khong phai so nguyen to" True_Ht_A: False_Ht_A True_Ht_B: False_Ht_B .asciiz "A la so hoan thien" : .asciiz "A khong phai so hoan thien" .asciiz "nB la so hoan thien" : .asciiz "nB khong phai so hoan thien" True_Cp_A: False_Cp_A True_Cp_B: False_Cp_B .asciiz "A la so chinh phuong" : .asciiz "A khong phai so chinh phuong" .asciiz "nB la so chinh phuong" : .asciiz "nB khong phai so chinh phuong" True_Dx_A: False_Dx_A True_Dx_B: False_Dx_B .asciiz "A la so doi xung" : .asciiz "A khong phai so doi xung" .asciiz "nB la so doi xung" : .asciiz "nB khong phai so doi xung" .text .globl main main: li $v0,4 #print "Nhap a" la $a0,EnterA syscall li $v0,5 #scan a syscall move $s0,$v0 li $v0,4 #print "Nhap b" la $a0,EnterB syscall li $v0,5 #scan b syscall move $s1,$v0 li $v0,4 #print "Menu" la $a0,Menu syscall li $v0,4 #print "Chon"
  2. 2. la $a0,Chose syscall li $v0,5 #scan k syscall move $s2,$v0 li $v0,4 #print "Ket qua : " la $a0,Result syscall addi $t0,$s2,-1 bne $t0,$0,Subtraction #k==0 Jump -> Exit add $s3,$s1,$s0 #S=a+b li $v0,4 #print "Tong : " la $a0,Tong syscall move $a0,$s3 li $v0,1 #print "Tong" syscall j Exit Subtraction: addi $t0,$s2,-2 bne $t0,$0,Multiplication sub $s3,$s0,$s1 #S=a-b li $v0,4 #print "Hieu : " la $a0,Hieu syscall move $a0,$s3 li $v0,1 #print Hieu syscall j Exit Multiplication: addi $t0,$s2,-3 bne $t0,$0,Division mult $s1,$s0 #S=a*b mflo $s3 li $v0,4 #print "Tich : " la $a0,Tich syscall move $a0,$s3 li $v0,1 #print Tich syscall j Exit Division: addi $t0,$s2,-4 bne $t0,$0,Prime div $s0,$s1 #S=a/b mflo $s3
  3. 3. li $v0,4 #print "Thuong : " la $a0,Thuong syscall move $a0,$s3 li $v0,1 #print Thuong syscall Prime: addi $t0,$s2,-5 bne $t0,$0,CompleteNumber addi $s4,$0,2 #i=2 addi $s5,$0,1 #check = 1 Nt_A_Loop: slt $t0,$s4,$s0 #i<a i>=a thi thoat i<a beq $t0,$0,Nt_A_ExitLoop # Tuc la a khong lon hon i(a<=i) thi thoat div $s0,$s4 # a%i mfhi $s6 #temp = a%i bne $s6,$0,Nt_A_ExitIf add $s5,$0,$0 j Nt_A_ExitLoop Nt_A_ExitIf: addi $s4,$s4,1 j Nt_A_Loop Nt_A_ExitLoop: bne $s5,$0,Nt_A_CheckIf li $v0,4 #print "A khong la so nguyen to " la $a0,False_Nt_A syscall j Nt_A_CheckElse Nt_A_CheckIf: li $v0,4 #print "A la so nguyen to " la $a0,True_Nt_A syscall Nt_A_CheckElse: addi $s4,$0,2 #i=2 addi $s5,$0,1 #check = 1 Nt_B_Loop: slt $t0,$s4,$s1 #i<a i>=a thi thoat i<a beq $t0,$0,Nt_B_ExitLoop # Tuc la a khong lon hon i(a<=i) thi thoat div $s1,$s4 # a%i mfhi $s6 #temp = a%i bne $s6,$0,Nt_B_ExitIf add $s5,$0,$0 j Nt_B_ExitLoop
  4. 4. Nt_B_ExitIf: addi $s4,$s4,1 j Nt_B_Loop Nt_B_ExitLoop: bne $s5,$0,Nt_B_CheckIf li $v0,4 #print "A khong la so nguyen to " la $a0,False_Nt_B syscall j Nt_B_CheckElse Nt_B_CheckIf: li $v0,4 #print "A la so nguyen to " la $a0,True_Nt_B syscall Nt_B_CheckElse: j Exit CompleteNumber: addi $t0,$s2,-6 bne $t0,$0,SquareNumber addi $s3,$0,0 #s=0 addi $s4,$0,1 #i = 1 Ht_A_Loop: slt $t0,$s4,$s0 #i<a i>=a thi thoat i<a beq $t0,$0,Ht_A_ExitLoop # Tuc la a khong lon hon i(a<=i) thi thoat div $s0,$s4 # a%i mfhi $s6 #temp = a%i bne $s6,$0,Ht_A_ExitIf add $s3,$s3,$s4 Ht_A_ExitIf: addi $s4,$s4,1 j Ht_A_Loop Ht_A_ExitLoop: bne $s3,$s0,Ht_A_CheckIf li $v0,4 #print "A la so hoan thien" la $a0,True_Ht_A syscall j Ht_A_CheckElse Ht_A_CheckIf: li $v0,4 #print "A khong la so hoan thien" la $a0,False_Ht_A syscall Ht_A_CheckElse:
  5. 5. addi $s3,$0,0 #s=0 addi $s4,$0,1 #i = 1 Ht_B_Loop: slt $t0,$s4,$s1 #i<a i>=a thi thoat i<a beq $t0,$0,Ht_B_ExitLoop # Tuc la a khong lon hon i(a<=i) thi thoat div $s1,$s4 # a%i mfhi $s6 #temp = a%i bne $s6,$0,Ht_B_ExitIf add $s3,$s3,$s4 Ht_B_ExitIf: addi $s4,$s4,1 j Ht_B_Loop Ht_B_ExitLoop: bne $s3,$s1,Ht_B_CheckIf li $v0,4 #print "A la so hoan thien" la $a0,True_Ht_B syscall j Ht_B_CheckElse Ht_B_CheckIf: li $v0,4 #print "A khong la so hoan thien" la $a0,False_Ht_B syscall Ht_B_CheckElse: j Exit SquareNumber: addi $t0,$s2,-7 bne $t0,$0,SymmetryNumber addi $s5,$0,0 #check=0 addi $s4,$0,1 #i = 1 Cp_A_Loop: slt $t0,$s4,$s0 #i<a i>=a thi thoat i<a beq $t0,$0,Cp_A_ExitLoop # Tuc la a khong lon hon i(a<=i) thi thoat mult $s4,$s4 # a*a mflo $s6 #temp = a*a bne $s6,$s0,Cp_A_ExitIf addi $s5,$0,1 #check=1 j Cp_A_ExitLoop Cp_A_ExitIf: addi $s4,$s4,1 j Cp_A_Loop
  6. 6. Cp_A_ExitLoop: beq $s5,$0,Cp_A_CheckIf li $v0,4 #print "A la so hoan thien" la $a0,True_Cp_A syscall j Cp_A_CheckElse Cp_A_CheckIf: li $v0,4 #print "A khong la so hoan thien" la $a0,False_Cp_A syscall Cp_A_CheckElse: addi $s5,$0,0 #check=0 addi $s4,$0,1 #i = 1 Cp_B_Loop: slt $t0,$s4,$s1 #i<a i>=a thi thoat i<a beq $t0,$0,Cp_B_ExitLoop # Tuc la a khong lon hon i(a<=i) thi thoat mult $s4,$s4 # a*a mflo $s6 #temp = a*a bne $s6,$s1,Cp_B_ExitIf addi $s5,$0,1 #check=1 j Cp_B_ExitLoop Cp_B_ExitIf: addi $s4,$s4,1 j Cp_B_Loop Cp_B_ExitLoop: beq $s5,$0,Cp_B_CheckIf li $v0,4 #print "A la so hoan thien" la $a0,True_Cp_B syscall j Cp_B_CheckElse Cp_B_CheckIf: li $v0,4 #print "A khong la so hoan thien" la $a0,False_Cp_B syscall Cp_B_CheckElse: j Exit SymmetryNumber: addi $t0,$s2,-8 bne $t0,$0,Exit
  7. 7. addi $s3,$0,0 #dao=0 add $s4,$s0,$0 #m=a Dx_A_Loop: slt $t0,$0,$s4 #0>=m thi 0, 0<m thi 1 beq $t0,$0,Dx_A_ExitLoop # 0<=m thi thoat addi $s7,$0,10 # $s7 = 10 mult $s3,$s7 # dao*10 mflo $s3 # dao=dao*10 div $s4,$s7 mfhi $s6 # temp = m % 10 add $s3,$s3,$s6 # dao = dao + temp div $s4,$s7 mflo $s4 j Dx_A_Loop Dx_A_ExitLoop: bne $s3,$s0,Dx_A_CheckIf li $v0,4 la $a0,True_Dx_A syscall j Dx_A_CheckElse Dx_A_CheckIf: li $v0,4 la $a0,False_Dx_A syscall Dx_A_CheckElse: addi $s3,$0,0 #dao=0 add $s4,$s1,$0 #m=a Dx_B_Loop: slt $t0,$0,$s4 #0>=m thi 0, 0<m thi 1 beq $t0,$0,Dx_B_ExitLoop # 0<=m thi thoat addi $s7,$0,10 # $s7 = 10 mult $s3,$s7 # dao*10 mflo $s3 # dao=dao*10 div $s4,$s7 mfhi $s6 # temp = m % 10 add $s3,$s3,$s6 # dao = dao + temp div $s4,$s7 mflo $s4 j Dx_B_Loop Dx_B_ExitLoop:
  8. 8. bne $s3,$s1,Dx_B_CheckIf li $v0,4 la $a0,True_Dx_B syscall j Dx_B_CheckElse Dx_B_CheckIf: li $v0,4 la $a0,False_Dx_B syscall Dx_B_CheckElse: j Exit Exit: li $v0, 10 syscall

×