-
Notifications
You must be signed in to change notification settings - Fork 1
/
input-store-print.asm
65 lines (54 loc) · 1.43 KB
/
input-store-print.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[org 0x7C00]
mov ah, 0x0E ; BIOS teletype
mov bx, prompt ; prompt string
print_prompt:
mov al, [bx] ; load string pointer
cmp al, 0 ; check for null terminator
je get_name
int 0x10 ; print character
inc bx ; increment string pointer
jmp print_prompt ; loop again
get_name:
mov bx, var ; load variable pointer
input_name:
mov ah, 0 ; BIOS keyboard input
int 0x16 ; wait for keypress
cmp al, 0x0D ; check for enter key
je newline ; jump if enter key pressed
mov [bx], al ; store character in variable
inc bx ; increment variable pointer
jmp input_name ; loop again
newline:
mov ah, 0x0E ; BIOS teletype
mov al, 0x0A ; newline character
int 0x10 ; print newline
mov al, 0x0D ; carriage return character
int 0x10 ; print carriage return
print_hello:
mov bx, hello
hi_loop:
mov al, [bx]
cmp al, 0
je print_var
int 0x10
inc bx
jmp hi_loop
print_var:
mov bx, var
var_loop:
mov al, [bx]
cmp al, 0
je end
int 0x10
inc bx
jmp var_loop
end:
jmp $
prompt:
db "Welcome to the void. Your name ?", 0
var:
times 10 db 0
hello:
db "Hi ", 0
times 510-($-$$) db 0
dw 0xAA55