PDA

نسخه کامل مشاهده نسخه کامل : اشکال گیری برنامه اسمبلی



masome
18-07-2007, 13:35
سلام!
من این برنامه را نوشته ام ولی درست کار نمی کنه!می شه بگید اشکالش چیه و باید چی کار کرد؟
صورت برنامه:
یک منو با سه گزینه ایجاد شود که در قسمت اول باید یک string را به وسیله کلیدهای مکان نما حرکت دهیم.در قسمت بعد باید وضعیت کلیدهای insert,scrolllock,capslock,numlock را بررسی کند و در قسمت بعد از برنامه خارج شود.
کد برنامه:


dataseg segment 'data'
row_up db ?
row_down db ?
left_coloum db ?
right_coloum db ?
cr equ 0dh
lf equ 0ah
menu db 0c9h,40 dup(0cdh),0bbh,cr,lf
db 0bah,2 dup(32),'please choose 1,2 or 3',2 dup(32),0bah,cr,lf
db 0bah,2 dup(32),'then press enter.',2 dup(32),0bah,cr,lf
db 0bah,40 dup(32),0bah,cr,lf
db 0bah,2 dup(32),'1)Game',2 dup(32),0bah,cr,lf
db 0bah,2 dup(32),'2)Keys staute',2 dup(32),0bah,cr,lf
db 0bah,2 dup (32),'3)Exit',2 dup(32),0bah,cr,lf
db 0c8h,40 dup(0cdh),0bch,cr,lf,"$"
msg1 db "YOU ENTERED INVALID NUMBER,PRESS ESC TO BACK.","$"
msg2 db "Inser is on.","$"
msg3 db "Caps Lock is on.","$"
msg4 db "Num Lock is on.","$"
msg5 db "Scroll Lock is on.","$"
msg6 db "press Esc to back.","$"
msg7 db "Thank you","$"
msg8 db "GOOD BYE","$"
msg9 db "press Del to back.","$"
border db 0dah,50 dup(0c4h),0bfh,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0c0h,50 dup(0c4h),0d9h,cr,lf,"$"
hello db 0c9h,7 dup(0cdh),0bbh,cr,lf
db 0bah,7 dup(32),0bah,cr,lf
db 0bah,1 dup(32),'HELLO',1 dup(32),0bah,cr,lf
db 0bah,7 dup(32),0bah,cr,lf
db 0c8h,7 dup(0c4h),0bch,cr,lf,"$"
dataseg ends
codeseg segment 'code'
main proc far
assume cs:codeseg,ds:dataseg
mov ax,dataseg
mov ds,ax
call cls
call disp_menu ;display menu
p1:
call read_char ;read character from keyboard
cmp al,49
je game ;select first item in menu
cmp al,50
je satute ;select second item in menu
cmp al,51
je exit ;select third item in menu
back:
call cls
mov dx,0c0eh
call locate ;set cursor in center
lea dx,msg1
mov ah,9h
int 21h ;print error
call read_char ;read character from keyboard
cmp al,27 ;press esc?
jne back
call cls
mov dh,5
mov dl,5
call locate ;set cursor
call disp_menu ;display menu
jmp p1
game:
call cls
mov dh,2
mov dl,30
call locate ;set cursor in(2,30)
mov ah,9h
lea dx,msg9
int 21h ;print message for back to the menu
mov dh,4
mov dl,4
call locate ;set cursor in (4,4)
call disp_border
mov dh,0bh
mov dl,1bh
call locate ;set cursor in (11,27)
call disp_hello ;request display menu
mov row_up,11
mov row_down,15
mov left_coloum,27
mov right_coloum,35
lup:
p:
call read_char ;read character from keyboard
cmp ah,72 ;press up arrow
jne L1
dec row_up
jne lup
call cls
mov dh,2
mov dl,30
call locate ;set cursor in(2,30)
mov ah,9h
lea dx,msg9
int 21h ;print message for back to the menu
mov dh,4
mov dl,4
call locate ;set cursor in (4,4)
call disp_border
dec row_down
mov dh,row_up
mov dl,left_coloum
call locate
call disp_hello
jmp lup
L1:
cmp ah,80 ;press down arrow
jne L2
inc row_down
cmp row_down,24
jnl lup
call cls
mov dh,2
mov dl,30
call locate ;set cursor in(2,30)
mov ah,9h
lea dx,msg9
int 21h ;print message for back to the menu
mov dh,4
mov dl,4
call locate ;set cursor in (4,4)
call disp_border
inc row_up
mov dh,row_up
mov dl,left_coloum
call locate
call disp_hello
jmp lup
L2:
cmp ah,75 ;press left arrow
jne L3
dec left_coloum
cmp left_coloum,4
jne lup
call cls
mov dh,2
mov dl,30
call locate ;set cursor in(2,30)
mov ah,9h
lea dx,msg9
int 21h ;print message for back to the menu
mov dh,4
mov dl,4
call locate ;set cursor in (4,4)
call disp_border
mov dh,row_up
mov dl,left_coloum
call locate
call disp_hello
jmp lup
L3:
cmp ah,77 ;press right arrow
jne L4
inc right_coloum
cmp right_coloum,55
jnl lup
call cls
mov dh,2
mov dl,30
call locate ;set cursor in(2,30)
mov ah,9h
lea dx,msg9
int 21h ;print message for back to the menu
mov dh,4
mov dl,4
call locate ;set cursor in (4,4)
call disp_border
inc left_coloum
mov dh,row_up
mov dl,left_coloum
call locate
call disp_hello
jmp lup
L4:
cmp ah,83 ;press delete key?
jne L5
call cls
mov dh,5
mov dl,5
call locate ;set cursor in (5,5)
call disp_menu
L5:
call cls
mov ah,9h
lea dx,msg1
int 21h
call read_char ;read character from keyboard
cmp ah,27 ;press Esc?
jne L5
call cls
mov dh,5
mov dl,5
call locate ;set cursor in (5,5)
call disp_menu
jmp p1
satute:
mov ah,12h
int 16h
test al,10000b
jz k2
call cls
mov dl,5
mov dh,8
call locate
lea dx,msg2
mov ah,09h
int 21h
k2:
test al,100000b
jz k3
call cls
mov dl,5
mov dh,8
call locate
lea dx,msg3
mov ah,09h
int 21h
k3:
test al,1000000b
jz k4
call cls
mov dl,5
mov dh,8
call locate
lea dx,msg4
mov ah,09h
int 21h
k4:
test al,10000000b
jz k5
call cls
mov dl,5
mov dh,8
call locate
lea dx,msg5
mov ah,09h
int 21h
k5:
call cls
mov dl,5
mov dh,8
call locate
lea dx,msg6
mov ah,09h
int 21h
p6:
call read_char ;read character from keyboard
cmp ah,27
jne p6
call cls
mov dh,5
mov dl,5
call locate ;set cursor in (5,5)
call disp_menu
jmp p1
exit:
call cls
mov dh,10
mov dl,34
call locate ;set cursor
lea dx,msg7
mov ah,09h
int 21h
mov dh,12
mov dl,36
call locate ;set cursor
lea dx,msg8
mov ah,09h
int 21h
mov ax,4c00h
int 21h
main endp
;************************************************* *************
disp_menu proc near
mov ah,9h
lea dx,menu
int 21h
ret
disp_menu endp
;************************************************* *************
disp_border proc near
mov ah,9h
lea dx,border
int 21h
ret
disp_border endp
;************************************************* *************
disp_hello proc near
mov ah,9h
lea dx,hello
int 21h
ret
disp_hello endp
;************************************************* *************
locate proc near
mov ah,2h
mov bh,0
int 10h
ret
locate endp
;************************************************* *************
cls proc near
mov ah,6h
mov al,25
mov cx,0000h
mov dx,184fh ;full screen
mov bh,7
int 10h
ret
cls endp
;************************************************* ************
read_char proc near
mov ah,10h
int 16h
ret
read_char endp
;************************************************* ************
codeseg ends
end main

