Hi Everyone,

i have recently started learning assembly and so far i do enjoy it ,
however my recent problem has me stumped ...

The question is : ask the user to enter a keystroke and then determine whether its a decimal # or lower case char or printable symbol, or a control key that he or she has entered.

Now so far im able to ask the user to enter a key and then i can output to the screen what he enter but i can seem to determine how to show what he entered, i have a feeling i'll need to use the case statement ,,,, Any help would be appreciated.

Code:

; This program displays a prompt for the user to enter a keystroke

segment .data ; initialized data segment

msg db "Please enter a keystroke", 0xA,0xD ; length of message
len equ $ - msg

;-----------------------------------------------
segment .bss ; uninitialized data segment
;-----------------------------------------------

key1 resb 10 ; reserve 10 bytes for id input

;------------------------------------------------

segment .text ; code segment

msg2 db "the keystroke entered is : ", 0xA,0xD ; length of message
len1 equ $ - msg2

global _start ; main function

_start: ; select system call 4

;------------------------------------------------------------------------

mov eax, 4 ; standard output device

mov ebx, 1 ; pointer to message buffer

mov ecx, msg ; number of output bytes bassically in segment.data

mov edx, len ;
int 0x80
;-----------------------------------------------------------------------------


mov eax, 3 ; select system call 3
mov ebx, 0 ; standard input device
mov ecx, key1 ; pointer to input buffer
mov edx, 10 ; number of input bytes

int 0x80 ; invoke selected system call
;-------------------------------------------------------------------------

mov eax, 4 ; standard output device

mov ebx, 1 ; pointer to message buffer

mov ecx, msg2 ; number of output bytes bassically in segment.data

mov edx, len1 ;

int 0x80

;---------------------------------------------------------------------------

mov eax, 4 ; standard output device

mov ebx, 1 ; pointer to message buffer

mov ecx, key1 ; number of output bytes bassically in segment.data

mov edx, len ;

int 0x80


exit:
mov eax, 1 ; select system call 1
xor ebx, ebx ; set default exit code
int 0x80 ; invoke selected system call

I assume your using the linux API, due to your INT80 system calls.
Any keystrokes read into the buffer should be printable.
Check you parameters to the API calls.

What is this?

mov ecx, msg2 ; number of output bytes bassically in segment.data

You are loading the counter register with the address of your buffer
for the number of output bytes.

This already has the number of output bytes, or your buffers length:

len1 equ $ - msg2

Hence use the equate 'len1' for the number of bytes to ouput

mov ecx, len1

To get the number of bytes entered by the user I believe the contents
of EAX will have the number of bytes read in. This may be wrong,
I don't typically program in assembler in a *NIX environment.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.