Professional Documents
Culture Documents
Score
Submitted by:
Orduna, Camille
Dumalag, Joshua
Monday, 6:00 pm – 9:00 pm
CPE 0323.1-3 Computer Architecture and Organization
Date Submitted
06-05-2023
Submitted to:
CH
I. Objectives
II. Methods
This program is a snake game made using 8086 assembly language. It contains several
data, code segments and labels to define variables and implement functions that serve as the game
logic.
The program uses interrupts for setting the video mode, key press, and sound. It also uses
input/output operations to interact with the screen and keyboard. It follows very basic game logic
and structure where a player controls a character(snake) where it can navigate space, it can eat
objects while avoiding colliding to itself. The points increase with each successful eat the dot. The
game ends when the snake eats its own body.
Data Segment:
The data segment defines various variables used in the snakeGame , including:
DownButtn label
• The label checks the value of variable selector. When it is equal to 1, then it jumps in to
op1 where the screen is cleared, changing the colors of which it would be the only one
highlighted using the attribute 0Ah on bl (int 10, AH = 09) to present the highlighted
option for the user in bright green colors.
• The labels op1, op2, op3, and op4 uses interrupt 16h to get character input from the user.
The code uses a pseudo AND gate logic where if the selector is a current value (1-4) and
the user pressed enter (scan code 1ch), then it will jump to the function as to which the
screen will the be cleared in order for that function to be used
• The function for op1 when entered is to play a game, thus it jumps to label snakeGame
where the game is found. snakeGame label points back to the data segment where the
variables for the game are used. Upon exiting the code, it reverts the ax to use the .data
segment of the code.
• The function for op2 when enter is pressed is for the user to enter their name which
would be shown when playing the game. It uses variable buff to store the maximum
character the program accepts, the name of the user entered, and the length of the string
entered by the user. Upon pressing enter after finishing the user input, the code will jump
to label downButtn , looping back for players to select options 1 to 4.
• The function for op3 when enter is pressed is to change the color of the snake game when
played. It uses the label changeme to allow character input from the player to select their
desired color (1 = default green, 2 = blue, 3 = cyan, and 4 = red). Upon character input,
variable color_selector is updated for label color_decider to use.
• Finally, op4 when entered, will invoke the ah = 4ch of interrupt 21 of DOS, exiting the
program
playmeLoop:
color_decider label:
• It will be used when snakeGame is initialized. After calling snakeGame label from op1,
the code will jump to color_decider where it compares the value of the variable
color_selector, jumping when equivalent to either color1, color2, color3, and color4 where
the int 10, ah = 09 is used to modify the attributes of the text to be displayed
snakeGame:
Summary:
The code implements a main menu for a basic snake game in assembly language. The menu
handles the additional parts of the game, including changing its colors, customizing player name,
as well as selecting whether to play again or not. The game itself handles keyboard input, updates
the game state, performs collision detection, renders the game screen, and manages the player's
score. The game will terminate when the player presses the esc key, the snake character collides
with the body and selected to press Q
Int 16h
Interrupt 10
AH = 09h VIDEO - WRITE ATTRIBUTES/CHARACTERS AT CURSOR POS
Where AL = character, BH = display page, BL = attributes of char and CX = number of
times to write character
Interrupt 16h
AH = 00h KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY
Where AH = scan code and AL = character
Interrupt 15h
AH = 86h SYSTEM - WAIT
Where CX,DX = number of microseconds to wait (only accurate to 977 us)
Computer Architecture and Organization Lab Page 6 PLM_CpE
Program Tools
1. Visual Code Studio – Visual Studio Code is a free and widely used program that helps
programmers write and edit their code. It has a simple and user-friendly interface,
supports many programming languages, and offers features like highlighting and
suggestions. It also has a built-in terminal for running commands and interacting with
code.
2. DOSBox - DOSBox is a program that lets you play old MS-DOS games and use
applications on modern computers. It creates a virtual environment that mimics the
functionality of the old MS-DOS system, allowing you to run those programs. You can
adjust settings and mount drives to access the necessary files. It's a useful tool for retro
gaming and running older software.
3. MASM/TASM -
MASM and TASM are assemblers used for low-level programming. They convert assembly
language code into machine code. MASM is developed by Microsoft and is commonly used for
programming on x86 architecture. TASM, developed by Borland, is also used for x86
programming. They allow programmers to write efficient code that interacts directly with
hardware. They are often used for system-level programming.
III. Results
The main focus of the program is to provide a simple interactive game where the player is
directed to menu screen that allows simple customization of a classic snake game, including
changing ones name, and changing the colors of the game. The classic game of snake is where
player controls a ‘snake’ to collect stars and increase their score. The gameplay experience is
displayed in the text-based console.
The code keeps track of the player's score and updates it whenever a star is collected. The
score is displayed on the screen during gameplay. The game also displays the player's name on the
screen, which is obtained through the buff variable.
The results that the group found upon running the code achieved the objectives of the
project. The code allows for player to change their name, enabled player to choose the colors of
the game, and most importantly to play the classic game of snake. However, the group found that
jumping back to the menu screen loses the colors of the program 9/10 times. The group suspect
that this is due to memory allocation as the group experimented with largely changing the value
of cx for character attributes to the maximum to compensate for the change of characters but was
In conclusion, the program successfully achieves its main focus of providing a simple
interactive game based on the classic snake game. The player is able to customize their gaming
experience by changing their name and the colors of the game. The code effectively keeps track
of the player's score, updates it when stars are collected, and displays the score during gameplay.
The player's name is also displayed on the screen, obtained through the buff variable.
Overall, the objectives of the project were met, allowing players to enjoy the classic game
of snake with customization options. However, the group encountered a minor issue where
returning to the menu screen sometimes resulted in the loss of color settings. The group suspects
that this is due to memory allocation and attempted to address it by adjusting character attributes,
but the issue persisted. Fortunately, this does not affect the core objectives of the project, as
returning to the menu screen was not part of the intended gameplay flow.