Slide 9.6: This book's link library (cont.)
Slide 10.1: Programming Laboratory IV:
Home

This Book's Link Library (Cont.)


ParseDecimal32
It converts an unsigned decimal integer string to 32-bit binary.

ParseInteger32
It converts a signed decimal integer string to 32-bit binary.

For both procedures, all valid digits occurring before a non-numeric character are converted. They receive the offset of a string in EDX and the string's length in ECX. The binary value is returned in EAX.

 Writing a String “12345” to
a File, number.txt 
 Reading the String from
the File and Incrementing it 
 STR_LEN = 6

 .data
 fname   BYTE  "number.txt", 0
 buffer  BYTE  "12345", 0
 msg     BYTE  "Error!", 0
 fhandle DWORD ?

 .code
      mov   edx, OFFSET fname
      call  CreateOutputFile
      cmp   eax, \
            INVALID_HANDLE_VALUE
      je    err
      mov   fhandle, eax

      mov   edx, OFFSET buffer
      mov   ecx, STR_LEN
      call  WriteToFile

      call  WriteInt
      mov   eax, fhandle
      call  CloseFile
      exit

 err: mov   edx, OFFSET msg
      call  WriteString
 BUFFER_SIZE = 128
 .data
 fname    BYTE  "number.txt", 0
 buffer   BYTE  BUFFER_SIZE DUP(0)
 msg      BYTE  "Error!", 0
 fhandle  DWORD ?
 .code
      mov   edx, OFFSET fname
      call  OpenInputFile
      cmp   eax, \
            INVALID_HANDLE_VALUE
      je    err
      mov   fhandle, eax

      mov   edx, OFFSET buffer
      mov   ecx, BUFFER_SIZE
      call  ReadFromFile

      mov   edx, OFFSET buffer
      call  ParseInteger32
      inc   eax
      call  WriteInt

      mov   eax, fhandle
      call  CloseFile
      exit
        
 err: mov   edx, OFFSET msg
      call  WriteString
 Output   Output