leila_m
22-07-2007, 18:47
dataseg segment 'data'cr equ 0dhlf equ 0ahn db 0menu db 0c9h,40 dup(0cdh),0bbh,cr,lf db 0bah,2 dup(32),'please choose 1,2 or3',17 dup(32),0bah,cr,lf db 0bah,40 dup(32),0bah,cr,lf db 0bah,40 dup(32),0bah,cr,lf db 0bah,2 dup(32),'1)Game',32 dup(32),0bah,cr,lf db 0bah,2 dup(32),'2)Keys staute',25 dup(32),0bah,cr,lf db 0bah,2 dup (32),'3)Exit',32 dup(32),0bah,cr,lf db 0c8h,40 dup(0cdh),0bch,cr,lf,"$"msg1 db "YOU ENTERED INVALID NUMBER,PRESS ESC TO BACK.","$"msg2 db "Inser is on.","$"msg3 db "Caps Lock is on.","$"msg4 db "Num Lock is on.","$"msg5 db "Scroll Lock is on.","$"msg6 db "press Esc to back.","$"msg7 db "Thank you","$"msg8 db "GOOD BYE",cr,lf db "press any key to exit.","$"msg9 db "press Del to back.","$"msg10 db "all the keys are off.","$"border db 0dah,50 dup(0c4h),0bfh,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0b3h,50 dup(32),0b3h,cr,lf db 0c0h,50 dup(0c4h),0d9h,cr,lf,"$"str1 db 10,13,"HELLO","$"row_up db 11row_down db 15left_coloum db 25right_coloum db 30dataseg endscodeseg segment 'code'main proc farassume cs:codeseg,ds:datasegmov ax,datasegmov ds,axstart: call clscall disp_menu ;display menu call read_char ;read character from keyboardcmp al,49je game ;select first item in menucmp al,50je satute ;select second item in menucmp al,51je exit ;select third item in menuback:call clsmov dx,0c0ehcall locate ;set cursor in centerlea dx,msg1mov ah,9hint 21h ;print errorcall read_char ;read character from keyboardcmp al,27 ;press esc?jne backjmp start;________________________PART 1___________________________game:call clscall disp_border ;request display bordercall disp_hello ;request display hellolup:call read_char ;read character from keyboardcmp ah,72 ;press up arrow? jne L1call clsdec row_updec row_downcall disp_bordercall disp_hellojmp lupL1:cmp ah,80 ;press down arrow?jne L2call clscall disp_borderinc row_downinc row_upcall disp_hellojmp lupL2:cmp ah,75 ;press left arrow?jne L3call clscall disp_borderdec left_coloumdec right_coloumcall disp_hellojmp lupL3:cmp ah,77 ;press right arrowjne L4call clscall disp_borderinc left_colouminc right_coloumcall disp_hellojmp lupL4:cmp ah,83 ;press delete key?jne L5call clscall disp_menuL5:call clsmov dx,0c0ehcall locate ;set cursor in centerlea dx,msg1mov ah,9hint 21h ;print errorcall read_char ;read character from keyboardcmp al,27 ;press esc?jne backjne L5jmp start;________________________PART 2___________________________satute:mov ah,12hint 16hmov n,alp1:mov cl,1shl n,cljc p2back1:shl n,1jc p3back2:shl n,1jc p4back3:shl n,1jc p5back4:jmp p6p2:mov dl,5mov dh,8call locate ;set cursor in(5,8)lea dx,msg2mov ah,09hint 21hjmp back1p3:mov dl,7mov dh,8call locate ;set cursor in(7,8)mov ah,9hlea dx,msg3int 21hjmp back2p4:mov dl,9mov dh,8call locate ;set cursor in(9,8)mov ah,9hlea dx,msg4int 21hjmp back3p5:mov dl,11mov dh,8call locate ;set cursor in(11,8)mov ah,9hlea dx,msg5int 21hjmp back4p6:mov dl,22mov dh,32call locate ;set cursor in (22,32)mov ah,9hlea dx,msg6int 21hp7:call read_char ;read character from keyboardcmp ah,27 ;press esc?jne p7jmp start;_________________________part 3____________________________exit:call clsmov dh,10mov dl,34call locate ;set cursorlea dx,msg7mov ah,09hint 21hmov dh,13mov dl,36call locate ;set cursorlea dx,msg8mov ah,09hint 21hmov ax,4c00hint 21hmain endp;********************************************* *****************disp_menu proc nearmov dh,0mov dl,0call locate ;set cursor in (0,0)mov ah,9hlea dx,menuint 21hretdisp_menu endp;********************************************* *****************disp_border proc nearmov dh,0mov dl,0call locate ;set cursor in (0,0)mov ah,9hlea dx,borderint 21hmov dh,17hmov dl,10hcall locate ;set cursor in(24,10)mov ah,9hlea dx,msg9int 21h ;print message for back to the menuretdisp_border endp;********************************************* *****************disp_hello proc nearmov dh,row_upmov dl,left_coloumcall locate ;set cursor in(row_up,left_colume)mov ah,9hlea dx,str1int 21hretdisp_hello endp;********************************************* *****************locate proc nearmov ah,2hmov bh,0int 10hretlocate endp;********************************************* *****************cls proc nearmov ah,6hmov al,25mov cx,0000hmov dx,184fh ;full screenmov bh,7int 10hretcls endp;********************************************* ****************read_char proc nearmov ah,10hint 16hretread_char endp;********************************************* ****************codeseg endsend main

