0% found this document useful (0 votes)
6 views2 pages

Mip 3 A

Uploaded by

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

Mip 3 A

Uploaded by

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

Bai03.a.

asm -1- November 15, 2024 2:06 PM

1: .data
2: array: .space 400 # Cap phat mang chua 100 phan tu (4 bytes/phan tu)
3: size: .word 100
4: length: .asciiz "Nhap n: "
5: inputArray: .asciiz "Nhap mang: \n"
6: inputElement: .asciiz "+ Nhap phan tu: "
7: minElement: .asciiz "Phan tu nho nhat: "
8: maxElement: .asciiz "\nPhan tu lon nhat: "
9: sum: .asciiz "\nTong cac phan tu = "
10: space: .asciiz " "
11: .text
12: main:
13: li $v0, 4
14: la $a0, length
15: syscall
16: li $v0, 5
17: syscall
18: sw $v0, size
19: la $t0, array
20: lw $t1, size
21: sll $t2, $t1, 2
22: add $t2, $t2, $t0
23: li $v0, 4
24: la $a0, inputArray
25: syscall
26: inputLoop:
27: bge $t0, $t2, process
28: li $v0, 4 # Hien yeu cau nhap phan tu
29: la $a0, inputElement
30: syscall
31: li $v0, 5
32: syscall # Nhap phan tu
33: sw $v0, ($t0) # Luu phan tu vao mang
34: addi $t0, $t0, 4
35: j inputLoop
36:
37: process:
38: la $t0, array
39: lw $t1, size
40: sll $t6, $t1, 2
41: add $t6, $t6, $t0
42: lw $t2, ($t0) # Khoi tao min = array[0]
43: lw $t3, ($t0) # Khoi tao max = array[0]
44: lw $t4, ($t0) # Khoi tao tong = array[0]
45: addi $t0, $t0, 4 # Con tro tro toi array[1] ($t0 chua dia chi array[1])
46: processLoop:
47: bge $t0, $t6, Print
48: lw $t5, ($t0) # Lay gia tri tai con tro array[]
49: add $t4, $t4, $t5 # Tinh tong = tong + array[]
50: checkMax: # Kiem tra array[] > max khong
51: bgt $t5, $t3, updateMax
Bai03.a.asm -2- November 15, 2024 2:06 PM

52: j checkMin
53: updateMax: # Cap nhan max moi
54: add $t3, $0, $t5
55: checkMin: # Kiem tra array[] < min khong
56: blt $t5, $t2, updateMin
57: j next
58: updateMin: # Cap nhat min moi
59: add $t2, $0, $t5
60: next:
61: addi $t0, $t0, 4 # Do doi cua mang
62: j processLoop
63: Print:
64: li $v0, 4
65: la $a0, minElement
66: syscall
67: li $v0, 1
68: move $a0, $t2
69: syscall # Xuat gia tri min ra man hình
70: li $v0, 4
71: la $a0, maxElement
72: syscall
73: li $v0, 1
74: move $a0, $t3
75: syscall # Xuat gia tri max ra man hình
76: li $v0, 4
77: la $a0, sum
78: syscall
79: li $v0, 1
80: move $a0, $t4
81: syscall
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:

You might also like