PCSPIM - declaring an array of strings

In summary, the conversation discusses declaring integers and strings in memory and how to properly represent them in an assembler context. The most important factor is that the final representation in memory is accurate, and there are multiple ways to specify this. The conversation concludes with the successful implementation of a string array using the .asciiz format.
  • #1
magneto202
2
0
Hey all,

So declaring integers successively in memory (using .word) in an array is all well and understandable. Since an integer is 4 bytes in length, as is a memory word.
For example:

.data
x: .word 2, -13, 24, 123 #initialization of elements 0 to 3 of array x

However, how would I go about declaring an array of strings that are three characters long in memory?

would i use:

.data
stringArray: .asciiz "the", "dog", "run"

or perhaps:

.data
stringArray: .word 't''h''e', 'd''o''g', 'r''u''n'

thanks in advance
 
Technology news on Phys.org
  • #2
Hey magneto202 and welcome to the forums.

In terms of what the computer understands, and given that this is in an assembler context (correct me if I'm wrong), then the only thing that matters is the value of the data being correct and not how its represented.

If you know that the data is represented in a format (like say 8-bit ASCII) and you know the string and character representations work then I can't see why you wouldn't use this.

The important thing is that the definition and its representation in memory are the same.

Also you need to consider the functions that use the data (which I'm assuming are probably some kind of interrupt), but again I'm going to speculate and say that the data definitions will create the right kind of representations.

Alternatively if you need a specific representation, you can never go wrong with specifying a block by block representation in a per byte, or per word description of contiguous data, but the point of having multiple specifications is that the assembler does this for you anyway.

Bottom line: it doesn't matter as long the final representation in memory is right (and you can specify the same thing in many different ways).
 
  • #3
Excellent. have remained with the declaration of:

Nstart: .asciiz "the","dog","run"

and has worked successfully for my simulation implementation. The string array addressing in memory is consistent when I try access byte by byte.

Thanks chiro for the input.
 

FAQ: PCSPIM - declaring an array of strings

1. What is PCSPIM and how is it related to declaring an array of strings?

PCSPIM is a simulator for the MIPS assembly language, used for educational purposes. Declaring an array of strings in PCSPIM involves using the data segment to allocate memory for the array and the .asciiz directive to define and initialize the strings.

2. How do I declare an array of strings in PCSPIM?

To declare an array of strings in PCSPIM, you need to first allocate memory for the array in the data segment using the .space directive. Then, use the .asciiz directive to define and initialize each string in the array, separating them with commas.

3. Can I declare an array of strings of different lengths in PCSPIM?

Yes, you can declare an array of strings of different lengths in PCSPIM. This is because each string is allocated its own block of memory in the data segment, so the length of each string can vary.

4. How do I access individual strings in an array in PCSPIM?

To access individual strings in an array in PCSPIM, you can use the address of the array and an index to access the specific string. You can then use the lw or la instruction to load the string into a register and use it in your program.

5. Are there any limitations when declaring an array of strings in PCSPIM?

One limitation of declaring an array of strings in PCSPIM is that the total size of the array cannot exceed the amount of memory allocated in the data segment. Additionally, the maximum length of each string is limited by the size of the data segment as well.

Similar threads

Replies
20
Views
2K
Replies
3
Views
1K
Replies
6
Views
2K
Replies
7
Views
3K
Replies
3
Views
3K
Replies
4
Views
11K
Replies
4
Views
16K
Replies
4
Views
4K
Back
Top