1 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
2 ASM2.TXT - intro to keyboard and flow control
\r
3 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
5 Alright. This bit of code introduces control flow, keyboard input, and
\r
6 a way to easily print out one character.
\r
9 First off, lets examine the easiest one: printing a character.
\r
11 It's like this: you put the character to print in DL, put 2 in AH and
\r
12 call interrupt 21h. Damn easy.
\r
15 Ok, lets look at the next easiest one: keyboard input.
\r
17 There are quite a few functions related to INT 16h (the keyboard
\r
18 interrupt.) They are:
\r
23 0h -Gets a key from the keyboard buffer. If there isn't one, it waits
\r
25 Returns the SCAN code in ah, and the ASCII translation in AL
\r
27 1h -Checks to see if a key is ready to grab. Sets the zero flag if a
\r
28 key is ready to grab. Grab it with Fn# 0
\r
29 This also returns the same info about the key as Fn#0, but does
\r
30 not remove it from the buffer.
\r
32 2h -Returns the shift flags in al. They are:
\r
33 bit 7 - Insert active
\r
34 bit 6 - Caps lock active
\r
35 bit 5 - Num Lock active
\r
36 bit 4 - Scroll lock active
\r
38 bit 2 - Ctrl pressed
\r
39 bit 1 - Left shift pressed
\r
40 bit 0 - right shift pressed
\r
42 3h -You can set the Typematic Rate and delay with this function
\r
43 registers must be set as follows
\r
45 BH = Delay value (0-3: 250,500,750,1000 millisec)
\r
46 BL = Typematic rate (0-1fh) 1fh = slowest (2 chars per sec)
\r
47 0 =fastest (30 chars per second)
\r
49 4h -Key Click control - not important
\r
51 5h -STUFF the keyboard
\r
58 al = 1 keyboard buffer is full
\r
60 10h -Same as #0, but its for the extended keyboard. Checks all the keys.
\r
62 11h -Same as #1, but for the extended keyboard.
\r
64 12h -Same as #2, but AH contains additional shift flags:
\r
65 bit 7 - Sys req pressed
\r
66 bit 6 - Caps lock active
\r
67 bit 5 - Num Lock active
\r
68 bit 4 - Scroll lock active
\r
69 bit 3 - Right Alt active
\r
70 bit 2 - Right Ctrl active
\r
71 bit 1 - Left Alt active
\r
72 bit 0 - Right Alt active
\r
73 Al is EXACTLY the same as in Fn#2
\r
76 WHERE AH= the function number when you call INT 16h
\r
79 That's neat-o, eh? Now on to flow controll via CMP and Jcc...
\r
83 CMP is the same as SUB, but it does NOT alter any registers, only the
\r
84 flags. This is used in conjunction with Jcc.
\r
88 Ok, Jcc is not a real instruction, it means 'jump if conditionis met.'
\r
90 I'll break this into 3 sections, comparing signed numbers, comparing
\r
91 unsigned numbers, and misc.
\r
93 Note that a number being 'unsigned' or 'signed' only depends on how you
\r
94 treat it. That's why there are different Jcc for each...
\r
96 If you treat it as a signed number, the highest bit denotes whether it's
\r
99 Prove to yourself that 0FFFFh is actually -1 by adding 1 to 0FFFFh. You
\r
100 should get a big zero: 00000h. (Remember that the number is ONLY 16 bits
\r
101 and the carry dissapears..)
\r
105 JA -jumps if the first number was above the second number
\r
106 JAE -same as above, but will also jump if they are equal
\r
108 JB -jumps if the first number was below the second
\r
111 JNA -jumps if the first number was NOT above... (same as JBE)
\r
112 JNAE-jumps if the first number was NOT above or the same as..
\r
114 JNB -jumps if the first number was NOT below... (same as JAE)
\r
115 JNBE-jumps if the first number was NOT below or the same as..
\r
117 JZ -jumps if the two numbers were equal (zero flag = 1)
\r
118 JE -same as JZ, just a different name
\r
120 JNZ -pretty obvious, I hope...
\r
121 JNE -same as above...
\r
125 JG -jumps if the first number was > the second number
\r
126 JGE -same as above, but will also jump if they are equal
\r
128 JL -jumps if the first number was < the second
\r
131 JNG -jumps if the first number was NOT >... (same as JLE)
\r
132 JNGE-jumps if the first number was NOT >=.. (same as JL)
\r
134 JNL -jumps if the first number was NOT <... (same as JGE)
\r
135 JNLE-jumps if the first number was NOT <=... (same as JG)
\r
137 JZ, JE, JNZ, JNE - Same as for Unsigned
\r
141 JC -jumps if the carry flag is set
\r
144 Here's the rest of them... I've never had to use these, though...
\r
146 JO -jump if overflow flag is set
\r
149 JP -jump is parity flag is set
\r
151 JPE -jump if parity even (same as JP)
\r
152 JPO -jump if parity odd (same as JNP)
\r
154 JS -jumps if sign flag is set
\r
158 Here's the flags really quickly:
\r
159 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
160 bit# 8 7 6 5 4 3 2 1 0
\r
162 symbol: O D I T S Z A P C
\r
165 D = Direction flag *
\r
173 The * denotes the ones that you should know.
\r
175 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
177 That's it for now... Until next time...
\r
182 ÚÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
187 ; Prints messages get keyboard input and has control flow
\r
194 Prompt db 13,10,"Do you want to be prompted again? (Y/N) $"
\r
195 NoMessage db 13,10,"Ok, then I won't prompt you anymore.$"
\r
196 YesMessage db 13,10,"Here comes another prompt!$"
\r
197 UnKnownKey db 13,10,"Please hit either Y or N.$"
\r
202 mov ax,@DATA ;moves the segment of data into ax
\r
207 mov dx,offset Prompt
\r
208 int 21h ;print a message
\r
211 int 16h ;get a key, returned in AX
\r
212 ;AL is the ASCII part
\r
213 ;AH is the SCAN CODE
\r
217 int 21h ;print character in dl
\r
220 cmp al,"Y" ;was the character a 'Y'?
\r
221 jne NotYes ;nope it was Not Equal
\r
224 mov dx,offset YesMessage
\r
229 cmp al,"N" ;was the character a 'N'
\r
230 je ByeBye ;Yes, it was Equal
\r
232 mov dx,offset UnknownKey
\r
238 mov dx,offset NoMessage
\r
242 mov ax,4c00h ;Returns control to DOS
\r
243 int 21h ;MUST be here! Program will crash without it!
\r