简体   繁体   English

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

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

very newbie question, how can I express arithmetic equations using more than 4 values? 一个非常新手的问题,如何使用超过4个值来表示算术方程?

(14×3) + 16/4-3 (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 

First, MUL and DIV only take 1 argument. 首先,MUL和DIV仅接受1个参数。 Search for 'intel mul' and 'intel div' to see the instruction details: 搜索“ intel mul”和“ intel div”以查看说明详细信息:

For 8 bits: 对于8位:

Using an 8 bit register r8 as argument (where r8 is one of the 16 8 bit registers), 使用8位寄存器r8作为参数(其中r8是16个8位寄存器之一),

  • MUL r8 wil multiply r8 with al and store the result in ax . MUL r8r8al相乘并将结果存储在ax This is because, for instance, multiplying 127 with 127 is bigger than 8 bits (but never more than 16). 这是因为,例如,将127与127相乘大于8位(但绝不超过16位)。
  • Similarly, div r8 will divide ax by r8 , put the result in al , and the remainder in ah . 类似地, div r8ax除以r8 ,将结果放入al ,其余部分放入ah

For a 16 bit argument: 对于16位参数:

  • MUL r16 will multiply r16 (a 16 bit register) with ax , and store the result in dx:ax , ie, the high word in dx , and the low word in ax . MUL r16r16 (16位寄存器)与ax相乘,并将结果存储在dx:ax ,即dx的高位字和ax的低位字。

  • Again similarly, DIV r16 will divide dx:ax by r16 , put the result in ax and the remainder in dx . 同样, DIV r16dx:ax除以r16 ,将结果放入ax ,其余部分放入dx

Your calculation 您的计算

Calculating 14×3 + 16/4 - 3 is done like this: 像这样计算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

I hope you get the idea! 希望您能理解!

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

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