20
SUBMITTED BY- Team #NoFrazzle 1. Md Sanzidul Islam 151-15- 5223 2. Farhan Tawsif Chowdhury 151-15-4705 3. Nazmul Ahsan 151-15- 4668 SUBMITTED TO - Ms. Bashira Akter Anima Lecturer, Dep. Of CSE, Date of Submission : 18 th December, 2016 PROJECT REPORT ON “TRICKY MATH PUZZLE” COURSE : MICROPROCESSOR &ASSEMBLY LANGUAGE COURSE CODE : CSE 231

Tricky math puzzle project report

Embed Size (px)

Citation preview

Page 1: Tricky math puzzle project report

SUBMITTED BY -

Team #NoFrazzle1. Md Sanzidul Islam 151-15-

52232. Farhan Tawsif Chowdhury

151-15-47053. Nazmul Ahsan

151-15-46684. Md. Mahbubur Rahman

SUBMITTED TO -

Ms. Bashira Akter Anima

Lecturer, Dep. Of CSE,Daffodil International

Date of Submission: 18th December, 2016

PROJECT REPORT ON “TRICKY MATH PUZZLE”

COURSE: MICROPROCESSOR &ASSEMBLY LANGUAGE

COURSE CODE: CSE 231

Page 2: Tricky math puzzle project report

Abstract & Hints:

The purpose of this project is to design and build a math puzzle game that will give user the experience of solving various tricky math puzzle through gaming.

This was achieved through several steps. In background, we used programming language Assembly. Instructions like conditions, loops, call procedure & various types of registers and their uses, what we learned throughout our courses.

What is assembly language?

An assembly language is a programming language that can be used to directly tell the computer what to do. An assembly language is almost exactly like the machine language that a computer can understand, except that it uses words in place of numbers. A computer cannot really understand an assembly program directly. However, it can easily change the program into machine code by replacing the words of the program with the numbers that they stand for. A program that does that is called an assembler. Programs written in assembly language are usually made of instructions, which are small tasks that the computer performs when it is running the program. They are called instructions because the programmer uses them to instruct the computer what to do. The part of the computer that follows the instructions is the processor. The assembly language of a computer is a low-level language, which means that it can only be used to do the simple tasks that a computer can understand directly. In order to perform more complex tasks, one must tell the computer each of the simple tasks that are part of the complex task. For example, a computer does not understand how to print a sentence on its screen. Instead, a program written in assembly must tell it how to do all of the small steps that are involved in printing the sentence.

Strength of assembly language:

1. The symbolic programming of Assembly Language is easier to understand and saves a lot of time and effort of the programmer.

2. It is easier to correct errors and modify program instructions.

Page 3: Tricky math puzzle project report

3. Assembly Language has the same efficiency of execution as the machine level language. Because this is one-to-one translator between assembly language program and its corresponding machine language program.

Disadvantages of assembly language:

1. One of the major disadvantages is that assembly language is machine dependent. A program written for one computer might not run in other computers with different hardware configuration.

Project Description & Demo:

When we start the game “Tricky Math Puzzle” we will have a POP-Up window showing this menu.

The first three options in this menu is our game segments.

If you choose option 1. you will get enter into math teaser game segment. In math teaser segment we put some discretional tricky mathematical question as like puzzle.

Page 4: Tricky math puzzle project report

Something like this,

Here we have multiple choice option. Here the correct answer is number two (2). So you have to input number two (2) from your key board. Thus you will get your correct answer and your point one (1) which we will be regarded for each correct answer.

Whether you give the right or the wrong answer you will automatically have the next puzzle after answering previous one. Because of we are in the developing state of our game so we just put five puzzles into first two segments. Farther puzzle will be coming soon. When you will be able to answer all this five question you will get all the points and encouraged to go into our next segment which is sequence and assumption.

This is the choice number two on the game menu. In this segment the gamer will have to face some sort of sequentially math puzzle.

So here this is the sample of a question. You have to give your assumption to complete the sequence. So we can see this is a Fibonacci series and complete the sequence the answer will be number three (3) and you will have your point.

Page 5: Tricky math puzzle project report

The third or final segment of our game is the most interesting one. Here we test our player assumption skill.

