简体   繁体   中英

Multiplication, Division, Substraction and Addition in same Assembly Language Program

Does anyone knows how can one perform all four mathematical operations (Multiplication, Division, Substraction and Addition) in a single program for 8 BIT/16 BIT operands. I am able to perform maximum three programs using AL,BL,CL,DL registers but i am unable to understand where should i store the values afterwards because AL is required for both DIV,MUL operations.

All efforts shall be appreciated if anyone could come up with a simple program or logic at least.

Code:

;================== Header ==================
; File:         all.asm
; Author:       Anurag Shukla
; Date:         25/02/2013
;================== Directives ==================

[BITS 16H]
[ORG 100H]

;================== Code Segment ==================
[SECTION .text]

mov al,0
mov bl,0
mov cl,0
mov dl,0
mov si,0
mov di,0
;================== Addition 
mov bp, 10H
add bp, [NUMADD]
daa

mov di, 20H
sub di, [NUMSUB]
das

mov al, 10H
mov bl, 10H
mul bl
mov [RMUL],al
mov dl,[RMUL]

mov al, 10H
mov bl, 2H
div bl


int3


[SECTION .DATA]

NUMADD: DB 10H
NUMSUB: DB 10H
RSUB: DB 0H
RSUM: DB 0H
RMUL: DB 0H
RDIV: DB 0H

You can save your intermediate results on the stack or in some kind of buffer.

If you die to use the registers only, you still have ECX , ESI , EDI and EBP (and ESP in exceptional cases) handy while ultimately using EAX , EDX and EBX as inputs and outputs for the desired operations.

For example, if you want to have the results of all four operations after executing them sequentially, you could store EAX + EBX in ECX , EAX - EBX in EBP , EAX x EBX in ESI:EDI and simply keep EAX / EBX in EDX:EAX .

Anyways, the memory is there for the purpose of storing data, so I'd suggest sticking to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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