Array: Difference between revisions

m
→‎Null Terminator: Clarification
m (→‎End Label: Clarification)
m (→‎Null Terminator: Clarification)
Line 116:
====Encoding an Array's End====
=====Null Terminator=====
This method is most commonly used with strings. An ASCII value that is not associated with any keyboard key, typically 0, is placed at the end of a string. In a typical PrintString assembly routine, the routine is given a pointer to the 0th entry of the string as its only parameter. The routine reads from the pointer, prints that letter, increments the pointer, and repeats until the terminator is read, at which point the routine ends. Without the terminator, the program would not know when to stop reading and eventually crash. A string variable in [[C]] will place a 0 at the end of a string without you having to define it yourself. This method works well for strings and other arrays where the terminator's value is not a possible value for actual data. On more general arrays where the entries represent non-ASCII data, this causes problems where you have a datum that just so happens to equal the terminator.
 
<lang asm>PrintString: ;input: [DS:SI] = string pointer
1,489

edits