Read from file hexadecimal number and change their representation style
- by user576844
I want to write a program changing the notation of all hexadecimal numbers found in an assembly source file from traditional (h) to C-style (0x).
I have started the coding part but am not sure how can I detect the hexadecimal numbers and eventually change the style and save it back in the file...
I have started writing the program..
## Mips program -
.data
fin: .ascii "" # filename for input
msg0: .asciiz "aaaa"
msg1: .asciiz "Please enter the input file name:"
buffer: .asciiz ""
.text
#-----------------------
li $v0, 4
la $a0, msg1
syscall
li $v0, 8
la $a0, fin
li $a1, 21
syscall
jal fileRead #read from file
move $s1, $v0 #$t0 = total number of bytes
li $t0, 0 # Loop counter
loop:
bge $t0, $s1, end #if end of file reached OR if there is an error in the file
lb $t5, buffer($t0) #load next byte from file
jal checkhexa #check for hexadecimal numbers
addi $t0, $t0, 1 #increment loop counter
j loop
end:
jal output
jal fileClose
li $v0, 10
syscall
fileRead:
# Open file for reading
li $v0, 13 # system call for open file
la $a0, fin # input file name
li $a1, 0 # flag for reading
li $a2, 0 # mode is ignored
syscall # open a file
move $s0, $v0 # save the file descriptor
# reading from file just opened
li $v0, 14 # system call for reading from file
move $a0, $s0 # file descriptor
la $a1, buffer # address of buffer from which to read
li $a2, 100000 # hardcoded buffer length
syscall # read from file
jr $ra
Any help would be appreciated.