Calculating (\$a^2\$ + \$b(2c-d)^2)/(3e)\$ in assembly

2018-03-09 08:40:51

I made a simple assembly program to evaluate the function

$$f =\frac{a^2 + b(2c-d)^2}{3e}$$

Since this is basically my first ever, I would like to hear what I can improve and know how to use registers better.

.model small

.stack 100h


a dw 4

b dw 15

c dw 86

d dw 155

e dw 8

res dw 0;


mov ax,@data

mov ds,ax

mov dx,0

mov bx,0

mov cx,0

mov ax,c

shl ax,1

mov bx,d

sub ax,bx

mul ax

mul b

mov dx,ax

push dx

mov dx,0

mov ax,a

mul ax

pop cx

add ax,cx

mov dx,ax

push dx

mov dx,0

mov ax,e

mov bx,3

mul bx

mov bx,ax

pop cx

mov ax,cx

mov cx,bx

div cx

mov ax,4c00h

int 21h