首页 > 解决方案 > 如何在以下代码中找到 AX 和 BX 的最后一个值?

问题描述

    mov ax, 15
    mov bx, 0Fh
    cmp ax,bx
    jle a1
    mov bx,10
    mov cx,3
    jmp a2
 a1:
    move ax,12
    mov cx,5
 a2:
    dec ax
    inc bx
    loop a2;

标签: assemblyx86-16

解决方案


只需一一阅读说明(例如使用说明查看每条指令的作用)

    mov ax, 15     # ax = 15
    mov bx, 0Fh    # bx = 15 (since 0Fh = 15)
    cmp ax,bx      
    jle a1         # if (ax <= bx) jump to a1 -> true
    mov bx,10      # Therefore these not executes
    mov cx,3
    jmp a2
 a1:
    mov ax,12      # ax = 12
    mov cx,5       # cx = 5
 a2:
    dec ax         # ax = ax - 1
    inc bx         # bx = bx + 1
    loop a2;       # cx = cx - 1 AND if (cx != 0) then jump to a2. Since cx is 5 when
                   # reaching here therefore looping 4 times which means overall the
                   # effect is ax = ax - 4 = 12 - 4 = 8 and bx = bx + 4 = 15 + 4 = 19

执行此代码后,AX 为 8,BX 为 19。

基于@ecm 的鹰眼观察进行了更正。


推荐阅读