loops - Counter not working after jumps - assembly language -


for reason, when switch mouse input switch keyboard input program, increasing , decreasing counter has no effect. works in first loop input characters. here program, advice? @ whatspeed jump reference after mousetime jump. cx counter not updating or along lines. (i not know if counter not updating or weather there problem occuring in comparing cx after switch mousetime keytime . )

    clear   macro     mov ax,0600h     mov bh,07     mov cx,0000     mov dx,184fh     int 10h   endm    cursor  macro col, row     mov ah,02     mov bh,00     mov dl,col     mov dh,row     int 10h   endm  disp   macro mes     mov ah,09     mov dx,offset mes     int 21h endm  clearline macro row     cursor 00,row     disp spaces     endm  alwaysonscreeninfo macro         cursor 16,00         disp title1         cursor 50,00         disp names1          cursor 54,01         disp names2         cursor 33,7         disp menu         cursor 24,9         disp option1         cursor 24,10         disp option2         cursor 22,11         disp dashes         cursor 18,12         disp mousemenu         cursor 14,13         disp option3         cursor 8,14         disp option4         cursor 13,15         disp charmenu         cursor 21,16         disp kill endm  .model small ; run program in dimensions 79x24  .stack 64h .data  title1          db      'microprocessor - eeng410','$' names1          db      'name1 & name2','$' names2          db      'std1         std2','$' menu            db      'menu','$' option1         db      '1. press "u" speed motor','$' option2         db      '2. press "d" slow down motor','$' option3         db      '1. right click mouse turn motor direction clockwise','$' option4         db      '2. left click mouse turn motor direction anti-clockwise','$' dashes          db      '----------------------------------------','$' mousemenu       db      '(press m switch mouse options)','$' charmenu        db      '(press scroll button switch fist 2 options)','$'  speedup         db      'dc motor speeding ','$' slowdown        db      'dc motor slowing down','$' right           db      'dc motor rotate clockwise','$' left            db      'dc motor rotate anti-clockwise','$' kill            db      '-----to exit program, press "e"-----','$' programend1     db      'thank using our program','$' programend2     db      'the program has been terminated','$' spaces          db      '                                                                                    ','$' try             db      'please try again','$' speednow        db      'speed:','$' direction       db      'motor direction:','$' clock           db      'right','$' counter         db      'left  ','$' n1              db      '1','$'   n2              db      '2','$' n3              db      '3','$' n4              db      '4','$' n5              db      '5','$' n6              db      '6','$' n7              db      '7','$' maxspeed        db      'max speed 7','$' minspeed        db      'min speed 1','$'    .code main:   mov ax,@data         mov ds, ax         clear         alwaysonscreeninfo          mov cx,1         cursor 28,21         disp speednow         cursor 35,21         disp n1         cursor 22,22         disp direction         cursor 39,22         disp clock         mov cx,1 l0:     mov ah,00   ;loop start         int 16h         cmp al,' '         je spaced         cmp al,'u'         je faster         cmp al,'u'         je faster         cmp al,'d'         je slower         cmp al,'d'         je slower         cmp al,'m'         je mousetime         cmp al,'m'         je mousetime         cmp al,'e'         je exit         cmp al,'e'         je exit         jne tryagainkey  a1:     mov ax,03         int 33h         cmp bx,0         je a1         cmp bx,1    ;mouse left         je mright         cmp bx,2    ;mouse right         je mleft         cmp bx,3         je keytime  spaced: clearline 19         jmp l0  faster: clearline 19         cursor 27,19         disp speedup         jmp increase  slower: clearline 19         cursor 27,19         disp slowdown         jmp decrease  mousetime:  jmp a1 keytime:    jmp l0  mright: clearline 19         cursor 18,19         disp right         jmp tright  mleft:  clearline 19         cursor 18,19         disp left         jmp tleft  tryagainkey:    clearline 19                 cursor 28,19                 disp try                 jmp l0   increase: cmp cx,7           je cannotincreasespeed           inc cx           jmp whatspeed  decrease: cmp cx,1           je cannotdecreasespeed           dec cx           jmp whatspeed  tright: cursor 39,22         disp clock         jmp a1  tleft:  cursor 39,22         disp counter         jmp a1  cannotincreasespeed:    clearline 19                         cursor 27,19                         disp maxspeed                         jmp l0  cannotdecreasespeed:    clearline 19                         cursor 27,19                         disp minspeed                         jmp l0  whatspeed:  cmp cx,1             je n11             cmp cx,2             je n22             cmp cx,3             je n33             cmp cx,4             je n44             cmp cx,5             je n55             cmp cx,6             je n66             cmp cx,7             je n77  n11:    cursor 35,21         disp n1         jmp l0 n22:    cursor 35,21         disp n2         jmp l0 n33:    cursor 35,21         disp n3         jmp l0 n44:    cursor 35,21         disp n4         jmp l0 n55:    cursor 35,21         disp n5         jmp l0 n66:    cursor 35,21         disp n6         jmp l0 n77:    cursor 35,21         disp n7         jmp l0 exit:   clear         cursor 21,12         disp programend1         cursor 21,13         disp programend2         mov ah, 4ch         int 21h     end main 

the fault caused because mouse interrupt 33h function ax=0003h returns mouse position in cx , dx.

this overwrites "counter" in register cx.

it dangerous game keep values in registers throughout program. better have memory variable location.

you try push cx before executing mouse functions , pop cx after, program structure , flow might not conducive (i have not followed fully).

also, reason why program not recover (in context) absurd value of cx because of test instruction used. example here

increase: cmp cx,7           je cannotincreasespeed 

you must cautious , trap any value out of range (even if think won't be)

          jge cannotincreasespeed 

also with

cannotincreasespeed: mov cx,7    ;clamp value ... 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -