-1

I have to write a program in 8086 assembly that calculates this:

(a+b*c+2/c)/(2+a)+e

where

a,b - byte

c - word

e - doubleword,

in unsigned interpretation.

So far I have this:

assume cs:code,ds:data

data segment

    a db 4
    b db 2
    c dw 16
    e dd 126
    data ends

code segment
start:

    mov ax,data
    mov ds,ax

and here is my program

    mov al,b ; al=b
    mov ah,0 ; ax=b;
    mul c; dx:ax=b*c; b*c=doubleword
    mov bx,ax; we save b*c in bx to use ax in the division 2/c
    mov al,2; al=2
    mov ah,0; al=ax=0
    div c; ax=dx:ax/c ; dx=dx:ax%c;

I don't know how to continue.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Boolean
  • 27
  • 6
  • You need help. See [**Art of Assembly**](https://courses.engr.illinois.edu/ece390/books/artofasm/artofasm.html) Particularly [**Arithmetic Operations**](https://courses.engr.illinois.edu/ece390/books/artofasm/CH06/CH06-2.html#HEADING2-1) and [**Sign and Zero Extension**](https://courses.engr.illinois.edu/ece390/books/artofasm/CH01/CH01-2.html#HEADING2-151) – David C. Rankin Nov 02 '14 at 22:52

1 Answers1

0

When you write

mov bx,ax; we save b*c in bx to use ax in the division 2/c  

you're actually only saving the low word of the product between B and C. It works with the numbers provided but it's not a general solution.

In stead of writing

mov al,2; al=2
mov ah,0; al=ax=0  

use mov ax,2 and remember to explicitely clear the DX register because the division needs it.

To continue I would suggest you create a result variable of doubleword size because in the end the size of your largest expression participant defines the size of the result. Then on the way move or add your partial results to this variable.
If you are allowed to use 32 bit registers a suitable approach might be to promote all values to 32 bit and continue from there.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76