CharacterStrings - Introduction to Character Strings...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Character Strings Beta Draft - Do not distribute © 2001, By Randall Hyde Page 419 Intr oduction to Character Strings Chapter Two 2.1 Chapter Overview This chapter discusses ho w to declare and use character strings in your programs. While not a complete treatment of this subject (additional material appears later in this te xt), this chapter will pro vide suf fi cient information to allo w basic string manipulation within your HLA programs. 2.2 Composite Data Types Composite data types are those that are b uilt up from other (generally scalar) data types. This chapter will co v er one of the more important composite data types – the character string. A string is a good e xample of a composite data type – it is a data structure b uilt up from a sequence of indi vidual characters and some other data. 2.3 Character Strings After inte ger v alues, character strings are probably the most popular data type that modern programs use. The 80x86 does support a handful of string instructions, b ut these instructions are really intended for block memory operations, not a specifi c implementation of a character string. Therefore, this section will concentrate mainly on the HLA defi nition of character strings and also discuss the string handling routines a v ailable in the HLA Standard Library . In general, a c har acter string is a sequence of ASCII characters that possesses tw o main attrib utes: a length and the c har acter data . Dif ferent languages use dif ferent data structures to represent strings. T o bet - ter understand the reasoning behind HLA strings, it is probably instructi v e to look at tw o dif ferent string rep - resentations popularized by v arious high le v el languages. W ithout question, zer o-terminated strings are probably the most common string representation in use today because this is the nati v e string format for C/C++ and programs written in C/C++. A zero terminated string consists of a sequence of zero or more ASCII characters ending with a byte containing zero. F or e xample, in C/C++, the string “abc” requires four characters: the three characters ‘a’, ‘b’, and ‘c’ follo wed by a byte containing zero. As you’ ll soon see, HLA character strings are upw ards compatible with zero ter - minated strings, b ut in the meantime you should note that it is v ery easy to create zero terminated strings in HLA. The easiest place to do this is in the ST A TIC section using code lik e the follo wing: static zeroTerminatedString: char; @nostorage; byte “This is the zero terminated string”, 0; Remember , when using the @NOSTORAGE option, no space is actually reserved for a variable declaration, so the zeroTerminatedString variable’s address in memory corresponds to the first character in the following BYTE directive. Whenever a character string appears in the BYTE directive as it does here, HLA emits each character in the string to successive memory locations. The zero value at the end of the string properly ter-
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

CharacterStrings - Introduction to Character Strings...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online