Empty string: Difference between revisions

Line 27:
byte 0</lang>
 
Checking if a string is empty is simple, just count the number of characters before you reach the terminator. If that count equals zero, the string is empty. Otherwise, the string is not empty.
 
<lang 6502asm>lda #<EmptyString ;address of string we wish to check
Line 46:
;otherwise, the string is not empty</lang>
 
=={{header|68000 Assembly}}==
 
{{trans|6502 Assembly}}
An empty string is just a null terminator with no text in front.
<lang 68000devpac>EmptyString:
DC.B 0
EVEN</lang>
Checking if a string is empty is simple, just count the number of characters before you reach the terminator. If that count equals zero, the string is empty. Otherwise, the string is not empty.
<lang 68000devpac>LEA EmptyString,A0
getStringLength:
MOVE.L A0,-(SP) ;push A0 onto the stack. This will be used to check if the string is empty.
loop_getStringLength:
MOVE.B (A0)+,D0
BEQ Terminated
JMP loop_getStringLength
SUBQ.L #1,A0 ;after the terminator is read, A0 is incremented to point to the byte after it. This fixes that.
CMP.L A0,(SP) ;compare the current A0 with the original value.
BEQ StringIsEmpty ;if they are equal, then nothing was read besides the terminator. Therefore the string is empty.
;if the above branch wasn't taken, the string is not empty and execution arrives here.</lang>
 
=={{header|8th}}==
1,489

edits