← Back to list

Crafting a Classic: Our Journey in Building a Snake Game with NASM & DOSBox

By Arsalan Hassan and Amna Sajjad, FAST University, CFD Campus

Arsalan Hassan · 2023-12-05 13:19 · 21 claps · 2.8 min read
#assembly-language #8086 #programming
Open on Medium ↗
Wiki topics: EDU · Education & Learning 💻 · Programming 🛠️ · Crafts & DIY

Crafting a Classic: Our Journey in Building a Snake Game with NASM & DOSBox

By Arsalan Hassan and Amna Sajjad, FAST University, CFD Campus

Introduction

Welcome to our development diary! We’re Arsalan Hassan and Amna Sajjad, enthusiastic computer science students from FAST University, CFD Campus. In a venture blending nostalgia with coding prowess, we embarked on a journey to recreate the timeless Snake game. This blog post is a walkthrough of our project, developed using NASM (Netwide Assembler) and DOSBox, an emulator for running DOS-based programs.

Why Snake?

Snake is a game that needs little introduction. It’s a classic that many of us played on our earliest mobile devices. The idea was to not just recreate a piece of digital nostalgia but also to dive deep into the world of low-level programming, where understanding every bit and byte matters.

Choosing Our Tools: NASM and DOSBox

Our choice of tools was crucial for this project. We opted for NASM for its simplicity and efficiency in handling assembly language. To run our code, DOSBox was the perfect fit, offering a real-time testing environment reminiscent of the DOS era.

The Coding Odyssey

The Assembly Adventure

Our journey began with NASM, a tool that translates assembly language into machine code. The choice of assembly language was deliberate; it allowed us to manipulate hardware directly, a learning experience that higher-level languages seldom offer.

Setting Up the Game Environment

We started by defining the game’s data section, which included variables for game state (like score and snake length), control keys (W, A, S, D), and strings for display (like “GAME OVER”). The clrscr subroutine cleared the screen, setting the stage for the game.

Bringing the Snake to Life

The print_snake subroutine was pivotal. It drew the snake on the screen, using positions stored in an array. Movement subroutines move_left, move_right, move_up, and move_down were implemented to control the snake based on player input, updating the position array and redrawing the snake.

Collision and Game Over Logic

Detecting collisions was crucial. The check_border subroutine checked if the snake hit the walls, and self_collision detected if the snake ran into itself. The game_over subroutine was triggered upon these events to end the game.

The Final Touch: Scoring and Food

Implementing the scoring system and food mechanics added the final touch. The eat subroutine increased the snake’s length and the player’s score when the snake ate food, randomly placed by the print_food subroutine.

Challenges and Learnings

The biggest challenge was the direct interaction with the system’s hardware and memory. Every byte and address mattered, and debugging required a meticulous approach. However, it was a rewarding experience that deepened our understanding of how software interacts with hardware.

Conclusion

This project was more than just writing a game; it was a journey through the annals of computing history, reminding us of how far technology has come. As budding computer scientists, the experience was invaluable, giving us a deeper appreciation for the intricacies of software development.

Acknowledgments

We extend our gratitude to our professors at FAST University for guiding us, and to the online coding communities for their endless resources and support.

This project, a blend of coding skill and nostalgia, not only taught us about assembly language but also offered a window into the past, reminding us of the roots of modern computing. Stay tuned for more adventures in coding from Arsalan Hassan and Amna Sajjad!👩‍💻👨‍💻


메타데이터
post_id
7cdd9debaefa
slug
crafting-a-classic-our-journey-in-building-a-snake-game-with-nasm-dosbox-7cdd9debaefa
url
https://medium.com/@a.h.bajwa2004/crafting-a-classic-our-journey-in-building-a-snake-game-with-nasm-dosbox-7cdd9debaefa
canonical_url
https://medium.com/@a.h.bajwa2004/crafting-a-classic-our-journey-in-building-a-snake-game-with-nasm-dosbox-7cdd9debaefa
author_url
https://medium.com/@a.h.bajwa2004
status
ok
fetched_at
2026-07-24 19:51:38