8086 汇编 移位减除

发布于 2024-11-19 06:46:07 字数 1942 浏览 3 评论 0原文

大家好,这是我第一次发帖,请对我好一点!我必须编写一个程序来进行移位和减法以最终除以两个数字。我已经编写了一个可以移位加法和乘法的程序......现在只需要除法。这是我到目前为止所拥有的。你必须制作一个带有菜单的程序,要求用户输入 2 个输入,然后进行加、减、乘、除。

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
        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  

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
        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  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阪姬 2024-11-26 06:46:07

像这样的事情可能会起作用:

; 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文