next up previous
Next: Integer and Float Arrays Up: Data Structures Previous: Byte Arrays

Example: Get String

A string is a data structure consisting of a character array and a string length. The length information may be a separate integer field or a special terminator character which marks the end of the string. The .asciiz declaration creates a byte array which is terminated by a 0 byte.

The following SAL program reads a line of input and formats it as an .asciiz byte array, simulating the operation of a gets (get string) instruction.

Characters are read one-by-one into an 80 byte array called 'name'. When a newline character is found, a zero byte is added to the end of the array to produce a string in .asciiz format. The puts instruction is used to echo the resulting string.




CS 301 Class Account
Mon Sep 13 11:15:41 ADT 1999