开发者

8086 assembly Shift subtract and Divide

Hey guys this is my first time posting so be nice to me! I have to make a program that shifts and subtracts to eventually divide two numbers. I have already made a program that can shift add and multiply... Just need to divide now. This is what I have so far. You have to make a program with a menu, that asks the users for 2 inputs and then it adds, subtracts, multiplies and then divides.

product_a_b proc near
        clc
        push ax 
        push cx
        push bx
        push si
        push dx 
        push di
        push bp

        mov si, 00h
        mov ax, 00h         
        mov bx, 00h
        mov dx, 00h
        mov cx, 00

        mov al, A[si]
        mov ah, A[si+1]
        mov dl, B[bx]
        mov dh, B[bx+1]

        mov bp, 10h

multiply:   TEST DX, 01B

        jz  skip             
        add  cx, ax

skip:       rcr  cx, 01
        rcr  dx, 01
        dec  bp               ; dec number
        jnz  multiply                           

        mov [di],dl
        mov [di+1],dh
        mov [di+2],cl
        mov [di+3],ch

        pop bp
        pop di                        
        pop dx
        pop si
        pop bx
        pop cx
        pop ax
        ret               
product_a_b endp               

QUOTIENT_A_B proc near
        clc
        push ax 
        push cx开发者_JAVA百科
        push bx
        push si
        push dx 
        push di
        push bp

        mov si, 00h
        mov ax, 00h         
        mov bx, 00h
        mov dx, 00h
        mov cx, 00

        mov dl, A[si]          ;ax = m 
        mov dh, A[si+1]
        mov al, B[bx]          ; dx = q
        mov ah, B[bx+1]        ; cx = a

        mov bp, 10h

divide:     rcl  cx, 01
        rcl  dx, 01  
        cmp  cx, dx         
        jb   div_add
        dec  bp               ; dec number
        jnz  divide                           

div_add:    add cx, dx
        jmp divide


        mov [di],dl
        mov [di+1],dh
        mov [di+2],cl
        mov [di+3],ch

        pop bp
        pop di                        
        pop dx
        pop si
        pop bx
        pop cx
        pop ax
        ret         
QUOTIENT_A_B endp  


Something like this may work:

; divide cx by dx, leaving the quotient in cx and the remainder in ax.
         mov  ax, 0
         mov  bp, 10h
divide:  sal  cx, 1
         rcl  ax, 1
         cmp  ax, dx
         jb   smaller
         sub  ax, dx
         inc  cx
smaller: dec  bp
         jnz  divide
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