Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- segment .code
- _read_file:
- ; Push all registers to the stack
- pusha
- ; Open file
- mov ah, 3dh
- mov dx, settings_file
- mov al, 0
- int 21h
- ; Read file
- mov bx, ax
- mov ah, 3fh
- mov cx, 256
- mov dx, position_string
- int 21h
- ; Close file
- mov ah, 3eh
- int 21h
- ; Parse text form the file and split it in two parts
- mov si, position_string
- call _split_string
- ; Covert row string to the integer and store it
- mov si, position_row_string
- call _string_to_int
- mov [position_row_int], ax
- ; Covert columns string to the integer and store it
- mov si, position_column_string
- call _string_to_int
- mov [position_column_int], ax
- ; Pop all registers from the stack
- popa
- ret
- _split_string:
- ; Push all registers to the stack
- pusha
- ; Clear ax and bx registers
- xor ax, ax
- xor bx, bx
- .loop:
- mov al, byte [si] ; Load current character into the al
- ; Check if strings is terminated by zero and
- ; current character is zero, if it is then exit out of the loop
- or al, al ; We can use cmp al, 0 but or al, al is faster
- jz .end ; Jump, exit out of the loop
- cmp al, ' ' ; Compare current character with space
- je .next_string ; If current character is space then jump to the .next_string
- ; If delimiter has been found, copy only second string
- cmp [.other_string], byte 1
- je .second_string
- mov [position_row_string+bx], al ; Add current letter to the first string
- inc bx ; Move position to the next character inside the current destination string
- inc si ; Move position to the next character inside string which needs to be parsed
- jmp .loop ; Loop again
- .second_string:
- mov [position_column_string+bx], al ; Add current letter to the second string
- inc bx ; Move position to the next character inside the current destination string
- inc si ; Move position to the next character inside string which needs to be parsed
- jmp .loop ; Loop again
- ; Copy only second string
- .next_string:
- mov [.other_string], byte 1 ; Delimiter has been found, remember that we need to parse only second part of the string
- xor bx, bx ; Reset bx register, because we need to begin from the first place in new string (0)
- inc si ; Move position to the next character inside string which needs to be parsed
- jmp .loop ; Loop again
- ; Exit out of the loop
- .end:
- ; Pop all registers from the stack
- popa
- ret
- segment .data
- .other_string: db 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement