Skip to content

Instantly share code, notes, and snippets.

@Kittoes0124
Last active August 30, 2019 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kittoes0124/c2288ec4daee90f549dfe73430494847 to your computer and use it in GitHub Desktop.
Save Kittoes0124/c2288ec4daee90f549dfe73430494847 to your computer and use it in GitHub Desktop.
COMMENT @
C Interface:
extern char* Rfc4180_ReadRow(const char* bufferOffset, const char* bufferTail, long long isQuotedSequence);
Reference:
https://tools.ietf.org/html/rfc4180
@
;-----------------------------; (CONSTANTS)
CARRIAGE_RETURN = 00Dh
DOUBLE_QUOTE = 022h
LINE_FEED = 00Ah
TRUE = 001h
;-----------------------------; (ARGUMENTS)
arg0 textequ <rcx>
arg1 textequ <rdx>
arg2 textequ <r8>
;-----------------------------; (LOCALS)
bufferOffset textequ <rax>
bufferTail textequ <r9>
currentCharacter textequ <ecx>
isQuotedSequence textequ <rdx>
nextCharacter textequ <r8d>
.code
Rfc4180_ReadRow proc
mov bufferOffset, arg0 ; initialize [bufferOffset]
mov bufferTail, arg1 ; initialize [bufferTail]
mov isQuotedSequence, arg2 ; initialize [isQuotedSequence]
cmp bufferOffset, bufferTail ; validate that there are more characters to read
jae Rfc4180_ReadRow@Return ; if end of file reached, jump to Return
movzx nextCharacter, byte ptr[bufferOffset] ; extract [nextCharacter] from [bufferOffset]
Rfc4180_ReadRow@NextChar:
mov currentCharacter, nextCharacter ; shift [nextCharacter] into [currentCharacter]
inc bufferOffset ; increment [bufferOffset]
cmp bufferOffset, bufferTail ; validate that there are more characters to read
jae Rfc4180_ReadRow@Return ; if end of file reached, jump to Return
movzx nextCharacter, byte ptr[bufferOffset] ; extract [nextCharacter] from [bufferOffset]
cmp currentCharacter, DOUBLE_QUOTE ; compare [currentCharacter] to QUOTE_DOUBLE
jz Rfc4180_ReadRow@HitDoubleQuote ; if equal, jump to HitDoubleQuote
cmp currentCharacter, CARRIAGE_RETURN ; compare [currentCharacter] to CARRIAGE_RETURN
jz Rfc4180_ReadRow@HitCarriageReturn ; if equal, jump to HitCarriageReturn
cmp currentCharacter, LINE_FEED ; compare [currentCharacter] to LINE_FEED
jz Rfc4180_ReadRow@HitLineFeed ; if equal, jump to HitLineFeed
jmp Rfc4180_ReadRow@NextChar ; jump to NextChar
Rfc4180_ReadRow@HitDoubleQuote:
xor isQuotedSequence, TRUE ; invert [isQuotedSequence] indicator
jmp Rfc4180_ReadRow@NextChar ; jump to NextChar
Rfc4180_ReadRow@HitCarriageReturn:
cmp nextCharacter, LINE_FEED ; compare [nextCharacter] to LINE_FEED
jz Rfc4180_ReadRow@NextChar ; if equal, jump to NextChar
Rfc4180_ReadRow@HitLineFeed:
cmp isQuotedSequence, TRUE ; compare [isQuotedSequence] to TRUE
jz Rfc4180_ReadRow@NextChar ; if equal, jump to NextChar
Rfc4180_ReadRow@Return:
ret ; return to caller
Rfc4180_ReadRow endp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment