MIPS Assembly: how to know if user inputted values are correctly stored into an array

DjokovicFan
.data
      array: .word 0:5
      prompt1: .asciiz "enter number: "
      newline: .asciiz "\n"
.text

      add $t2,$zero,$zero       # initializes counter to 0
      la $s0, array     # stores the beginning of array into $s0

secretcode:

      li $v0, 4                 # prints "enter number: "   
      la $a0, prompt1
      syscall

      li $v0, 5                 # reads in user input
      syscall
      sw $v0, ($s0)     # saves user input into address at $s0
      addi $s0, $s0, 4          # increments address at $s0 by 4 bytes

      addi $t2, $t2, 1          # increments counter by 1
      bne $t2, 5, secretcode    # stops loop when loop executes 5 times 

printsecretcode:

      lw $a0, ($s0)         # print first element
      li $v0, 1
      syscall

      li $v0, 10                # system code halt
      syscall

The program is supposed to store 5 user inputted numbers into an array. I tried to print the first value but it comes up as a large number which I assume is an address. How would I print the actual value of the number so that I know it saved correctly?

Michael

By the time you reach your printing code $s0 contains the address array + 4*5, so what you end up printing is the 32-bit number formed by the first four characters of the "enter number: " string.

To fix this, add an la $s0, array before you try to print the first element.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to store a string that the user inputted into a char pointer instead of a char array

From Dev

How to loop user input until an integer is inputted?

From Dev

sorting array in mips (assembly)

From Dev

MIPS Assembly language traversing an array

From Dev

How to declare a (multi-dimensional) array with value inputted by the user?

From Dev

How to load assembly correctly

From Dev

MIPS assembly string array

From Dev

How to fill an array with values inputted from one text box in C#

From Dev

How to handle apostophes in user inputted String?

From Dev

How can I TryParse() a string inputted by the user?

From Dev

How does Python know the values already stored in its memory?

From Dev

How to initialise a huge array in MIPS assembly?

From Dev

MIPS assembly string array

From Dev

How to replace user inputted ^ with **?

From Dev

Assembly - Copying an array of bytes - MIPS

From Dev

How can I TryParse() a string inputted by the user?

From Dev

Problems with sum of user-inputted array elements

From Dev

How do I convert stored hexa number array to decimal with MIPS?

From Dev

Assembly language-How to make two inputted number as one?

From Dev

How to fill an array , print it and sort it with bubble sort MIPS assembly

From Dev

How to get the prediction at a value that inputted from user?

From Dev

How are values stored in array methods?

From Dev

How to compare stored strings with inputted strings-MIPS

From Dev

Manipulating/Printing a user inputted array in java

From Dev

How to correctly save the values of a multidimensional array into an array?

From Dev

How to split the string inputted by user

From Dev

how to sort a user-inputted list

From Dev

How to deal with user inputted logarithmic equations in Python

From Dev

MIPS Manipulating array stored in data

Related Related

  1. 1

    How to store a string that the user inputted into a char pointer instead of a char array

  2. 2

    How to loop user input until an integer is inputted?

  3. 3

    sorting array in mips (assembly)

  4. 4

    MIPS Assembly language traversing an array

  5. 5

    How to declare a (multi-dimensional) array with value inputted by the user?

  6. 6

    How to load assembly correctly

  7. 7

    MIPS assembly string array

  8. 8

    How to fill an array with values inputted from one text box in C#

  9. 9

    How to handle apostophes in user inputted String?

  10. 10

    How can I TryParse() a string inputted by the user?

  11. 11

    How does Python know the values already stored in its memory?

  12. 12

    How to initialise a huge array in MIPS assembly?

  13. 13

    MIPS assembly string array

  14. 14

    How to replace user inputted ^ with **?

  15. 15

    Assembly - Copying an array of bytes - MIPS

  16. 16

    How can I TryParse() a string inputted by the user?

  17. 17

    Problems with sum of user-inputted array elements

  18. 18

    How do I convert stored hexa number array to decimal with MIPS?

  19. 19

    Assembly language-How to make two inputted number as one?

  20. 20

    How to fill an array , print it and sort it with bubble sort MIPS assembly

  21. 21

    How to get the prediction at a value that inputted from user?

  22. 22

    How are values stored in array methods?

  23. 23

    How to compare stored strings with inputted strings-MIPS

  24. 24

    Manipulating/Printing a user inputted array in java

  25. 25

    How to correctly save the values of a multidimensional array into an array?

  26. 26

    How to split the string inputted by user

  27. 27

    how to sort a user-inputted list

  28. 28

    How to deal with user inputted logarithmic equations in Python

  29. 29

    MIPS Manipulating array stored in data

HotTag

Archive