Files
2024-05-03 23:57:11 +08:00

43 lines
1.4 KiB
NASM

.data
file_buff: .space 8 # A space of 2 bytes
.align 3
input_file_name: .asciiz "a.in"
.align 3
output_file_name: .asciiz "a.out"
.align 3
.text
la $a0, input_file_name
li $a1, 0 # set mode as read
li $a2, 0 # meaning nothing, really
li $v0, 13 # open file
syscall #now $v0 is the file handler
move $a0, $v0 #move file handler to a0 as first syscall arg
la $a1, file_buff
li $a2, 8 # read in 8 bytes
li $v0, 14
syscall
li $v0, 16
syscall # close file
la $a0, output_file_name
li $a1, 1 # set mode as write
li $a2, 0 # meaning nothing, really
li $v0, 13 # open file
syscall
move $a0, $v0
la $a1, file_buff
li $a2, 8 # write 8 bytes
li $v0, 15 # write file
syscall
li $v0, 16
syscall
li $v0, 5 # read integer
syscall
addi $a0, $v0, 10 # a0 = v0 + 10
li $v0, 1 # print integer
syscall