Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; In the convention I use DX and EX
- ; must be preserved accross function calls
- start:
- mov bx, 0
- mov ax, .message0
- call output_str
- mov ax, 0x0042
- mov cx, .input_result
- mov dx, 16 ; .input_result is 16 spaces and a 0
- call input_str
- mov [cx+ax], 0
- mov ax, .message1
- call output_str
- mov ax, cx
- call output_str
- mov ax, .message2
- call output_str
- hlt
- .message0: dw 0x1021, "Hello! What's your name?", 0
- .message1: dw 0x1081, "Hey there, ", 0x200F, 0
- .message2: dw 0x2007, ",", 0x10A1, "how is it going?", 0
- .input_result: dw " ", 0
- ; Input string
- ; AX: initial position of the cursor
- ; BX: port number
- ; CX: pointer to input buffer
- ; DX: maximum length of input
- ; Clobbers: AX
- input_str:
- push cx
- push dx
- or ax, 0x1000
- push ax
- mov dx, 0
- send bx, ax
- send bx, 0x5F
- .cloop:
- recv ax, bx
- cmp ax, 0x0A
- je .done
- cmp ax, 0x08
- je .backspace
- .insert:
- mov cx, [sp+1]
- cmp dx, cx
- je .cloop
- mov cx, [sp]
- add cx, dx
- send bx, cx
- send bx, ax
- send bx, 0x5F
- mov cx, [sp+2]
- mov [dx+cx], ax
- add dx, 1
- jmp .cloop
- .backspace:
- cmp dx, 0
- je .cloop
- mov ax, [sp]
- sub dx, 1
- add ax, dx
- send bx, ax
- send bx, 0x5F
- send bx, 0x20
- jmp .cloop
- .done:
- pop ax
- add ax, dx
- send bx, ax
- send bx, 0x20
- mov ax, dx
- pop dx
- pop cx
- ret
- ; Output string
- ; AX: pointer to null-terminated string
- ; BX: port number
- ; Clobbers: AX
- output_str:
- push cx
- .cloop:
- mov cx, [ax]
- cmp cx, 0
- je .done
- send bx, cx
- add ax, 1
- jmp .cloop
- .done:
- pop cx
- ret
Add Comment
Please, Sign In to add comment