通过减法划分

时间:2013-12-05 17:37:59

标签: assembly x86 masm irvine32

问题:

  

将A除以B,假设A< B.答案将是A进入B q   剩余时间为R

的时间      

示例:7进入20 2次剩余6

     

提示:从B减去A直到A>差异。算一下多少次   你减去了,差异应该是余数。

Ex  20-7 = 13 
    13 – 7 = 6
    6 <7 so the count is 2 and the remainder is 6

这是我的代码。它不完整。我不知道该怎么办这个问题。任何帮助都会很感激。

TITLE       PROJECT
INCLUDE Irvine32.inc
.data
prompt1 byte 'Enter number A:',0
prompt2 byte 'Enter number B:',0
a dword ?
b dword ?
remainder dword ?
.code
main proc
    call clrscr

    mov eax,0
    mov ebx,0
    mov edx,offset prompt1
    call writestring
    call readint
    mov a,eax

    mov edx,offset prompt2
    call writestring
    call readint
    mov b,ebx

    mov eax,a
    mov ebx,b
    sub ebx,a       ;set edx to 0
    div ebx
    mov remainder,ebx
    ;xor eax,eax


    call writedec
    call crlf

exit
main ENDP
END main

1 个答案:

答案 0 :(得分:1)

循环实现如下:

循环播放:

    mov   ecx, 10   ; count from 10 to 0

 label:
    dec   ecx
    loop label

循环:

   xor  ecx,ecx   ; count from 0 to 10
 label:
   inc ecx
   cmp ecx, 10
   jne label

现在想想你的算法如何运作以及如何应用这些信息。