0% found this document useful (0 votes)
16 views4 pages

KTMT

Uploaded by

Cú Cú
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

KTMT

Uploaded by

Cú Cú
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

.

data
string0: .asciiz "Nhap a: "
string1: .asciiz "Nhap b: "
string2: .asciiz "Nhap c: "
string3: .asciiz "Nhap d: "
string4: .asciiz "Nhap e: "
string5: .asciiz "Nhap f: "
strKetQua: .asciiz "Ket qua phep tinh la: "
.text
main:
#Nhap vao 6 so nguyen
li $v0, 4
la $a0, string0
syscall
li $v0, 5
syscall
add $s0, $v0, $0

li $v0, 4
la $a0, string1
syscall
li $v0, 5
syscall
add $s1, $v0, $0

li $v0, 4
la $a0, string2
syscall
li $v0, 5
syscall
add $s2, $v0, $0

li $v0, 4
la $a0, string3
syscall
li $v0, 5
syscall
add $s3, $v0, $0

li $v0, 4
la $a0, string4
syscall
li $v0, 5
syscall
add $s4, $v0, $0

li $v0, 4
la $a0, string5
syscall
li $v0, 5
syscall
add $s5, $v0, $0

# Gan gia tri cua c, d, e, f vao cac thanh ghi $a0, $a1, $a2, $a3 de truyen vao ham
add $a0, $s2, $0
add $a1, $s3, $0
add $a2, $s4, $0
add $a3, $s5, $0
jal proc_example #Thuc hien goi ham tinh toan

# Xuat ra ket qua


li $v0, 4
la $a0, strKetQua
syscall
addi $v0, $0, 1
add $a0, $s6, $0
syscall
j exit # Thoat chuong trinh

proc_example: # Dinh nghia ham tinh toan


# Luu cac gia tri cua $s0, $s1 vao Stack
addi $sp, $sp, -4
sw $s0, 0($sp)
addi $sp, $sp, -4
sw $s1, 0($sp)

# Thuc hien tinh toan


add $t0, $s0, $s1
add $t1, $a0, $a1
sub $t0, $t0, $t1
add $t1, $a2, $a3
sub $t0, $t0, $t1
add $s6, $t0, $0

# Khoi phuc gia tri cua $s0, $s1


lw $s1, 0($sp)
addi $sp, $sp, 4
lw $s0, 0($sp)
addi $sp, $sp, 4

# Quay lai chuong trinh de tiep tuc thuc hien cac lenh phia sau lenh goi ham
proc_example
jr $ra
exit:

You might also like