Subversion Repositories SvarDOS

Rev

Rev 406 | Rev 415 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 406 Rev 410
Line 299... Line 299...
299
      dst[end++] = src[i];
299
      dst[end++] = src[i];
300
    }
300
    }
301
    dst[end] = 0;
301
    dst[end] = 0;
302
  }
302
  }
303
}
303
}
-
 
304
 
-
 
305
 
-
 
306
/* converts an ASCIIZ string into an unsigned short. returns 0 on success. */
-
 
307
int atouns(unsigned short *r, const char *s) {
-
 
308
  int err = 0;
-
 
309
 
-
 
310
  _asm {
-
 
311
    mov si, s
-
 
312
    xor ax, ax  /* general purpose register */
-
 
313
    xor cx, cx  /* contains the result */
-
 
314
    mov bx, 10  /* used as a multiplicative step */
-
 
315
 
-
 
316
    NEXTBYTE:
-
 
317
    xchg cx, ax /* move result into cx temporarily */
-
 
318
    lodsb  /* AL = DS:[SI++] */
-
 
319
    /* is AL 0? if so we're done */
-
 
320
    test al, al
-
 
321
    jz DONE
-
 
322
    /* validate that AL is in range '0'-'9' */
-
 
323
    sub al, '0'
-
 
324
    jc FAIL   /* neg result */
-
 
325
    cmp al, 9
-
 
326
    jg FAIL
-
 
327
    /* restore result into AX (CX contains the new digit) */
-
 
328
    xchg cx, ax
-
 
329
    /* multiply result by 10 and add cl */
-
 
330
    mul bx    /* DX AX = AX * BX(10) */
-
 
331
    jc FAIL   /* overflow */
-
 
332
    add ax, cx
-
 
333
    /* if CF then overflow occured (overflow part lands in DX) */
-
 
334
    jnc NEXTBYTE
-
 
335
 
-
 
336
    FAIL:
-
 
337
    inc [err]
-
 
338
 
-
 
339
    DONE: /* save result (CX) into indirect memory address r */
-
 
340
    mov bx, [r]
-
 
341
    mov [bx], cx
-
 
342
  }
-
 
343
  return(err);
-
 
344
}