Water Industry Process Automation & Control Monthly - April 2024
Tricky math puzzle project report
1. SUBMITTED BY-
Team #NoFrazzle
1. Md Sanzidul Islam 151-15-
5223
2. Farhan Tawsif Chowdhury 151-15-
4705
3. Nazmul Ahsan 151-15-
4668
4. Md. Mahbubur Rahman 151-15-
4761
5. Sadia Sultana Sharmin Mousumi 151-
15-5191
SUBMITTED TO-
Ms. Bashira Akter
Anima
Lecturer, Dep. Of CSE,
Daffodil International
UniversityDate of Submission: 18th
December, 2016
PROJECT REPORT ON “TRICKY MATH PUZZLE”
COURSE: MICROPROCESSOR &ASSEMBLY
LANGUAGE
COURSE CODE: CSE 231
2. Abstract & Hints:
The purposeof this projectis to design and build a math puzzlegame that will
give user the experience of solving various tricky math puzzlethrough gaming.
This was achieved through severalsteps. In background, weused programming
language Assembly. Instructions likeconditions, loops, call procedure& various
types of registers and their uses, whatwe learned throughoutour courses.
What is assembly language?
An assembly languageis a programming language that can be used to directly tell
the computer what to do. An assembly language is almostexactly 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 programinto machine code by
replacing the words of the programwith the numbers that they stand for. A
programthat 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 whatto do. The part
of the computer that follows the instructions is the processor. Theassembly
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
performmore complex tasks, onemust tell the computer each of the simple tasks
that are part of the complex task. For example, a computer does not understand
how to printa sentence on its screen. Instead, a programwritten in assembly
must tell it how to do all of the small steps that are involved in printing the
sentence.
Strengthof assembly language:
3. 1. The symbolic programming of Assembly Languageis easier to understand
and saves a lot of time and effortof the programmer.
2. Itis easier to correct errors and modify programinstructions.
3. Assembly Languagehas the sameefficiency of execution as the machine
level language. Because this is one-to-onetranslator between assembly
language programand its corresponding machinelanguage program.
Disadvantages of assembly language:
1. One of the major disadvantages is that assembly language is machine
dependent. A programwritten for one computer might not run in other
computers with different hardwareconfiguration.
Project Description&Demo:
When we startthe game “Tricky Math Puzzle” we will have a POP-Up window
showing this menu.
The firstthree options in this menu is our game segments.
4. If you chooseoption 1. you will get enter into math teaser game segment. In math
teaser segment we put somediscretional tricky mathematical question as like
puzzle.
Something like this,
Here we have multiple choice option. Herethe correctanswer is number two (2).
So you have to input number two (2) fromyour key board. Thus you will get your
correctanswer 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 puzzleafter answering previous one. Becauseof we are in the developing
state of our game so we justput five puzzles into firsttwo segments. Farther
puzzlewill 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 sortof sequentially math puzzle.
5. 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.
The third or final segment of our game is the mostinteresting one. Here we test
our player assumption skill.
You will be asked to guess and input 3 digits. In programlogic unit it automatically
generate 3 randomdigits and compare/match with your imputed digits. If 1 digit
will match, you will get 100$.If 2 digitwill match, you will get 1000$. If 3 digit will
match, you will get 10000$.Herewecan see 1 digit will match and he/she get
100$. If anyonecan play again you press 1.
If the gamer need any help he justhaveto get into choice 4 for help like how to
operate this game, how to operate this menu and how to play this game whatI
justmention above. If you wantto exit you justpress 5.
8. Background of Project:
Conditional execution in assembly language is accomplished by severallooping
and branching instructions. Theseinstructions can change the flow of control in a
program. Conditionalexecution 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 samesteps.
9. 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 offsetvalue in IP.
Let us discuss theCMP instruction beforediscussing the conditional instructions.
CMP Instruction:
The CMP instruction compares two operands. Itis generally used in conditional
execution. This instruction basically subtracts oneoperand fromthe other for
comparing whether the operands are equal or not. Itdoes not disturb the
destination or sourceoperands. Itis used along with the conditional jump
instruction for decision making.
Syntax
CMP destination, source
CMP compares two numeric data fields. The destination operand could be either
in register or in memory. The sourceoperand 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
performa jump; depending on whether the processor is in real mode or
protected mode, and an overrideinstruction is used, the instructions may take 16-
bit, 32-bit, or segment: offsetpointers.
The syntax is,
10. JMP destination
Where destination is usually a label in the samesegment as the JMP itself. JMP
can be used to get around the range restriction of a conditional jump.
Conditional Jump:
If somespecified condition is satisfied in conditional jump, the controlflow 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: ...
EQUAL:...
Use of CMP and JMP instruction in our project:
MOV AH,1 ; MENU CHOICE
INT21H
MOV CHOOSE,AL
CMP AL,'1'
JE MATH_TEASER
11. 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.
FORLOOP:
This is a loop structurein which the loop statements are repeated a known
number of times (a count-controlled loop). In pseudocodes,
FORloop_ counttimes DO
Statements
END_FOR
The LOOP instruction can be used to implement a FOR loop. Ithas
the form,
LOOP destination_ label
WHILELOOP:
This loop depends on a condition. In pseudocode,
WHILEcondition DO
12. 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
INT21H
CMP AL,RANDOMNUM1
JE MATCH
CMP AL, RANDOMNUM2
JE MATCH
CMP AL, RANDOMNUM3
JE MATCH
LOOP AGAIN
JMP RESULT
MATCH:
INC BL
13. 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:
procedurebody
...
ret
The procedureis called fromanother function by using the CALL instruction. The
CALL instruction should havethe name of the called procedureas an argument as
shown below −
CALL proc_name
The called procedurereturns the controlto the calling procedureby using the RET
instruction.
Use of CALL PROC in our project:
NEW_LINEPROC ; NEW LINEPRINTPROCEDURE
MOV AH,2
MOV DL,0AH
14. INT21H
MOV DL,0DH
INT21H
RET
………………………………………….
CALL NEW_LINE
INT10h:
INT10h, INT10H or INT16 is shorthand for BIOS interruptcall 10hex, the 17th
interrupt vector in an x86-based computer system. TheBIOS 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. INT10h is slow, so
many programs bypass this BIOS routineand access the display hardwaredirectly.
Setting the video mode, which is done infrequently, can be accomplished by using
the BIOS, whiledrawing graphics on the screen in a game needs to be done
quickly, so direct access to video RAM is moreappropriate 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
15. 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 FORFULL CLEAR SCREEN
MOV BH,07H ;ATTRIBUTE0 FORBACKGROUND AND 7 FOR FOREGROUND
MOV CX,0000H ;STARTING COORDINATES
MOV DX,184FH ;ENDING COORDINATES
INT10H ;FOR VIDEO DISPLAY
RET
Function of INT1Ah:
1Ah Real Time Clock Services
AH Description
00h Read RTC
01h Set RTC
02h Read RTC Time
03h Set RTC Time
04h Read RTC Date
05h Set RTC Date
06h Set RTC Alarm
07h Reset RTC Alarm
16. Random no generate procedureusing 00h:
RANDOMPROC ; GENERATE A RANDOMNO USING THE SYSTEMTIME
MOV AH, 00h ; INTERRRUPTS TO GET SYSTEM TIME
INT1AH ; CX:DX NOW HOLD NUMBER OF CLOCK TICKS SINCE
MIDNIGHT
MOV AX, DX
XOR DX, DX
MOV CX, 10
DIV CX ; HERE DX CONTAINS THEREMINDEROF THE DIVISIONFROM
0 TO 9
ADD DL,'0' ; TO ASCII FROM'0'TO '9'
MOV BL,DL
RET
Project showing/ Interface:
Tricky math puzzleis a game made by assembly language. We made it with a
lucrative interface as wecould. Actually, assembly language doesn’t give as
opportunities as any other high level languages. After all, our game had very user
friendly interface wethink. In addition-
For being in assembly languageits procedureis so speedy.
17. 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.
Itcan be said a brain game. We tried to make it logical so that one can
stormhis/ her brain through our game.
Future Planning:
Actually, wemade it in very shorttime. Though we full filled all of our
expectations, we have somefuture 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 partof gaming is its graphics quality. So, we musthave a
lucrative graphicalinterface.
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 morestages and will update everything day by day.
------- Thank you! -------