Reputation: 2957
In assembly, is there a way to store an input from the user as string into a .asciiz instead of .word?
I know sw and lw but how to do it with .asciiz?
Thanks
UPDATE:
I had to remove my code snippet, because it's a full program for an Assignment.
As you see, this is the application I'm trying to make, when the program read the filename from the user which is stored in userInput
I cannot execute option processImage
, but I use myInput2
which already has the name of my image file I want to read, processImage
will work just fine.
Upvotes: 1
Views: 8731
Reputation: 58762
sw
and lw
are runtime instructions while .asciiz
is a compile time assembler directive.
You can use .asciiz
to allocate space for the user input if you want, but you still need to fill it at runtime, for example by reading characters in a loop and storing them using sb
or using read string
or similar system call if you have one.
The .asciiz
is just syntactical sugar to make it easier to store strings, it's equivalent to specifying a bunch of bytes, just that you don't have to manually figure out the values.
.asciiz "a"
is the same as .byte 97, 0
.
Update
li $a1, 6 # length
la $a0, str1 # buffer
li $v0, 8 # read string call number
syscall
.data
str1: .byte 0, 0, 0, 0, 0, 0
str2: .word 0, 0, 0
str3: .space 6
.comm str4, 6
str5: .asciiz "12345"
The above str1
through str5
are all equivalent except that str5
isn't initialized to all zeroes. You can use any of those on the la $a0
line.
Upvotes: 1