PCSPIM - declaring an array of strings

  • Thread starter Thread starter magneto202
  • Start date Start date
  • Tags Tags
    Array Strings
Click For Summary
SUMMARY

Declaring an array of strings in PCSPIM can be achieved using the .asciiz directive, as demonstrated with the declaration Nstart: .asciiz "the", "dog", "run". This method ensures that the strings are stored correctly in memory, with each string being null-terminated. The discussion confirms that the representation of data in memory is crucial, and using .word for character representation is not appropriate for strings. The consensus is that as long as the final memory representation is accurate, various declaration methods can be utilized.

PREREQUISITES
  • Understanding of PCSPIM assembler syntax
  • Knowledge of memory representation in assembly language
  • Familiarity with string data types and null-termination
  • Basic concepts of ASCII encoding
NEXT STEPS
  • Explore PCSPIM documentation on .asciiz and .word directives
  • Learn about memory addressing and data representation in assembly language
  • Investigate string manipulation functions in assembly language
  • Study examples of multi-dimensional arrays in PCSPIM
USEFUL FOR

Assembly language programmers, computer science students, and anyone working with PCSPIM who needs to understand string declarations and memory management in assembly code.

magneto202
Messages
2
Reaction score
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
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).
 
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.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
12K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
17K
  • · Replies 4 ·
Replies
4
Views
5K