Skip to content

Commit fe8062d

Browse files
committed
Commented gets.asm
1 parent d4a8596 commit fe8062d

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

functions/gets.asm

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,37 @@ global _gets
22

33

44
section .text:
5+
; Get string function
56
_gets:
67
push bp
78
mov bp, sp
89

910

10-
mov si, 0
11-
mov ah, 0
11+
mov si, 0 ; Sets SI to 0 as is is a counter
12+
mov ah, 0 ; Sets read key-press mode
1213

13-
mov bx, [bp+6]
14+
mov bx, [bp+6] ; Writes address of buffer to BX
1415

15-
_read_char:
16-
cmp al, 0x0d
17-
je _done_gets
18-
cmp si, [bp+4]
19-
je _done_gets
16+
_read_char: ; Subroutine that reads input
17+
cmp al, 0x0d ; If "Enter" pressed
18+
je _done_gets ; Exits
19+
cmp si, [bp+4] ; If last character was entered
20+
je _done_gets ; Exits
2021
21-
int 16h
22+
int 16h ; Calls BIOS interuption to read key
2223

23-
mov ah, 0xe
24-
int 10h
25-
mov ah, 0
24+
mov ah, 0xe ; Sets console output mode
25+
int 10h ; Calls BIOS output interuption
26+
mov ah, 0 ; Sets read key-press mode
2627

27-
mov [bx], al
28-
inc bx
29-
inc si
30-
jmp _read_char
28+
mov [bx], al ; Writes character to buffer
29+
inc bx ; Shifts the buffer address
30+
inc si ; Incriments the counter
31+
jmp _read_char ; Reads next character
3132
3233

3334
_done_gets:
34-
mov ah, 0xe
35-
mov al, 0x0a
36-
int 10h
37-
mov al, 0x0d
38-
int 10h
39-
mov ah, 0
40-
41-
pop bp
42-
ret
35+
call _newline ; Moves cursor to a new line
36+
37+
pop bp ; Restores BP
38+
ret ; Exits function

0 commit comments

Comments
 (0)