首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何添加/sub/div/mul超过4个值?汇编语言

如何添加/sub/div/mul超过4个值?汇编语言
EN

Stack Overflow用户
提问于 2015-10-21 20:33:33
回答 1查看 1.5K关注 0票数 1

非常新鲜的问题,我如何用4个以上的数值来表达算术方程?

(14×3) + 16/4-3

代码语言:javascript
运行
复制
ORG 0
MOV AL, E
MOV BL, 3
MUL AL, BL
;
MOV CL, 10
MOV DL, 4
DIV CL, DL
;
ADD AL, CL
MOV ??, 03 <--- what to put, DL is the last register
SUB AL, ?? <--- what to do 

END

EN

回答 1

Stack Overflow用户

发布于 2015-10-21 20:59:27

首先,MUL和DIV只进行了一次论证。搜索“intel mul”和“intel div”以查看详细说明:

8双边投资条约:

使用8位寄存器r8作为参数(其中r8是16位8位寄存器之一),

  • MUL r8r8al相乘,并将结果存储在ax中。这是因为,例如,将127乘以127大于8位(但不超过16位)。
  • 类似地,div r8ax除以r8,将结果放在al中,其余的在ah中。

对于16位参数:

  • MUL r16r16 ( 16位寄存器)与ax相乘,并将结果存储在dx:ax中,即dx中的高字,ax中的低字。
  • 同样,DIV r16将把dx:ax除以r16,将结果放在ax中,其余的在dx中。

你的计算

计算14×3 + 16/4 - 3的步骤如下:

代码语言:javascript
运行
复制
    ; First term: 14x3
    mov al, 14
    mov bl, 3
    mul bl        ; ax = 42 (or, al=42 and ah=0)


    ; next we're going to DIV, which uses `AX`, so we better copy our result out of ax:
    mov cx, ax    ; or: mov cl, al


    ; Second term, 16/4 (16/3 would be more interesting!)
    mov ax, 16    ; we could mov al, 16 since ah is already 0
    mov dl, 4
    div dl        ; now al=4 and ah=0  (With 16/3, al=5 and ah=1!)


    ; Add to our result:
    add cl, al
;   adc ch, 0     ; take care of overflow if we want a 16 bit result


    ; calculate the 3rd term    
    mov al, 3     ; that was easy :-)

    ; and add the 3rd term to our result:
    sub cl, al    ; we could have done sub cl, 3

我希望你知道这个主意!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33268699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档