如何在程序集x86中使用cmp参数

时间:2015-03-30 16:20:00

标签: assembly x86

我的cmp命令出了问题。无论我传递什么结果,程序都会忽略cmp结果并运行我的代码的所有部分。有人可以帮帮我吗?

     ;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

我很擅长集会,我有一个非常糟糕的老师,用#34;使用google"来解决我们的所有问题,忽略了有很多装配类型,而且它真的不是& #39; ta直接语言。

1 个答案:

答案 0 :(得分:1)

的问题
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

如下:

  • 如果[tipoBandeira] = 1,则执行T1,然后执行T2
  • 如果[tipoBandeira] = 2,则执行T2
  • 如果[tipoBandeira]其他,则执行T1,然后执行T2

你错过了比较和T1阻止的退出。 你想要的可能是:

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
...
相关问题