Orange Lash
Orange Lash

Reputation: 11

How to work with the cmp parameter in assembly x86

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.

Upvotes: 1

Views: 1181

Answers (1)

Alexander Zhak
Alexander Zhak

Reputation: 9282

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

Upvotes: 1

Related Questions