Array: Difference between revisions

Content added Content deleted
m (→‎Encoding an Array's End: Provided more fitting examples that actually relate to the text.)
(→‎Encoding an Array's End: Added additional clarification)
Line 138: Line 138:
; input: [DS:SI] = string pointer
; input: [DS:SI] = string pointer
mov al,[ds:si]
mov al,[ds:si]
cmp al,5Ch ;ascii for backslash, this is the escape character
cmp al,5Ch ;ascii for backslash, this is the escape character
;notice that the check for the escape character happens before the check for the terminator.
jz EscapeNextChar
jz EscapeNextChar
cmp al,0h ;check the terminator
cmp al,0h ;check the terminator
jz Terminated ;we've reached the terminator
jz Terminated ;we've reached the terminator
call PrintChar ;call to hardware-specific printing routine
call PrintChar ;call to hardware-specific printing routine
jmp PrintString
jmp PrintString

EscapeNextChar:
EscapeNextChar:
mov al,[ds:si] ;perform an additional read, except this read doesn't compare the fetched character to anything.
mov al,[ds:si] ;perform an additional read, except this read doesn't compare the fetched character to anything.
call PrintChar ;print that character as-is
call PrintChar ;print that character as-is
jmp PrintString ;go back to the loop's beginning, skipping the terminator check entirely.
jmp PrintString


Terminated:
Terminated: