错误#14:尝试写入只读存储器Mips Assembly

时间:2015-05-04 01:25:24

标签: assembly mips

board_one:
    .space 3600

board_two:
    .space 3600

        set_boards:
        addi    $sp, $sp,-16    
        sw  $ra, 0($sp)
        sw  $s0, 4($sp)
        sw  $s1, 8($sp)
        sw  $s2, 12($sp)

        move    $s4, $s0
        la  $s0, board_one
        la  $s1, board_two
        li  $s2, 0
        mul $s3, $s4, $s4
        jal     set_zero_loop

        lw  $ra, 0($sp)
        lw  $s0, 4($sp)
        lw  $s1, 8($sp)
        lw  $s2, 12($sp)
        addi    $sp, $sp, 16

        jr  $ra

    set_zero_loop:
        beq $s2, $s3, done_looping
        li  $v0, PRINT_INT  # print generation counter
        move    $a0, $s2
        syscall 

        li  $s4, 5

        sw  $s4, 0($s0)
        sw  $s4, 0($s1)
        addi    $s1, $s1, 4
        addi    $s0, $s0, 4
        addi    $s2, $s2, 1
        j   set_zero_loop


    done_looping:
        jr  $ra

当我尝试sw时,我的问题就出现了。说我试着写只读内存?真的很困惑。我将数组的地址放入寄存器然后尝试迭代它们

    Error #14:  Attempted write to read-only memory

Fault address:  0040203c

Register contents:

 $zero: 00000000   $at: 00000000   $v0: 00000001   $v1: 00000000
   $a0: 00000000   $a1: 7fffeb8c   $a2: 00000000   $a3: 00000000
   $t0: 00000019   $t1: 00000000   $t2: 00000000   $t3: 00000000
   $t4: 00000000   $t5: 00000000   $t6: 00000000   $t7: 00000000
   $s0: 00400000   $s1: 00400e10   $s2: 00000000   $s3: 00000019
   $s4: 00000005   $s5: 00000000   $s6: 00000000   $s7: 00000000
   $t8: 00000000   $t9: 00000000   $k0: 00000000   $k1: 00000000
   $gp: 00000000   $sp: 7fffeae0   $fp: 00000000   $ra: 00402010
    pc: 00402040    hi: 00000000    lo: 00000019

Current instruction:    ae140000 (at 0040203c)

Decoded instruction:  sw    $s4, 0($s0) (0x400000)

有人帮忙我不知道为什么我不能在这里说一句话。

1 个答案:

答案 0 :(得分:0)

原来我有这个

    board_one:
    .space 3600

board_two:
    .space 3600

更改为

    .data
board_one:
    .space 3600
.text

.data
board_two:
    .space 3600
.text

正确分配空间,以便在运行时尝试写入程序。