[41] | 1 | ; File name : String.asm |
---|
| 2 | ; Project name : Assembly Library |
---|
| 3 | ; Created date : 12.7.2010 |
---|
[52] | 4 | ; Last update : 12.10.2010 |
---|
[41] | 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Functions for handling characters. |
---|
| 7 | |
---|
| 8 | ; Section containing code |
---|
| 9 | SECTION .text |
---|
| 10 | |
---|
| 11 | ;-------------------------------------------------------------------- |
---|
| 12 | ; String_ConvertWordToAXfromStringInDSSIwithBaseInBX |
---|
| 13 | ; Parameters: |
---|
| 14 | ; BX: Numeric base (10 or 16) |
---|
| 15 | ; DS:SI: Ptr to string to convert |
---|
| 16 | ; Returns: |
---|
| 17 | ; AX: Word converted from string |
---|
[52] | 18 | ; SI: Updated |
---|
| 19 | ; CF: Cleared if successfull |
---|
| 20 | ; Set if error during conversion |
---|
[41] | 21 | ; Corrupts registers: |
---|
[52] | 22 | ; Nothing |
---|
[41] | 23 | ;-------------------------------------------------------------------- |
---|
| 24 | ALIGN JUMP_ALIGN |
---|
| 25 | String_ConvertWordToAXfromStringInDSSIwithBaseInBX: |
---|
[52] | 26 | push di |
---|
| 27 | push dx |
---|
[41] | 28 | |
---|
[52] | 29 | xor di, di |
---|
| 30 | mov dx, StringProcess_ConvertToWordInDIWithBaseInBX |
---|
| 31 | call StringProcess_DSSIwithFunctionInDX |
---|
| 32 | xchg ax, di |
---|
[41] | 33 | |
---|
[52] | 34 | pop dx |
---|
| 35 | pop di |
---|
[41] | 36 | ret |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | ;-------------------------------------------------------------------- |
---|
[52] | 40 | ; String_CopyDSSItoESDIandGetSizeToCX |
---|
[41] | 41 | ; Parameters: |
---|
| 42 | ; DS:SI: Ptr to source NULL terminated string |
---|
| 43 | ; ES:DI: Ptr to destination buffer |
---|
| 44 | ; Returns: |
---|
| 45 | ; CX: Number of characters copied |
---|
| 46 | ; SI,DI: Updated by CX characters |
---|
| 47 | ; Corrupts registers: |
---|
| 48 | ; Nothing |
---|
| 49 | ;-------------------------------------------------------------------- |
---|
| 50 | ALIGN JUMP_ALIGN |
---|
[52] | 51 | String_CopyDSSItoESDIandGetSizeToCX: |
---|
[41] | 52 | push ax |
---|
[52] | 53 | |
---|
[41] | 54 | xor cx, cx |
---|
| 55 | ALIGN JUMP_ALIGN |
---|
[52] | 56 | .CopyNextCharacter: |
---|
[41] | 57 | lodsb ; Load from DS:SI to AL |
---|
| 58 | test al, al ; NULL to end string? |
---|
| 59 | jz SHORT .EndOfString |
---|
| 60 | stosb ; Store from AL to ES:DI |
---|
| 61 | inc cx ; Increment number of characters written |
---|
[52] | 62 | jmp SHORT .CopyNextCharacter |
---|
[41] | 63 | |
---|
| 64 | ALIGN JUMP_ALIGN |
---|
| 65 | .EndOfString: |
---|
| 66 | pop ax |
---|
| 67 | ret |
---|
[46] | 68 | |
---|
| 69 | |
---|
| 70 | ;-------------------------------------------------------------------- |
---|
[52] | 71 | ; String_GetLengthFromDSSItoCX |
---|
[46] | 72 | ; Parameters: |
---|
[52] | 73 | ; DS:SI: Ptr to NULL terminated string |
---|
[46] | 74 | ; Returns: |
---|
[52] | 75 | ; CX: String length in characters |
---|
[46] | 76 | ; Corrupts registers: |
---|
| 77 | ; Nothing |
---|
| 78 | ;-------------------------------------------------------------------- |
---|
| 79 | ALIGN JUMP_ALIGN |
---|
[52] | 80 | String_GetLengthFromDSSItoCX: |
---|
| 81 | push ax |
---|
[46] | 82 | push si |
---|
| 83 | |
---|
[52] | 84 | call Memory_ExchangeDSSIwithESDI |
---|
| 85 | xor ax, ax ; Find NULL |
---|
| 86 | mov cx, -1 ; Full segment if necessary |
---|
| 87 | repne scasb |
---|
| 88 | mov cx, di |
---|
| 89 | call Memory_ExchangeDSSIwithESDI |
---|
[46] | 90 | |
---|
[52] | 91 | pop si |
---|
| 92 | stc |
---|
| 93 | sbb cx, si ; Subtract NULL |
---|
[46] | 94 | pop ax |
---|
| 95 | ret |
---|