×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

sw $rs, imm($rx) (store word)

sw $rs, imm($rx) (store word)

sw $rs, imm($rx) (store word)

(OP)
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!

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close