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