Reputation: 69
How can I receive a key press from keyboard in assembly (8086 emu)? ..such that when some specific key is pressed, then some action need be taken (an action like adding 2 numbers or sth like that)...
For example, let's say I have the value 2 stored in AX ,the value 3 in BX , and while running the code, if I pressed "+" for example, then Add AX and BX, and if I pressed "-" then subtract AX from BX, otherwise don't do anything..
Can anyone explain the code to do that in details? I'm a complete newbie to Assembly.
Upvotes: 0
Views: 3562
Reputation: 3203
You asked 2 Questions in a Single Question:
1. Getting Values From Keyboard
MOV AH,01h
INT 21H
The entered number will be stored in DL general purpose register in ASCII Form.
Example:
You entered 'A' that has an ASCII value of 65 the DL will contain a value of 01000001.
To learn more about ASCII value I'd like to suggest you ASCII Table
2. Performing Operations based on Input:
You can perform various operations simply by comparing the value of DL register with ASCII values.
Example:
CMP DL, 43 ; '+' has ASCII value of 43
JE addition;
<<Some code here>>
<<Some code here>>
<<Some code here>>
ADDITION:
ADD AX , BX
Upvotes: 1