mayio
Programmer
- Feb 24, 2009
- 1
Hi to you all...!
I am new to assembly, and I have a small problem with sw(store)
I can't figure how is the proper use of this instruction. I want to store the integer I've read to an array of integers.
My code follows, I get an 'Exception 7 [Bad data address] occured and ignored' in sw $19, 16($10) # STORES
How should I declare sw(at the end of the code)???
thank you in advance!
I am new to assembly, and I have a small problem with sw(store)
I can't figure how is the proper use of this instruction. I want to store the integer I've read to an array of integers.
My code follows, I get an 'Exception 7 [Bad data address] occured and ignored' in sw $19, 16($10) # STORES
How should I declare sw(at the end of the code)???
thank you in advance!
Code:
# register $7 : .,.,.,.,
# register $16: Array Start Address
# register $17: i
# register $18: j
# register $19: tmp
# register $20: tmp2
# register $26: 8, The number of the values
# register $27: 1
# register $28: x
.data
.align 2
Array1: .space 32 #Array1 can store 8 integers(each 4 bytes)
str_n: .asciiz "Dwse enan akeraio!"
str_ln: .asciiz "\n"
str_sp: .asciiz " "
str_hyphen: .asciiz "---------------------"
.text # program memory:
.globl main # label "main" must be global;
# default trap.handler calls main.
.globl label_a #
.globl label_b #
main:
addi $26, $0, 8 # initialize the number of values inserting
la $15, Array1 # pseudo-instruction: starting address of array
add $17, $0, $0 # initialize i=0
label1:
# (1) PRINT A PROMPT
addi $2, $0, 4 # system call code for print_string
la $4, str_n # pseudo-instruction: address of string
syscall # print the str_n string
# (2) READ n
addi $2, $0, 5 # system call code for read int
syscall # Read a line containing an integer
add $19, $2, $0 # copy returned int from $2 to tmp($19)
# (3) print a line
add $2, $0, 4
la $4, str_ln
syscall
# (4) PRINT n
addi $2, $0, 1
add $4, $0, $19
syscall
# (5) STORE INTEGER INTO ARRAY
sw $19, 16($10) # STORES
addi $16, $16, 4 #move 4 bytes...
j label1