2014-04-01 39 views
0
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: 

那么我应该为每个条件使用什么样的跳转语句(总和> 5000或计数= 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: 

回答

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: