3 ms·
Null terminated is going to be nice in most instruction sets, you don't need to keep track of a count, so you save a register, and you have one less thing to in
by toast0 11y ago
Null terminated is going to be nice in most instruction sets, you don't need to keep track of a count, so you save a register, and you have one less thing to increment (or decrement). Loop condition is basically free too, loading the next byte into a register is going to set the status register, so you don't need a compare, you can just branch if the zero flag is set.
As long as you are handling good data, it's clearly more efficient.
- rasz_pl 11y ago> loading the next byte into a register is going to set the status register not in x86
- toast0 11y agoIf you load into C, you can JCXZ, instead of JZ, since you don't get the zero flag for free with a load.
- Zardoz84 11y agoAlso, null-terminated arrays are used for other stuff that not are strings. For example : https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strsplit https://developer.gnome.org/glib/stable/glib-String-Utility-... returns an null terminated array of strings.
- Buge 11y agoargv is a null-terminated array of string.
- ksherlock 11y agoAside from the Zero flag, there was also a Negative/Signed flag. Setting the high-bit in the last character (or clearing it if the rest had the high bit set) was also a way to terminate strings and save a byte over null-terminated strings. People who go ape-shit over 0-terminated strings would probably be even more upset if we still did that.