samedi 11 juillet 2015

MIPS Reading Input File and Random Number Generator

I'm currently stuck on a project using MIPS assembly language. I'm trying to randomly select alphabet characters from a text file that contains all the lower-case letters of the alphabet. What is the best way for me to randomly select a character from the file in MIPS? So far my code opens an input file and reads it, but I am confused on how to pick a random character from the file. I used the pseudo-random number generator to get a random number and was going to use that to pick a character somehow. How can I know where the characters are in the file and select them? I've been reading a lot of books on MIPS, but none of them seem to have anything explaining this. Please help. I will post part of my code below:

.data
input_file: .asciiz "alphabet.txt"  #input file name
buffer: .space 1024
.txt
main:
jal random
jal read_file

read_file:
#opens input file
li $v0, 13  
la $a0, input_file
li $a1, 0   
li $a2, 0   
syscall     
move $s0, $v0   
#read from file
li $v0, 14  
move $a0, $s0   
la $a1, buffer  
li $a2, 1024    
#close the file
li $v0, 16  
move $a0, $s0   
syscall

random: 
#pseudorandom number generator (0-26)
sw $a0, 0($s1)
li $a1, 26  
li $v0, 42  
move $s2, $a0   




Aucun commentaire:

Enregistrer un commentaire