Note that there are some explanatory texts on larger screens.

plurals
  1. POLearning MIPS assembly: read text and write to file
    primarykey
    data
    text
    <p>I'm trying to write simple program in MIPS assembly language. What i'm trying to do is read multiple characters from keyboard and save its to file. I'm creating file with 13 opcode and saving characters with 15 opcode. I don't understand: how to dynamically assign number of characters to write in $a2 for 15 opcode (line 37, now hardcoded). Also I can't figure out how to print numbers of characters written to my file ($v0 contains this value after writting to file, line 49).</p> <p>Now program is throwing error: line 49: Runtime exception at 0x00400078: address out of range 0x0000002c</p> <p>Here is my code:</p> <pre><code>.data handle_text: .space 100 # buffor of 100 characters, bits, bytes? out_file: .asciiz "file_out.txt" # out file asklabel: .asciiz "\Please enter string to save\n" countlabel: .asciiz "\Characters typed:\n" .text main: la $a0, asklabel # text to print li $v0, 4 # opcode syscall la $a0, handle_text # Where to put text la $a1, handle_text # Number of characters to write li $v0, 8 # opcode syscall li $v0, 13 # system call for open file la $a0, out_file # output file name li $a1, 1 # Open for writing (flags are 0: read, 1: write) li $a2, 0 # mode is ignored syscall # open a file (file descriptor returned in $v0) move $s6, $v0 # save the file descriptor move $a0, $s6 # file handle la $a1, handle_text # text to print #line 37 li $a2, 44 # TEXT LENGTH li $v0, 15 # opcode syscall move $t1, $v0 # move v0 to t1 so v0 won't be overwritten la $a0, countlabel # show text li $v0, 4 # op code syscall move $a0, $t1 # place characters amount in $a0 li $v0, 4 # opcode syscall # ERROR. Maybe it's becouse string should be null terminated? li $v0, 16 # system call for close file move $a0, $s6 # file descriptor to close syscall # close file li $v0, 10 # close app syscall </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload