AOA Forums AOA Forums AOA Forums Folding For Team 45 AOA Files Home Front Page Become an AOA Subscriber! UserCP Calendar Memberlist FAQ Search Forum Home


Go Back   AOA Forums > Software > Programming and Assembly Language

Programming and Assembly Language Please read this Topic's rules!!


Reply
 
LinkBack Thread Tools Rate Thread
  #1 (permalink)  
Old 29th August, 2007, 06:08 AM
Member
 
Join Date: August 2007
Posts: 5

Hangman in Assembly

My machine problem is to make a game of Hangman implemented in assembly language.

The specification of the program is for the the random words (to be used in the game) to come from an external word database (text file named worddb.txt).

How is that possible? How am I going to access and read the values in the an external file and incorporate it in my game?

I really have no clue. I am a beginner in assembly programming.

And if you know any website on this, it will be a big help.

p.s im using tasm.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 29th August, 2007, 09:24 AM
Chief Systems Administrator
 
Join Date: September 2001
Location: Europe
Posts: 13,075

What platform do you need to write the code on? As you're using TAsm, I'm presuming you're writing it for DOS?

It is possible to access file under DOS - int 21 functions include such things.

What time period do you have to write the code in?
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 29th August, 2007, 11:01 AM
Member
 
Join Date: August 2007
Posts: 5

yes, i am writing it for dos.
i am only given 2 weeks to finish everything.

could you elaborate on the procedure (on how the access words in the textfile to my program)?
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 29th August, 2007, 01:34 PM
Chief Systems Administrator
 
Join Date: September 2001
Location: Europe
Posts: 13,075

You can use the int 21 functions in order to first open the file, and then to read data from the file.

For example
Code:
mov ax, 3d00 ; set ax to Open file for read
mov dx, xxx ; pointer to the filename - XXX
int 21
would result in DOS attempting to open the file. You want to check CF to see that the file exists - if it's not set, then AX will contain the filehandle you need for reading the file.

You can then do something like
Code:
mov bx, ax ; save the filehandle in bx
mov ah, 3f ; set ax for read file
mov cx, xx ; cx sets how many bytes you want to read
mov dx, xxx ; dx points to where you want the data
int 21
You'll want to check CF again. If CF is not set, then AX should equal the number of bytes read. If AX is zero, then you've hit the end of the file.

Once you have the file (or a section of the file), then you can run through it looking for the CR/LF sequence that terminates each line in the file.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 30th August, 2007, 02:04 PM
Member
 
Join Date: August 2007
Posts: 5

i am finally able to access my external file. Although how can i individually access the words. As in per line.. because the words in the textfile seems to be considered as a whole.
For example,
red
yellow
blue

how am i suppose to access each word individually? Do i have to put them in an array?? ..
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 30th August, 2007, 02:16 PM
Member
 
Join Date: August 2007
Posts: 5

hmm.. what im trying to say is how to read word by word or line per line from the file ?

Since i need only one word at a time in the game.
hehe
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 30th August, 2007, 03:46 PM
Chief Systems Administrator
 
Join Date: September 2001
Location: Europe
Posts: 13,075

A text file is just a sequence of bytes. That said, each line ends in a pair of bytes (CRLF) - 0x0D 0x0A. You can use those as a delimiter to tell where the end of a word is.

Once you've loaded a block into memory, you can use those CRLF sequences to indicate the next word. You could push these into an array, or build an index table for the block, so you can then randomly choose one.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 2nd September, 2007, 03:06 PM
Member
 
Join Date: August 2007
Posts: 5

my program is sequentially reading the words in my file. So everytime I run my program, it always starts with the same word. (ofcourse the rest of words are the same too).
Is it there any way where everytime I run my program the sequence of words changes?
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 2nd September, 2007, 06:01 PM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, Unicycle Challenge Champion, YetiSports 9: Final Spit Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 16,178
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

You'll have to implement a random number generator in order to do that. There are a lot of implementations of random numbers in assembly out on the 'net; This one is an implementation of the classic Knuth random number generator, which is fine for most applications. Be aware, though, that the classic Knuth implementation has a distribution in the least significant bit of EXACTLY 50% (or so I've read). This makes it unsuitable for some applications, thought it should work fine for you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why program in Assembly!? Garfield Programming and Assembly Language 61 4th October, 2012 11:55 AM
hangman in c help barneygumble742 Programming and Assembly Language 3 11th November, 2004 02:54 AM
80x86 Assembly Trouble. DigitalKnight Programming and Assembly Language 10 23rd October, 2004 02:33 PM
The Assembly Language Garfield Random Nonsense! 16 7th August, 2002 09:24 PM
Assembly Programmers Garfield Programming and Assembly Language 13 29th June, 2002 02:37 AM


All times are GMT +1. The time now is 03:45 PM.


Copyright ©2001 - 2023, AOA Forums
Don't Click Here Don't Click Here Either

Search Engine Friendly URLs by vBSEO 3.3.0