leila_m
22-07-2007, 18:52
;):thumbsup:

leila_m
22-07-2007, 18:56
dataseg segment 'data'
cr equ 0dh
lf equ 0ah
n db 0
menu db 0c9h,40 dup(0cdh),0bbh,cr,lf
db 0bah,2 dup(32),'please choose 1,2 or3',17 dup(32),0bah,cr,lf
db 0bah,40 dup(32),0bah,cr,lf
db 0bah,40 dup(32),0bah,cr,lf
db 0bah,2 dup(32),'1)Game',32 dup(32),0bah,cr,lf
db 0bah,2 dup(32),'2)Keys staute',25 dup(32),0bah,cr,lf
db 0bah,2 dup (32),'3)Exit',32 dup(32),0bah,cr,lf
db 0c8h,40 dup(0cdh),0bch,cr,lf,"$"
msg1 db "YOU ENTERED INVALID NUMBER,PRESS ESC TO BACK.","$"
msg2 db "Inser is on.","$"
msg3 db "Caps Lock is on.","$"
msg4 db "Num Lock is on.","$"
msg5 db "Scroll Lock is on.","$"
msg6 db "press Esc to back.","$"
msg7 db "Thank you","$"
msg8 db "GOOD BYE",cr,lf
db "press any key to exit.","$"
msg9 db "press Del to back.","$"
msg10 db "all the keys are off.","$"
border db 0dah,50 dup(0c4h),0bfh,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0b3h,50 dup(32),0b3h,cr,lf
db 0c0h,50 dup(0c4h),0d9h,cr,lf,"$"
str1 db 10,13,"HELLO","$"
row_up db 11
row_down db 15
left_coloum db 25
right_coloum db 30
dataseg ends
codeseg segment 'code'
main proc far
assume cs:codeseg,ds:dataseg
mov ax,dataseg
mov ds,ax
start:
call cls
call disp_menu ;display menu
call read_char ;read character from keyboard
cmp al,49
je game ;select first item in menu
cmp al,50
je satute ;select second item in menu
cmp al,51
je exit ;select third item in menu
back:
call cls
mov dx,0c0eh
call locate ;set cursor in center
lea dx,msg1
mov ah,9h
int 21h ;print error
call read_char ;read character from keyboard
cmp al,27 ;press esc?
jne back
jmp start
;________________________PART 1___________________________
game:
call cls
call disp_border ;request display border
call disp_hello ;request display hello
lup:
call read_char ;read character from keyboard
cmp ah,72 ;press up arrow?
jne L1

