-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex12_a.asm
96 lines (79 loc) · 1.89 KB
/
ex12_a.asm
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
95
96
.eqv print_string, 4
.eqv read_integer, 5
.eqv read_string, 8
.eqv read_float, 6
.eqv stidof, 0
.eqv stfnof, 4
.eqv stlnof, 22
.eqv stgrof, 40
.eqv stmxfn, 17
.eqv stmxln, 16
.eqv MAX_STUDENTS, 4
.data
st_arr: .space 176 # 44 x 4 elementos
str1: .asciiz "N. Mec: "
str2: .asciiz "Primeiro Nome: "
str3: .asciiz "Ultimo Nome: "
str4: .asciiz "Nota: "
.text
.globl main
read_data: # $s2 - i Recebe em $a0 - ponteiro para o início do array de estruturas e no $a1 o numero de elementos desse array
move $s0,$a0
move $s1,$a1
li $s2,0 # i=0
f_rd: bge $s2,$s1, end_f_rd # i<ns
la $a0,str1 # le id
li $v0,print_string
syscall
move $t0,$s0
li $t2,44 # sizeof(student)
mul $t2, $s2, $t2 # i * sizeof(student)
addu $t0, $t0, $t2 # endereco inicial da instancia i do array de estruturas st_arr
li $v0, read_integer
syscall
sw $v0, stidof($t0)
la $a0,str2 # le fn
li $v0,print_string
syscall
move $t0,$s0
li $t2,44 # sizeof(student)
mul $t2, $s2, $t2 # i * sizeof(student)
addu $t0, $t0, $t2 # endereco inicial da instancia i do array de estruturas st_arr
addiu $a0,$t0,stfnof
li $a1,stmxfn
li $v0,read_string
syscall
la $a0,str3 # le ln
li $v0,print_string
syscall
move $t0,$s0
li $t2,44 # sizeof(student)
mul $t2, $s2, $t2 # i * sizeof(student)
addu $t0, $t0, $t2 # endereco inicial da instancia i do array de estruturas st_arr
addiu $a0,$t0,stlnof
li $a1,stmxln
li $v0,read_string
syscall
la $a0,str4 # le grade
li $v0,print_string
syscall
move $t0,$s0
li $t2,44 # sizeof(student)
mul $t2, $s2, $t2 # i * sizeof(student)
addu $t0, $t0, $t2 # endereco inicial da instancia i do array de estruturas st_arr
li $v0, read_float
syscall
s.s $f0, stgrof($t0)
addi $s2,$s2,1 # i++
j f_rd
end_f_rd:
jr $ra
####### MAIN ######
main: addiu $sp,$sp,-4
sw $ra,0($sp)
la $a0, st_arr
li $a1, MAX_STUDENTS
jal read_data
lw $ra,0($sp)
addiu $sp,$sp,4
jr $ra