Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard shift status

Status
Not open for further replies.

phreaky

Technical User
Nov 21, 2004
1
0
0
IE
Hi all, im new to assembly and tasm and all that, taught myself from a book. Just wondering if anyone could tell me whats wrong with this code?
Thanks

;
.model small
.stack 100h
.data

msg7 db 'Insert on $'
msg6 db 'Caps lock on $'
msg5 db 'Num lock on $'
msg4 db 'Scroll lock on $'
msg3 db 'Alt pressed $'
msg2 db 'Ctrl pressed $'
msg1 db 'Left shift pressed $'
msg0 db 'right shift pressed $'

.code

Start:

mov ah, 02h ;keyboard passes bit
int 16h
mov cx, 0 ;Initialize cx to 0

ShrLoop: shr al, 1 ;Shift al one bit to the right

jc numberCheck ; jump to cl number when carry = 1
inc cl ;increment cl counter
jnc shrloop ;restart loop when carry = 0


cmp cl, 8 ; compare cl with 8 if true
je finish ; then finish

numberCheck: cmp cl, 0
je no0
cmp cl, 1
je no1
cmp cl, 2
je no2
cmp cl, 3
je no3
cmp cl, 4
je no4
cmp cl, 5
je no5
cmp cl, 6
je no6
cmp cl, 7
je no7

mov bx,0 ;Set bx to 0 so
shr bx,1 ;the carry can be reset
ret


no7: mov dx, offset msg7
call puts ; Calls procedure to display string
ret
no6: mov dx, offset msg6
call puts
ret
no5: mov dx, offset msg5
call puts
ret
no4: mov dx, offset msg4
call puts
ret
no3: mov dx, offset msg3
call puts
ret
no2: mov dx, offset msg2
call puts
ret
no1: mov dx, offset msg1
call puts
ret
no0: mov dx, offset msg0
call puts
ret


finish: mov ah, 4Ch ;End Program
int 21h




puts: ;display a string

mov ah, 9h
int 21h

ret


End start
 
Dear phreaky,

You just made one mistake:

shr al,1 shifts right al 1 bit and place the tightmost
bit in the carry.
The leftmost bit however is shifted in by a 0.

So: if al = 0FFh, afther 1 shift al = 07Fh
and so on.

If the strating value of al = 000h, your check will never
stop, becose the carry is clear, inc cl will not change
to carry and the jnc shrloop will make your program
"hang"


ShrLoop: shr al, 1 ;Shift al one bit to the right

jc numberCheck ; jump to cl number when carry = 1
inc cl ;increment cl counter
jnc shrloop ;restart loop when carry = 0


cmp cl, 8 ; compare cl with 8 if true
je finish ; then finish


I hope i helped you a bit,

Tessa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top