1

I'm having problems in my cmp commands. No matter what result I may pass, the program ignores the cmp result and runs all parts of my code. Can anyone help me please?

 ;tipo de bandeira mov ah, 40h mov bx, 1 mov cx, 24 mov dx, bandeira int 21h ;linha mov ah, 40h mov bx, 1 mov cx, 1 mov dx, linha int 21h ;input e confirmação do tipo de bandeira mov ah, 3Fh mov bx, 00 mov cx, 1 mov dx, tipoBandeira int 21h ;clear feed mov ah, 3Fh mov bx, 00 mov cx, 2 mov dx, crlf int 21h cmp[tipoBandeira],01 je T1 cmp[tipoBandeira],02 je T2 T1: mov ah, 40h mov bx, 1 mov cx, 08 mov dx, quad int 21h T2: mov ah, 40h mov bx, 1 mov cx, 11 mov dx, rect int 21h 

I'm pretty new to assembly, and I have a pretty lousy teacher that awnsers all our questions with "use google", ignoring that there are a lot of assembly types and that it really isn't a straight-forward language.

1
  • After the je T2 if the condition is failed the code execution continues so that will run your T1. Also, after T1 the code continues into T2. You should add some unconditional jump to avoid the fall-through. Draw a flowchart if that helps. Commented Mar 30, 2015 at 16:27

1 Answer 1

1

The problem with

cmp [tipoBandeira],01 je T1 cmp [tipoBandeira],02 je T2 T1: mov ah, 40h mov bx, 1 mov cx, 08 mov dx, quad int 21h T2: mov ah, 40h mov bx, 1 mov cx, 11 mov dx, rect int 21h 

is the following:

  • if [tipoBandeira] = 1, then execute T1, then T2
  • if [tipoBandeira] = 2, then execute T2
  • if [tipoBandeira] other, then execute T1, then execute T2

You're missing exits from compare and T1 blocks. What you want is probably something like:

cmp [tipoBandeira],02 ;if tipoBandeira = 2 je T2 ; go to T2 cmp [tipoBandeira],01 ;else if tipoBandeira = 1 jne EXIT ; go to T1 ;else go to EXIT T1: mov ah, 40h mov bx, 1 mov cx, 08 mov dx, quad int 21h jmp EXIT ;end if T2: mov ah, 40h mov bx, 1 mov cx, 11 mov dx, rect int 21h EXIT: ;end if ... 
Sign up to request clarification or add additional context in comments.

4 Comments

i usually work in c so this language is a bit confusing for me. i originally wanted some sort of if-statement so that, if tipoBandeira is equal to 1 it would run T1 but not T2. also what does EXIT: do? i would need to run a separate code if any of the conditions were true, would that code be in exit?
separate code if any of the conditions were true yes, unless by "any condition" you mean really any, but not only if (var == 1 || var == 2). jumps are simple - if you need to skip some part - jump over it
ok, so i altered the code to: cmp [tipoBandeira],01 je T1 cmp [tipoBandeira],02 jmp T2 T1: mov ah, 40h mov bx, 1 mov cx, 08 mov dx, quad int 21h jmp s1 T2: mov ah, 40h mov bx, 1 mov cx, 11 mov dx, rect int 21h s1: thing is, i would then have to ask and compare another value and, by using both values, draw either a x-color square or rectangle. Would i have to then use 2 cmp´s or just jump from part to part?
cmp [tipoBandeira],02 / jmp T2 this one will be taken always. should be je T2 / jmp <code_which_will_run_if_neither_1_nor_2>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.