2

How can I declare a string variable without initialization in MIPS assembly? And then it receives an amount from the user.

For example: string judge;

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Amin
  • 241
  • 2
  • 11

1 Answers1

1

By using the .space directive to reserve some space:

.data
foo: .space 100  # Reserve 100 bytes of space

.text
la $a0, foo      # Load the address of foo
# Do whatever
Michael
  • 57,169
  • 9
  • 80
  • 125
  • Thanks dear Michael. And how can make it to read the string from keyboard, I am a little bit confused. – Amin Oct 30 '15 at 06:33
  • You would use [one of the available system calls](https://www.doc.ic.ac.uk/lab/secondyear/spim/node8.html) to do so. In this case, number 8. – Michael Oct 30 '15 at 06:38
  • Thanks. Is there any way to print a new line in MIPS? – Amin Oct 30 '15 at 07:50
  • Print the string `13, 10, 0`. Or `.asciiz "\r\n"` if QtSpim recognizes those escape characters. – Michael Oct 30 '15 at 07:52
  • 13 is Carriage Return, 10 is Line Feed, and 0 is the null terminator. so `.byte 13, 10, 0` is the same thing as `.asciiz "\r\n"`. Use whichever of them your assembler supports. – Michael Oct 30 '15 at 08:06
  • thanks dear Michael. I want to have a string variable with value: stringName: .word "string" -------------- but it doen't work? how can I initialize a string variable in data section of the code? – Amin Oct 30 '15 at 08:38
  • `.word` is for 32-bit data. use `.asciiz` or `.ascii`. `.byte` might also work. – Michael Oct 30 '15 at 08:49
  • That's a completely different problem, and should be posted as a separate question. – Michael Oct 30 '15 at 12:29
  • Dear Michael, I have limitation in asking question. So I cannot ask anymore. Please answer me here. – Amin Oct 30 '15 at 14:27
  • how can do floor and ceil function in MIPS assembly? – Amin Oct 30 '15 at 17:39
  • Again, that should be posted as a separate question. If you're not allowed to post any more questions right now you'll just have to wait, and try to research your problem yourself in the meantime. And try to put more effort into future questions, to avoid being further restricted in the number of questions you can ask. – Michael Oct 30 '15 at 17:44
  • This is feeling more and more like a homework assignment. – David Hoelzer Oct 30 '15 at 18:50