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
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