call cls
dec row_up
dec row_down
call disp_border
call disp_hello
jmp lup
L1:
cmp ah,80 ;press down arrow?
jne L2

call cls
call disp_border
inc row_down
inc row_up
call disp_hello
jmp lup
L2:
cmp ah,75 ;press left arrow?
jne L3

call cls
call disp_border
dec left_coloum
dec right_coloum
call disp_hello
jmp lup
L3:
cmp ah,77 ;press right arrow
jne L4

call cls
call disp_border
inc left_coloum
inc right_coloum
call disp_hello
jmp lup
L4:
cmp ah,83 ;press delete key?
jne L5
call cls
call disp_menu
L5:
call cls
mov dx,0c0eh
call locate ;set cursor in center
lea dx,msg1
mov ah,9h
int 21h ;print error
call read_char ;read character from keyboard
cmp al,27 ;press esc?
jne back
jne L5
jmp start
;________________________PART 2___________________________
satute:
mov ah,12h
int 16h
mov n,al
p1:
mov cl,1
shl n,cl
jc p2
back1:
shl n,1
jc p3
back2:
shl n,1
jc p4
back3:
shl n,1
jc p5
back4:
jmp p6
p2:
mov dl,5
mov dh,8
call locate ;set cursor in(5,8)
lea dx,msg2
mov ah,09h
int 21h
jmp back1
p3:
mov dl,7
mov dh,8
call locate ;set cursor in(7,8)
mov ah,9h
lea dx,msg3
int 21h
jmp back2
p4:
mov dl,9
mov dh,8
call locate ;set cursor in(9,8)
mov ah,9h
lea dx,msg4
int 21h
jmp back3
p5:
mov dl,11
mov dh,8
call locate ;set cursor in(11,8)
mov ah,9h
lea dx,msg5
int 21h
jmp back4
p6:
mov dl,22
mov dh,32
call locate ;set cursor in (22,32)
mov ah,9h
lea dx,msg6
int 21h
p7:
call read_char ;read character from keyboard
cmp ah,27 ;press esc?
jne p7
jmp start
;_________________________part 3____________________________
exit:
call cls
mov dh,10
mov dl,34
call locate ;set cursor
lea dx,msg7
mov ah,09h
int 21h
mov dh,13
mov dl,36
call locate ;set cursor
lea dx,msg8
mov ah,09h
int 21h
mov ax,4c00h
int 21h
main endp
;************************************************* *************
disp_menu proc near
mov dh,0
mov dl,0
call locate ;set cursor in (0,0)
mov ah,9h
lea dx,menu
int 21h
ret
disp_menu endp
;************************************************* *************
disp_border proc near
mov dh,0
mov dl,0
call locate ;set cursor in (0,0)
mov ah,9h
lea dx,border
int 21h
mov dh,17h
mov dl,10h
call locate ;set cursor in(24,10)
mov ah,9h
lea dx,msg9
int 21h ;print message for back to the menu
ret
disp_border endp
;************************************************* *************
disp_hello proc near
mov dh,row_up
mov dl,left_coloum
call locate ;set cursor in(row_up,left_colume)
mov ah,9h
lea dx,str1
int 21h
ret
disp_hello endp
;************************************************* *************
locate proc near
mov ah,2h
mov bh,0
int 10h
ret
locate endp
;************************************************* *************
cls proc near
mov ah,6h
mov al,25
mov cx,0000h
mov dx,184fh ;full screen
mov bh,7
int 10h
ret
cls endp
;************************************************* ************
read_char proc near
mov ah,10h
int 16h
ret
read_char endp
;************************************************* ************
codeseg ends
end main