i am trying to learn assembly using TASM . How do i make the below program terminate . i.e jump to final: after entering wrong key say 3 times ??

.model small
.data 
        msg1   db  "- - - Enter y - - -",0dh,0ah,'$'
        msg2   db  0dh,0ah, "..Correct...Good luck ..",0dh,0ah,'$'
        msg3   db  "- - - try again - - -",0dh,0ah,'$'
.code
start:
        mov  ax, seg msg1
        mov  ds,ax
        mov  dx,offset msg1
        mov  ah, 09h
        int  21h
;
        mov  ah,01h
        int  21h
;
        mov  bl,al
        cmp  bl,'y'
        je   good
        cmp  bl,'y'
        jne  wrong

good:
        mov  ax, seg msg2
        mov  ds,ax
        mov  dx,offset msg2
        mov  ah, 09h
        int  21h
        jmp  final
;
wrong:
        mov  ax, seg msg3
        mov  ds,ax
        mov  dx,offset msg3
        mov  ah, 09h
        int  21h
        jmp  start
;
final:
        mov  ax, 4c00h
        int  21h
        end  start

Thank you …salem

My query being so elementary in essence could be a little monotonous to respond to for those refined, well-informed people. My limited awareness in this area tells me that probably I need to use a loop somewhere around the ‘wrong:’ and I need to put a value in cx counter register. But how to do all that is beyond my shallow awareness right now. So, it would of great assistance to me if you could put in writing those few lines of code needed that would smooth down this hindrance in my learning process. you will not be pestered again in this context.
Hope iam not asking too much…

Regards…

Only in the sense that you've almost walked a mile, so why are the last few yards suddenly so difficult?

What you've done so far seems harder than what's left to do.

Post an attempt, and we'll take it from there.

Many…many thanks for the very positive and encouraging stance noticeable in your reply.

Those lines of code that is presented earlier are what I almost got from the tutorials available on the net. (Of course not copied from any source). The time I spend on this Assembly land was mostly used up in trying to understand the meaning of instructions, processor directives and still many more puzzling oddities. And I have not reached any firm ground on this area.

The position is I never had time to think in parallel. But, you gave me a few tips to work out my problem, and I was able to get a direction to carry on. what little I could do is given below. Though, it has not solved the issue, it was a satisfying experience for me.

wrong:                     
        inc   cx             ; assuming initial value of cx=0
        cmp   cx,3     
        jl    start
        cmp   cx,3
        jb    final 
        mov   ax, seg msg3
        mov   ds, ax
        mov   dx, offset msg3
        mov   ah, 09h
        int   21h
        jmp   start
;
final:
        mov   ax, 4c00h
        int    21h
        end  start

Execution is not jumping out of the 'wrong' to 'final' even after a few wrong keypresses.May be cx is not incrementing. I would be very grateful, if you could make suitable corrections needed.

Regards….

Maybe use a debugger to watch what the code is doing. It's a vital tool which is well worth getting to know how to use.
For instance you could put a breakpoint on your inc cx instruction, and maybe observe it counting up (or maybe observe something else happening).

Are you sure cx is preserved through your use of those interrupts?
Or even initialised for that matter - you did put it before start right?

Assuming you still want to print the message on a wrong answer, I would have done

wrong:                     
        mov   ax, seg msg3
        mov   ds, ax
        mov   dx, offset msg3
        mov   ah, 09h
        int   21h
        inc   cx             ; assuming initial value of cx=0
        cmp   cx,3     
        ja    final ; or whatever the >= mnemonic is
        jmp   start

You might like this link
http://www.ctyme.com/intr/int.htm

Points you had made:

“ Are you sure cx is preserved through your use of those interrupts? Or even initialized for that matter “

i need to initialise cx register value ( i hadn’t done it ). Also, I think i need to make the program check the value of CX register, after every execution ( i haven’t done that too; because I don’t know how to do it).

Debugger:

“ use a debugger to watch what the code is doing “

i tried to open this exe in ollydebugger, but Olly refuses to open not only this particular file but all the .exe' s that i made using tasm . But an exe made using Borland compiler experience no such problem. So, there is something wide of the mark with myCoding+tasm Vs Olly. So, i would not be able to follow that tip given till i could resolve the issue with Olly.

Meanwhile, iam trying to learn the use of loop instruction and cx register (suppose that is what I need to learn/understand in this context).

The link provided for Interrupt jump table is very handy. Thank you once again.

Regards…

… When you had suggested the use of debugger, iam sure that you had meant the one that comes with windows. iam sorry… at first, i failed to think of the inbuilt Debugger. Later on, i opened the file in that debugger; used the –r to see the register ….and of course as you had suggested, I had a look at CX.

iam back with those few lines of assembly and still with CX register …Not able to make headway…trial by error doesn’t seem to work here. i have heard the expressions like backbreaking, clogged mind and so on... never experienced one so for. Now I’ve an idea … what it is like...

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.