[list -] %INCLUDE "Along32.inc" %INCLUDE "Macros_Along.inc" [list +] ;--------------------------------------------------------------------- extern isValid ; HLL prototype: bool isValid(char *string); ; This function receives the offset of a null-terminated array of ; characters. The function returns true if the string is valid and ; false otherwise. ; Implements the following code: ; let n = the length of the string ; let state = 0 ; for (i = 0; i < n; ++i) ; { ; print state and array[i] ; switch (state) ; { ; case 0: if array[i] == 'a' ; state = 1 ; else if array[i] == 'b' ; state = 2 ; else ; state = 4 ; case 1: if array[i] == 'a' ; state = 0 ; else if array[i] == 'b' ; state = 3 ; else ; state = 4 ; case 2: if array[i] == 'a' ; state = 3 ; else if array[i] == 'b' ; state = 0 ; else ; state = 4 ; case 3: if array[i] == 'a' ; state = 2 ; else if array[i] == 'b' ; state = 1 ; else ; state = 4 ; case 4: do nothing ; } // end switch ; print state ; } // end for ; return state == 1 ; Receives: ESI = starting offset of array ; Returns: bool in eax ;--------------------------------------------------------------------- SECTION .data string times 100 db 0 size equ $ - string lit1 db 'Input String: ',0 lit2 db 'Status: ',0 valid db `Valid\n\n`,0 invalid db `Invalid\n\n`,0 SECTION .bss n resd 1 h resd 1 SECTION .text global _start _start: call ReadDec ; read an unsigned 32-bit integer mov [h],eax ; store in h mainloop: cmp dword [h], 0 ; while h > 0 do jle done mov edx,string ; read a string from standard input mov ecx,size call ReadString mov dword [n],eax ; store length of input string in n mov edx,lit1 ; print the input string call WriteString mov edx,string call WriteString mov al,`\n` call WriteChar mov esi,string ; call isValid function call isValid mov edx,lit2 ; print the status of the string call WriteString cmp eax,1 jne printInvalid mov edx,valid jmp printIt printInvalid: mov edx,invalid printIt: call WriteString dec dword [h] ; get ready for the next iteration jmp mainloop ; end while done: Exit {0}