Conversion Functions


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

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

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

Writing a String “12345” to
a File, number.txt
Reading the String from
the File and Incrementing it
 INCLUDE Irvine32.inc
  STR_LEN = 6
 .data
  fname   BYTE  "number.txt", 0
  buffer  BYTE  "12345", 0
  msg     BYTE  "Error!", 0
  fhandle DWORD ?
 .code
 main PROC 
      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
      exit
 main ENDP
 END main

 INCLUDE Irvine32.inc 
  BUFFER_SIZE = 128
 .data
  fname    BYTE  "number.txt", 0
  buffer   BYTE  BUFFER_SIZE DUP(0)
  msg      BYTE  "Error!", 0
  fhandle  DWORD ?
 .code
 main PROC
      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
      exit
 main ENDP
 END main
 
Output Output

 

 

 

 


      “Never go to bed mad. Stay up and fight.”    
      ― Phyllis Diller