Question

Question:

Divide A into B , assume A < B. The answer will be A goes into B q times with a remainder of R

Example: 7 goes into 20 2 times remainder 6

Hint: Subtract A from B until A>the difference. Count how many times you subtracted and the difference should be the remainder.

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

This is my code. It's not complete. I don't know how to do this problem. Any help would be grateful.

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
Was it helpful?

Solution

A loop is implemented like this:

loop down:

    mov   ecx, 10   ; count from 10 to 0

 label:
    dec   ecx
    loop label

loop up:

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

Now think how your algorithm works and how to apply this information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top