繁体   English   中英

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

[英]how to add/sub/div/mul more than 4 values? assembly language

一个非常新手的问题,如何使用超过4个值来表示算术方程?

(14×3)+ 16 / 4-3

 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 

首先,MUL和DIV仅接受1个参数。 搜索“ 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 r16dx:ax除以r16 ,将结果放入ax ,其余部分放入dx

您的计算

像这样计算14×3 + 16/4 - 3

    ; 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

希望您能理解!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM