|
Programming and Assembly Language Please read this Topic's rules!! |
![]() |
| LinkBack | Thread Tools | Rate Thread |
| |||
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.
__________________ |
| |||
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?
__________________ |
| |||
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 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 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.
__________________ |
| |||
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?? ..
__________________ |
| |||
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.
__________________ |
| |||
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?
__________________ |
| ||||
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. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Rate This Thread | |
| |
![]() | ||||
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 |