如何在汇编语言语句之前实现此操作?

时间:2014-04-01 02:33:09

标签: loops assembly

b) sum = 0; count = 1; repeat (add count to sum; add 1 to count); until (sum > 5000) or (count = 40);
Answer:
    mov sum, 0
    mov ecx, 1
untilB: add sum, ecx
    inc ecx
    cmp sum, 5000
    **what comes after this?**
enduntilB:

那么我应该为每个条件使用什么样的跳转语句(sum> 5000或count = 40)?

此外:

c) sum = 1000; for count = 100 downto 50 (subtract (2 * count) from sum); end for;
Answer:
    mov sum, 1000
    mov ecx, 100
forC:   cmp ecx, 50
    jnge endforC
    **what comes after this?**
    dec ecx
    jmp forC
endforC:

1 个答案:

答案 0 :(得分:0)

这样的事情:

    mov sum, 0
    mov ecx, 1
untilB: add sum, ecx
    inc ecx
    cmp sum, 5000
    jg enduntilB
    cmp ecx, 40
    je enduntilB
    jmp untilB
enduntilB:

    mov sum, 1000
    mov ecx, 100
forC:   cmp ecx, 50
    jl endforC
    imul eax, ecx, 2
    //
    // alternatively:
    // mov eax, ecx
    // shl eax, 1
    //
    // alternatively:
    // mov eax, ecx
    // add eax, eax
    //
    dec sum, eax
    dec ecx
    jmp forC
endforC: