Group 4 Code Report Final Copy Review
Group 4 Code Report Final Copy Review
Group 4 Code Report Final Copy Review
COURSEWORK III
GROUP 4 MEMBERS
Question 7
(b) Use a data set of your choice to test this implementation and comment on your result(s) by
giving details of how and where the outcomes are stored after every step or operation evaluated.
Introduction
This report gives the details on how to solve 3(x2-x-1)/2 in assembly language using emulator
8086 including instructions, registers used and the screenshots partial evaluations until final
result on the screen.
Registers Used
We have used 16 bit and 8 bit registers for example DX, AL, BL, DL, AH
Instructions Used
MOV – it was used to store values in register for example mov AL,3 copies a value 3 to AL
register.
ADD and SUB –These are used to increase the value of a register and decrease the value of a
register by a certain value respectively.
IMUL and MUL –They are used for multiplication of signed and unsigned bits respectively.
IDIV and DIV –They are used for division of signed and unsigned bits respectively.
DEC – Used to decrease content of register by 1 for example DEC AL decrease content of AL
register by 1
In this implementation, the user is asked to enter positive integers to solve 3(x2-x-1)/2. This
report gives output at each stage in the evaluation of 3(x2-x-1)/2. For testing purpose the value 2
has been used as the user input.
Variables Declared
All the variables that are to be used in the assembly program are declared in the .data section as
shown below.
.data
x db 0
1
msg4 db 10,13,'x*x-x-1 evaluates to $'
mov ah,09h
int 21h
mov ah,1h
int 21h
After inputting x value, the program evaluates x*x, for this case its 2*2 = 4 as shown below
;multipying x*x:
mul al ;result in AX
2
mov ah,09h
int 21h
mov dl,bl
mov ah,2h
int 21h
The value of x is
The program then subtracts x-value that was stored in a memory location x from the product
result above for example x*x –x evaluates to 4-2 = 2 as shown below.
;subtracting x*x-x
mov ah,09h
int 21h
3
mov ah,2h
int 21h
The evaluation continue by subtracting 1 from the above result which results to 1 for example
;subtracting x*x-x-1
dec bl
mov ah,09h
int 21h
mov dl,bl
mov ah,2h
int 21h
for example 2-1=1 as shown below
4
On that evaluation of the bracket is done, we proceed to multiplying 3 by (x*x-x-1) which
evaluates to 3 for example 3*1 = 3.
The value 3 is moved into AL register which is then multiplied by the content of bl register as
shown below.
mov al,3
mul bl ;result in ax
Displaying the value of AX register, which give the results for the numerator
mov cx,ax
;display message
mov ah,09h
int 21h
;displaying numerator
mov dx,cx
mov ah,2h
int 21h
Output of 3(x*x-x-1)
5
Then the result of Multiplying 3 by (x*x-x-1) is divided by 2 which evaluates to 1 as the quotient
as shown below
mov ax,cx
mov bl,2
div bl ;result in ax
6
The Remainder of 3(x*x-x-1) is divided by 2 is 1 as shown below
• If x=2,
• x*x= 2*2=4,
• x*x-x = 4-2=2,
• x*x-x-1 =2-1 =1
• (x*x-x-1)=1
• 3 (x*x-x-1)= 3*1 =3
7
Conclusion
In Conclusion, This report has discussed how registers can be used to solve mathematical
problems in this case evaluating 3(x*x-x-1)/2 using different instructions such as mul and div,
sub as described above.
8
References