You will be asked to guess and input 3 digits. In program logic unit it automatically generate 3 random digits and compare/match with your imputed digits. If 1 digit will match, you will get 100$.If 2 digit will match, you will get 1000$. If 3 digit will match, you will get 10000$.Here we can see 1 digit will match and he/she get 100$. If anyone can play again you press 1.

If the gamer need any help he just have to get into choice 4 for help like how to operate this game, how to operate this menu and how to play this game what I just mention above. If you want to exit you just press 5.

Page 6: Tricky math puzzle project report

The Work Flow:

Page 7: Tricky math puzzle project report
Page 8: Tricky math puzzle project report

Background of Project : Conditional execution in assembly language is accomplished by several looping and branching instructions. These instructions can change the flow of control in a program. Conditional execution is observed in two scenarios −

SN Conditional Instructions

1 Unconditional jump

This is performed by the JMP instruction. Conditional execution often involves a transfer of control to the address of an instruction that does not follow the currently executing instruction. Transfer of control may be forward, to execute a new set of instructions or backward, to re-execute the same steps.

2 Conditional jump

This is performed by a set of jump instructions j<condition> (i.e. JNZ, JE, JG etc.) depending upon the condition. The conditional instructions transfer the control by breaking the sequential flow and they do it by changing the offset value in IP.

Let us discuss the CMP instruction before discussing the conditional instructions.

CMP Instruction:

The CMP instruction compares two operands. It is generally used in conditional execution. This instruction basically subtracts one operand from the other for comparing whether the operands are equal or not. It does not disturb the destination or source operands. It is used along with the conditional jump instruction for decision making.

Syntax

CMP destination, source

Page 9: Tricky math puzzle project report

CMP compares two numeric data fields. The destination operand could be either in register or in memory. The source operand could be a constant (immediate) data, register or memory.

JMP Instructions:

The JMP (Jump) instruction causes an unconditional transfer of control (unconditional jump). Such an instruction transfers the flow of execution by changing the instruction pointer register. There are several different opcodes that perform a jump; depending on whether the processor is in real mode or protected mode, and an override instruction is used, the instructions may take 16-bit, 32-bit, or segment: offset pointers.

The syntax is,

JMP destination

Where destination is usually a label in the same segment as the JMP itself. JMP can be used to get around the range restriction of a conditional jump.

Conditional Jump:

If some specified condition is satisfied in conditional jump, the control flow is transferred to a target instruction. There are numerous conditional jump instructions depending upon the condition and data.

For an example,

CMP AL, BL

JE EQUAL

CMP AL, BH

JE EQUAL

CMP AL, CL

JE EQUAL

NON_EQUAL: ...

Page 10: Tricky math puzzle project report

EQUAL: ...

Use of CMP and JMP instruction in our project :

MOV AH,1 ; MENU CHOICE

INT 21H

MOV CHOOSE,AL

CMP AL,'1'

JE MATH_TEASER

CMP AL,'2'

JE SEQUENCES

CMP AL,'3'

JE ASSUME_SKILL

CMP AL,'4'

JE HELP

CMP AL,'5'

JE EXIT

Loop Instructions:

A loop is a sequence of instructions that is repeated. The number of times to repeat may be known in advance, or it may depend on conditions.

FOR LOOP :

This is a loop structure in which the loop statements are repeated a known number of times (a count-controlled loop). In pseudocodes,

FOR loop_ count times DO

Page 11: Tricky math puzzle project report

Statements

END_FOR

The LOOP instruction can be used to implement a FOR loop. It has

the form,

LOOP destination_ label

WHILE LOOP :

This loop depends on a condition. In pseudocode,

WHILE condition DO

Statements

END WHILE

REPEAT LOOP :

Another conditional loop is the REPEAT LOOP. In pseudocode,

REPEAT

Statements

UNTIL condition

Use of Loop instructions in our project :

MOV CX,3

MOV BL,'0‘

AGAIN:

MOV AH,1

INT 21H

CMP AL,RANDOMNUM1

JE MATCH

Page 12: Tricky math puzzle project report

CMP AL, RANDOMNUM2

JE MATCH

CMP AL, RANDOMNUM3

JE MATCH

LOOP AGAIN

JMP RESULT

MATCH:

INC BL

LOOP AGAIN

RESULT:

Procedures :

