Group 4 Code Report Final Copy Review

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

KYAMBOGO UNIVERSITY

SCHOOL OF COMPUTING AND INFORMATION SCIENCE

DEPARTMENT OF COMPUTER SCIENCE

BACHELOR OF INFORMATION TECHNOLOGY AND COMPUTING

COURSE UNIT: MICROPROCESSOR BASED SYSTEM DESIGN

COURSE CODE: SCS3202

LECTURER: MR. MATOVU MOSES

COURSEWORK III

GROUP 4 MEMBERS

NAME REGISTRATION NUMBER


AHIKIRIZA HENRY 19/U/ITD/017/GV
KYASIIMIRE KELLEN 19/U/ITD/20336/PD
BUGEMBE JOHN PAUL 19/U/ITD/080/GV
NANSOVE VANESSA 19/U/ITD/2962/PD

Question 7

a) Implement the expression 3(x2 − x − 1)/2 in assembly language.

(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

The instructions used in this implementation include;

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

Implementation and Testing

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

msg1 db 'Enter the Value of x: $'

x db 0

msg2 db 10,13, 'x*x evaluates to $'

msg3 db 10,13,'x*x-x evaluates to $'

1
msg4 db 10,13,'x*x-x-1 evaluates to $'

msg5 db 10,13,'3(x*x-x-1) evaluates to $'

quotient db 10,13,'3(x*x-x-1)/2 evaluates to $'

remainder db 10,13, 'Remainder $'

In the main program we capture user input as shown below

mov dx, offset msg1

mov ah,09h

int 21h

;capturing the value of x

mov ah,1h

int 21h

mov x,al ;temporarily storing the value of x in memory location x

sub x,30h ; converts ASCII value to hexadecimal

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

mov bx,ax ;temporarily storing x2 result into BX register

;display x*x message

mov dx, offset msg2

2
mov ah,09h

int 21h

Displaying x*x result

mov dl,bl

add dl,30h ;changing the value of dl from hexadecimal to ASCII

mov ah,2h

int 21h

Output on the Screen

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

sub bl,x ;result in bl

Displaying the value of x*x –x on the screen

mov dx, offset msg3

mov ah,09h

int 21h

mov dl,bl ;the value of bl is moved to dl register

add dl,30h ;changing the value of dl from hexadecimal to ASCII

3
mov ah,2h

int 21h

Output of x*x-x on the screen

The evaluation continue by subtracting 1 from the above result which results to 1 for example

dec bl ;it decrements the value of bl register by 1

Displaying the value of x*x-x-1 on the screen

;subtracting x*x-x-1

dec bl

mov dx, offset msg4

mov ah,09h

int 21h

mov dl,bl

add dl,30h ;changing the value of dl from hexadecimal to ASCII

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 dx, offset msg5

mov ah,09h

int 21h

;displaying numerator

mov dx,cx

add dx,30h ;changing the value of dx from hexadecimal to ASCII

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

mov bl,al ;moving quotient to bl register

mov bh,ah moving remainder to bh register to avoid replacing it

6
The Remainder of 3(x*x-x-1) is divided by 2 is 1 as shown below

Testing the Implementation

• 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

• 3 (x*x-x-1)/2 = 3/2 = 1 as the quotient

• And Remainder = 1 which proves to be as Implemented.

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

https://www.elprocus.com/8086-assembly-language-programs-explanation/ visited on 31st


January 2023 at 10:00pm

You might also like