Sao em thấy upfile lên không được?
Em gửi đường link down file chạy về nha. Phần mềm chạy trên môi trường MAR4.0.1, loại hợp ngữ MIPS. Ngoài ra bạn cũng có thể xem code bằng trình duyệt Web vẫn OK.
Code trực tiếp ở đây
.data
Menu: .asciiz "\n----------Ban hay chon mot trong cac thao tac duoi day -----------"
EnterNgay: .asciiz "Nhap vao ngay: "
EnterThang: .asciiz "Nhap vao thang: "
EnterNam: .asciiz "Nhap vao nam: "
LuaChon1: .asciiz "\n1. Xuat chuoi theo dinh dang: DD/MM/YYYY"
LuaChon2: .asciiz "\n2. Chuyen doi chuoi time thanh mot trong cac dinh dang sau"
DD1: .asciiz "\n A. MM/DD/YYYY"
DD2: .asciiz "\n B. Month DD, YYYY"
DD3: .asciiz "\n C. DD Month, YYYY"
LuaChon3: .asciiz "\n3. Cho biet ngay vua nhap la ngay thu may trong tuan"
LuaChon4: .asciiz "\n4. Kiem tra nam trong chuoi TIME co phai nam nhuan khong"
LuaChon5: .asciiz "\n5. Cho biet khong thoi gian giua chuoi TIME_1 va TIME_2"
LuaChon6: .asciiz "\n6. Cho biet hai nam nhuan gan nhat voi nam trong chuoi TIME"
Chon: .asciiz "\nLua chon: "
strNhuan: .asciiz "La nam nhuan"
strKNhuan: .asciiz "Khong phai la nam nhuan"
Ketqua: .asciiz "\nKet qua: "
strNamNhuanKe: .asciiz "\n2 nam nhuan ke: "
KhoangTrang: .asciiz " "
XuongDong: .asciiz "\n"
strThuTrongTuan: .asciiz "\nThu trong tuan la: "
TIME: .space 11
Week: .space 6
const1: .float 2.6
const2: .float 0.2
.text
.globl main
main:
li $v0, 4 #printf "Nhap vao ngay: "
la $a0, EnterNgay
syscall
li $v0, 5 #scan Ngay
syscall
move $s1, $v0
li $v0, 4 #print "Nhap vao thang: "
la $a0, EnterThang
syscall
li $v0, 5 #scan Thang
syscall
move $s2, $v0
li $v0, 4 #printf "Nhap vao nam: "
la $a0, EnterNam
syscall
li $v0, 5 #scan Nam
syscall
move $s3, $v0
li $v0, 4 #printf "\n----------Ban hay chon mot trong cac thao tac duoi day -----------\n"
la $a0, Menu
syscall
li $v0, 4 #printf "\n1. Xuat chuoi theo dinh dang: DD/MM/YYYY"
la $a0, LuaChon1
syscall
li $v0, 4 #printf "\n2. Chuyen doi chuoi time thanh mot trong cac dinh dang sau"
la $a0, LuaChon2
syscall
li $v0, 4
la $a0, DD1
syscall
li $v0, 4
la $a0, DD2
syscall
li $v0, 4
la $a0, DD3
syscall
li $v0, 4 #printf "3. Cho biet ngay vua nhap la ngay thu may trong tuan"
la $a0, LuaChon3
syscall
li $v0, 4 #printf "4. Kiem tra nam trong chuoi TIME co phai nam nhuan khong"
la $a0, LuaChon4
syscall
li $v0, 4 #printf "5. Cho biet khong thoi gian giua chuoi TIME_1 va TIME_2"
la $a0, LuaChon5
syscall
li $v0, 4 #printf "6. Cho biet hai nam nhuan gan nhat voi nam trong chuoi TIME"
la $a0, LuaChon6
syscall
li $v0, 4 #printf "Lua chon: "
la $a0, Chon
syscall
li $v0, 5 #scan luachon
syscall
move $t1, $v0
li $v0, 4 #printf "Ket qua: "
la $a0, Ketqua
syscall
#######----------------------------
jal Date
li $t0, 1
beq $t0, $t1 Date1
li $t0, 4
beq $t0, $t1 KTNhuan
li $t0, 6
beq $t0, $t1 NamNhuanKe
li $t0, 3
beq $t0, $t1 ThuTrongTuan
li $t0, 2
beq $t0, $t1 Convert
j EXIT
ThuTrongTuan:
jal Weekday
li $v0, 4
la $a0, strThuTrongTuan
syscall
la $a0, Week
syscall
j EXIT
KTNhuan:
jal Year
move $a0, $v1
jal LeapYear
li $t0, 1
beq $t0, $v1 Nhuan
li $v0, 4
la $a0, strKNhuan
syscall
j EXIT
Nhuan:
li $v0, 4
la $a0, strNhuan
syscall
j EXIT
Date1:
la $a0, TIME
li $v0, 4
syscall
j EXIT
Date:
addi $sp, $sp, -12
sw $t0, 0($sp)
sw $t4, 4($sp)
sw $s0, 8($sp)
move $a1, $s1
move $a2, $s2
move $a3, $s3
la $s0, TIME
# NGAY
li $t0, 10
div $a1, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 0($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 1($s0)
li $t0, 47
sb $t0, 2($s0)
# THANG
li $t0, 10
div $a2, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 3($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 4($s0)
li $t0, 47
sb $t0, 5($s0)
# NAM
li $t0, 1000
div $a3, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 6($s0)
li $t0, 100
mfhi $t4
div $t4, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 7($s0)
li $t0, 10
mfhi $t4
div $t4, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 8($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 9($s0)
lw $t0, 0($sp)
lw $t4, 4($sp)
lw $s0, 8($sp)
addi $sp,$sp, 12
jr $ra
NamNhuanKe: #2 NAM NHUAN TIEP THEO
li $v0, 4
la $a0, strNamNhuanKe
syscall
addi $sp,$sp,-16
sw $ra, 0($sp)
sw $t0, 4($sp)
sw $t1, 8($sp)
sw $t2, 12($sp)
jal Year
move $a0, $v1 # $a0 = Nam
#$t0: Dem
#$t1: Kiem Tra (1, 0)
#$t2: Dung Gan so
li $t0, 0 # Dem = 0
li $t2, 1
add, $a0, $a0, $t2
LOOPNNK:
li $t2, 2
slt $t1, $t0, $t2
beq $t1, $0 EXIT
jal LeapYear
move $t1, $v1
li $t2, 1
beq $t1, $t2 Xuat
add $a0, $a0, $t2
j LOOPNNK
Xuat:
add $t0, $t0, $t2 #Dem++
li $v0, 1
syscall
add $a0, $a0, $t2 # Nam++
move $t2, $a0
li $v0, 4
la $a0, KhoangTrang
syscall
move $a0, $t2
j LOOPNNK
LeapYear: #KIEM TRA NAM NHUAN
addi $sp,$sp,-8
sw $t1, 0($sp)
sw $t0, 4($sp)
#nam = $a0
li $t1, 400
div $a0, $t1 #nam/400
mfhi $t1 # so du
beq $0, $t1 True #neu so du = 0 goto True
li $t1, 4
div $a0, $t1 #nam/4
mfhi $t1 # so du
beq $0, $t1 LY1
Flase:
li $v1, 0 #gia tri tra ve 0
lw $t1, 0($sp)
lw $t0, 4($sp)
addi $sp,$sp,8
jr $ra
LY1:
li $t1, 100
div $a0, $t1 #nam/100
mfhi $t1 # so du
beq $t1, $0, Flase
True:
li $v1, 1 #gia tri tra ve 1
lw $t1, 0($sp)
lw $t0, 4($sp)
addi $sp,$sp,8
jr $ra
# GET NGAY
Day:
addi $sp, $sp, -12
sw $t0, 0($sp)
sw $t2, 4($sp)
sw $t3, 8($sp)
li $t0 48
li $t3 10
la $a0 TIME
lb $v1,0($a0)
sub $v1 $v1 $t0
mult $v1 $t3
mflo $t1
lb $t2 1($a0)
sub $t2 $t2 $t0
add $v1 $t1 $t2
lw $t0, 0($sp)
lw $t2, 4($sp)
lw $t3, 8($sp)
addi $sp, $sp, 12
jr $ra
# GET THANG
Month:
addi $sp, $sp, -16
sw $t0, 0($sp)
sw $t1, 4($sp)
sw $t2, 8($sp)
sw $t3, 12($sp)
li $t0 48
li $t3 10
la $a0 TIME
lb $v1, 3($a0)
sub $v1 $v1 $t0
mult $v1 $t3
mflo $t1
lb $t2 4($a0)
sub $t2 $t2 $t0
add $v1 $t1 $t2
lw $t0, 0($sp)
lw $t1, 4($sp)
lw $t2, 8($sp)
lw $t3, 12($sp)
addi $sp, $sp, 16
jr $ra
Year:
addi $sp, $sp, -32
sw $t0, 0($sp)
sw $t1, 4($sp)
sw $t2, 8($sp)
sw $t3, 12($sp)
sw $t4, 16($sp)
sw $t5, 20($sp)
sw $t6, 24($sp)
sw $t7, 28($sp)
li $t7 1000
li $t0 48
la $a0 TIME
lb $v1, 6($a0)
sub $v1 $v1 $t0
mult $v1 $t7
mflo $t1 # luu ket qua so dau tien cua nam vao $t1
lb $t2 7($a0)
sub $t2 $t2 $t0
li $t7 100
mult $t2 $t7
mflo $t3 # luu ket qua so thu 2 cua nam vao $t3
lb $t4 8($a0)
sub $t4 $t4 $t0
li $t7 10
mult $t4 $t7
mflo $t5 # luu ket qua so thu 3 cua nam vao $t5
lb $t6 9($a0)
sub $t6 $t6 $t0 # luu ket qua so thu 4 cua nam vao $t6
add $t1 $t1 $t3
add $t1 $t1 $t5
add $v1 $t1 $t6
lw $t0, 0($sp)
lw $t1, 4($sp)
lw $t2, 8($sp)
lw $t3, 12($sp)
lw $t4, 16($sp)
lw $t5, 20($sp)
lw $t6, 24($sp)
lw $t7, 28($sp)
addi $sp, $sp, 32
jr $ra
Weekday:
addi $sp,$sp,-24
sw $t0, 0($sp)
sw $t1, 4($sp)
sw $t2, 8($sp)
sw $t3, 12($sp)
sw $s0, 16($sp)
sw $ra, 20($sp)
li $s0, 0
la $a0, TIME
la $a1, Week
jal Year
move $t3, $v1 #$t3 = Nam
jal Month
move $t2, $v1 #$t2 = Thang
jal Day
move $t1, $v1 #$t1 = Ngay
li $t0, 1
beq $t0, $t2 TruNam1
li $t0, 2
beq $t0, $t2 TruNam2
j Continue
TruNam1:
li $t0, 1
sub $t3, $t3, $t0 # Nam--
li $t2, 11
j Continue
TruNam2:
li $t0, 1
sub $t3, $t3, $t0 # Nam--
li $t2, 12
Continue:
li $t0, 7
div $t1, $t0
mfhi $s0 # $t1 ranh
l.s $f0, const1
l.s $f1, const2
li $t0, 2
sub $t2, $t2, $t0 # Thang - 2
li $t0, 12
div $t2, $t0
mfhi $t2 # $t2 = (Thang-2) mod 12
mtc1 $t2, $f2 #$t2 ranh || $f2 = $t2
cvt.s.w $f3, $f2 #int -> float($f3)
mul.s $f2, $f3, $f0 #$f2 = $t2*2.6
sub.s $f2, $f2, $f1 #$f2 = $f2 - 0.2
cvt.w.s $f3, $f2 #float -> int($f3)
mfc1 $t2, $f3 #$t2 = $f3 = 2.6 * (Thang-2) mod 12 - 0.2
li $t0, 7
div $t2, $t0
mfhi $t2
add $s0, $s0, $t2
li $t0, 100
div $t3, $t0 #Nam/100
mfhi $t1 #Nam mod 100
li $t0, 4
mult $t0, $t1
mflo $t1
li $t0, 7
div $t1, $t0
mfhi $t1
add $s0, $s0, $t1
li $t0, 400
div $t3, $t0
mfhi $t1 #Nam mod 400
li $t0, 6
mult $t0, $t1
mflo $t1
li $t0, 7
div $t1, $t0
mfhi $t1
add $s0, $s0, $t1
li $t0, 1000
div $t3, $t0
mflo $t1
mfhi $t2
li $t0, 10
mult $t1, $t0
mflo $t1
li $t0, 100
div $t2, $t0
mflo $t0
mfhi $t2 # $t2 = 2 so cuoi cua nam
add $t1, $t1, $t0 # $t1 = 2 so dau cua nam
li $t0, 4
div $t1, $t0
mfhi $t1
li $t0, 5
mult $t1, $t0
mflo $t1
li $t0, 7
div $t1, $t0
mfhi $t1
add $s0, $s0, $t1
li $t0, 4
div $t2, $t0
mfhi $t1
li $t0, 5
mult $t1, $t0
mflo $t1
li $t0, 7
div $t1, $t0
mfhi $t1
add $s0, $s0, $t1
li $t0, 7
div $t2, $t0
mfhi $t1
li $t0, 3
mult $t1, $t0
mflo $t1
li $t0, 7
div $t1, $t0
mfhi $t1
add $s0, $s0, $t1
li $t0, 7
div $s0, $t0
mfhi $s0
#####################
beq $s0, $0 L0
li $t0, 1
beq $s0, $t0 L1
li $t0, 2
beq $s0, $t0 L2
li $t0, 3
beq $s0, $t0 L3
li $t0, 4
beq $s0, $t0 L4
li $t0, 5
beq $s0, $t0 L5
li $t0, 6
beq $s0, $t0 L6
L0: #Sun
li $t0, 'S'
sb $t0, 0($a1)
li $t0, 'u'
sb $t0, 1($a1)
li $t0, 'n'
sb $t0, 2($a1)
j End
L1:
li $t0, 'M'
sb $t0, 0($a1)
li $t0, 'o'
sb $t0, 1($a1)
li $t0, 'n'
sb $t0, 2($a1)
j End
L2:
li $t0, 'T'
sb $t0, 0($a1)
li $t0, 'u'
sb $t0, 1($a1)
li $t0, 'e'
sb $t0, 2($a1)
li $t0, 's'
sb $t0, 3($a1)
j End
L3:
li $t0, 'W'
sb $t0, 0($a1)
li $t0, 'e'
sb $t0, 1($a1)
li $t0, 'd'
sb $t0, 2($a1)
j End
L4:
li $t0, 'T'
sb $t0, 0($a1)
li $t0, 'h'
sb $t0, 1($a1)
li $t0, 'u'
sb $t0, 2($a1)
li $t0, 'r'
sb $t0, 3($a1)
li $t0, 's'
sb $t0, 4($a1)
j End
L5:
li $t0, 'F'
sb $t0, 0($a1)
li $t0, 'r'
sb $t0, 1($a1)
li $t0, 'i'
sb $t0, 2($a1)
j End
L6:
li $t0, 'S'
sb $t0, 0($a1)
li $t0, 'a'
sb $t0, 1($a1)
li $t0, 't'
sb $t0, 2($a1)
End:
lw $t0, 0($sp)
lw $t1, 4($sp)
sw $t2, 8($sp)
lw $t3, 12($sp)
lw $s0, 16($sp)
lw $ra, 20($sp)
addi $sp,$sp, 24
jr $ra
Convert:
addi $sp, $sp, -16
sw $t0, 0($sp)
sw $t4, 4($sp)
sw $s0, 8($sp)
sw $s4, 12($sp)
move $a1, $s1
move $a2, $s2
move $a3, $s3
la $s0, TIME
#ChuyenDoiChuoi:
li $v0, 4
la $a0, DD1
syscall
li $v0, 4
la $a0, DD2
syscall
li $v0, 4
la $a0, DD3
syscall
li $v0, 4 #printf "Lua chon: "
la $a0, Chon
syscall
li, $v0, 12 #scanf lucchon
syscall
move $s4, $v0
li $t0, 'A'
bne $s4, $t0, DinhDang2
move $a1, $s1
move $a2, $s2
move $a3, $s3
la $s0, TIME
# NGAY
li $t0, 10
div $a1, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 0($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 1($s0)
li $t0, 47
sb $t0, 2($s0)
# THANG
li $t0, 10
div $a2, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 3($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 4($s0)
li $t0, 47
sb $t0, 5($s0)
# NAM
li $t0, 1000
div $a3, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 6($s0)
li $t0, 100
mfhi $t4
div $t4, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 7($s0)
li $t0, 10
mfhi $t4
div $t4, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 8($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 9($s0)
li $v0, 4
la $a0, XuongDong
syscall
la $a0, TIME
li $v0, 4
syscall
lw $t0, 0($sp)
lw $t4, 4($sp)
lw $s0, 8($sp)
lw $s4, 12($sp)
addi $sp, $sp, 16
j EXIT
DinhDang2:
li $t0, 'B'
bne $s4, $t0, DinhDang3
move $a1, $s1
move $a2, $s2
move $a3, $s3
la $s0, TIME
# NGAY
li $t0, 10
div $a1, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 3($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 4($s0)
li $t0, 44
sb $t0, 5($s0)
li $t0, 32
sb $t0, 6($s0)
# THANG
li $t0, 10
div $a2, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 0($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 1($s0)
li $t0, 32
sb $t0, 2($s0)
# NAM
li $t0, 1000
div $a3, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 7($s0)
li $t0, 100
mfhi $t4
div $t4, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 8($s0)
li $t0, 10
mfhi $t4
div $t4, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 9($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 10($s0)
li $v0, 4
la $a0, XuongDong
syscall
la $a0, TIME
li $v0, 4
syscall
lw $t0, 0($sp)
lw $t4, 4($sp)
lw $s0, 8($sp)
lw $s4, 12($sp)
addi $sp, $sp, 16
j EXIT
DinhDang3:
li $t0, 'C'
bne $s4, $t0, EXIT
move $a1, $s1
move $a2, $s2
move $a3, $s3
la $s0, TIME
# NGAY
li $t0, 10
div $a2, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 3($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 4($s0)
li $t0, 44
sb $t0, 5($s0)
li $t0, 32
sb $t0, 6($s0)
# THANG
li $t0, 10
div $a1, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 0($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 1($s0)
li $t0, 32
sb $t0, 2($s0)
# NAM
li $t0, 1000
div $a3, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 7($s0)
li $t0, 100
mfhi $t4
div $t4, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 8($s0)
li $t0, 10
mfhi $t4
div $t4, $t0
mflo $t4
addi $t0, $t4, 48
sb $t0, 9($s0)
mfhi $t4
addi $t0, $t4, 48
sb $t0, 10($s0)
li $v0, 4
la $a0, XuongDong
syscall
la $a0, TIME
li $v0, 4
syscall
lw $t0, 0($sp)
lw $t4, 4($sp)
lw $s0, 8($sp)
lw $s4, 12($sp)
addi $sp, $sp, 16
j EXIT
EXIT:
li $v0,10
syscall