Answer:
Macros: Trying this .
.data
.macro print_int(%x)
li $v0,1
li. $a0,%x
syscall
.end_macro
.macro print_string(%s)
li $v0,4
li $a0,%s
syscall
.end_macro
.macro print_character(%c)
.li $v0,'1'
.li $a0,%c
syscall
.end_macro
fin: .asciiz "l.dat"
buffer: .asciiz 1024 ""
.macro open_file(fin)
.li $v0,13
.la $a0,fin
.li $a1,0
.li $a2,0
syscall
move $s6,$v0
.end_macro
.macro read_file(fin)
.$v0,14
move $a0,$s6
.la $a1,buffer
.li $a3,1024
syscall
.end_macro
.macro close_file(fin)
.li $v0,16
move $a0,$s6
syscall
.end_macro
_main:
print_string("Hello")
loop:
la $a0,print_string("enter filename")
li $v0,4
read:
beq $v0,$zero,read
open:
la $a0,open_file(fin)
li $v0,4
beq $v0,$zero,exit
end_loop:
exit:
li $v0,10
syscall
Hope this helps.By using all the macros as used for open_file along with $a(1--10),$v(1--10), we can easily do all functionality.