Procedures or subroutines are very important in assembly language, as the assembly language programs tend to be large in size. Procedures are identified by a name. Following this name, the body of the procedure is described which performs a well-defined job. End of the procedure is indicated by a return statement.

Following is the syntax to define a procedure −

proc_name:

procedure body

...

ret

The procedure is called from another function by using the CALL instruction. The CALL instruction should have the name of the called procedure as an argument as shown below −

Page 13: Tricky math puzzle project report

CALL proc_name

The called procedure returns the control to the calling procedure by using the RET instruction.

Use of CALL PROC in our project :

NEW_LINE PROC ; NEW LINE PRINT PROCEDURE

MOV AH,2

MOV DL,0AH

INT 21H

MOV DL,0DH

INT 21H

RET

………………………………………….

CALL NEW_LINE

INT 10h :

INT 10h, INT 10H or INT 16 is shorthand for BIOS interrupt call 10hex, the 17th interrupt vector in an x86-based computer system. The BIOS typically sets up a real mode interrupt handler at this vector that provides video services. Such services include setting the video mode, character and string output, and graphics primitives (reading and writing pixels in graphics mode).

To use this call, load AH with the number of the desired sub function, load other required parameters in other registers, and make the call. INT 10h is slow, so many programs bypass this BIOS routine and access the display hardware directly. Setting the video mode, which is done infrequently, can be accomplished by using

Page 14: Tricky math puzzle project report

the BIOS, while drawing graphics on the screen in a game needs to be done quickly, so direct access to video RAM is more appropriate than making a BIOS call for every pixel.

Function:

Scroll up window AH=06h AL = lines to scroll (0 = clear, CH, CL, DH, DL are used),

BH = Background Color and Foreground color. BH = 43h, means that background color is red and foreground color is cyan. Refer the BIOS color attributes

CH = Upper row number, CL = Left column number, DH = Lower row number, DL = Right column number.

Clear screen procedure :

CLRSCR PROC ; CLEAR SCREEN PROCEDURE

MOV AX,0600H ;06 TO SCROLL & 00 FOR FULL CLEAR SCREEN

MOV BH,07H ;ATTRIBUTE 0 FOR BACKGROUND AND 7 FOR FOREGROUND

MOV CX,0000H ;STARTING COORDINATES

MOV DX,184FH ;ENDING COORDINATES

INT 10H ;FOR VIDEO DISPLAY

RET

Function of INT 1Ah :

1Ah Real Time Clock Services

AH Description

00h Read RTC

01h Set RTC

02h Read RTC Time

Page 15: Tricky math puzzle project report

03h Set RTC Time

04h Read RTC Date

05h Set RTC Date

06h Set RTC Alarm

07h Reset RTC Alarm

Random no generate procedure using 00h :

RANDOM PROC ; GENERATE A RANDOM NO USING THE SYSTEM TIME

MOV AH, 00h ; INTERRRUPTS TO GET SYSTEM TIME

INT 1AH ; CX:DX NOW HOLD NUMBER OF CLOCK TICKS SINCE MIDNIGHT

MOV AX, DX

XOR DX, DX

MOV CX, 10

DIV CX ; HERE DX CONTAINS THE REMINDER OF THE DIVISION FROM 0 TO 9

ADD DL,'0' ; TO ASCII FROM '0' TO '9'

MOV BL,DL

RET

Page 16: Tricky math puzzle project report

Project showing / Interface : Tricky math puzzle is a game made by assembly language. We made it with a lucrative interface as we could. Actually, assembly language doesn’t give as opportunities as any other high level languages. After all, our game had very user friendly interface we think. In addition-

For being in assembly language its procedure is so speedy. Though it is a small project, but we tried to make it bug free. And we also

confidently say that is has no bug in our game! It’s an interesting game, no doubt! Is has three segments full of enjoyment. It can be said a brain game. We tried to make it logical so that one can

storm his/ her brain through our game.

Future Planning : Actually, we made it in very short time. Though we full filled all of our expectations, we have some future plan about our game. We may develop it by any other high level language like C++/ Java or with Unity. The features may have in our next version like bellow-

A significant part of gaming is its graphics quality. So, we must have a lucrative graphical interface.

Now artificial interface is a hot cake in gaming world. We will try to add AI features in our next version.

We may add many more segments and events in our game. We may develop more stages and will update everything day by day.

------- Thank you! -------