Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with my hangman project in assembly language. I need to read words a

ID: 3572369 • Letter: I

Question

I need help with my hangman project in assembly language. I need to read words a text file to store a list and choose one using an LFSR pseudo-random number generator written in assembly language.

For my project progress report, I need:

High level pseudocode and description to describe HOW you will implement your project code.

List of tasks you need to complete before submitting the project.

List of items you need (Hardware and software) in order to debug, demonstrate and submit your project.

Revised and updated schedule.

PLEASE HELP!!!

Explanation / Answer

Hi,

This is pseudocode for Hangman project:

# generate a word at random and store it in a variable
# display the length of the word to the user
# correct_guesses is less than the length of the word
# prompt the user's to guess a letter
# if the guess is correct increment correct_guesses by '1'
# if the guess is incorrect increment incorrect_guesses by '1'
# and draw the next part of the hangman
# if the incorrect_guesses is greater than 8,then tell the user
# they lost and exit the program
# if correct_guesses is equal to the length of the word, tell the user they won
Hardware Requirements:

Hardware Requirements
Processor : Intel Core2 Duo

Hard Disk : 20 GB or more

RAM : 750 MB or more

Key Board : Standard Windows Keyboard

Mouse : Two or Three Button Mouse

Software requirements:

Operating System : Windows XP or above

IDE : SASM

Technology : Assembly language

Version : 1.0

Tasks:

;====== SECTION 1: constants =========

CR EQU 0Dh
LF EQU 0Ah
ESC EQU 01Bh
SPACE EQU 020h
HEAD EQU 04Fh
LEFTLIMB EQU 02Fh
RIGHTLIMB EQU 05Ch
ASCII_a EQU 061h

;====== SECTION 2: Declare external routines ==============================

; Declare external library routines
EXTERN kbdine, dspout, dspmsg, dosxit
EXTERN libInit, libProcessChar, libDisplayWord, libDisplayUsed
EXTERN libDisplayGallows, libCheckWinner, mp1xit

; Declare local routines
GLOBAL Init, ProcessChar, DisplayWord, DisplayUsed
GLOBAL DisplayGallows, CheckWinner

; Make program variables global
GLOBAL CRLFString, WelcomeString, PromptString, NotValidString, UsedString
GLOBAL WinString, LoseString, AlreadyUsed, AlreadyUsedEnd
GLOBAL GallowsTop, GallowsSide, GallowsBottom
GLOBAL NumIncorrect, TheWord, UsedLetters, WordSpace, Status


;====== SECTION 3: Define stack segment ===================================

SEGMENT stkseg STACK ; *** //STACK SEGMENT// ***
resb 64*8
stacktop:
resb 0 ; work around NASM bug

;====== SECTION 4: Define codesegment ====================================

SEGMENT code ; *** CODE SEGMENT ***

;====== SECTION 5: Declare variables for main procedure ===================
; Some useful strings
CRLFString db CR,LF,'$'
WelcomeString db CR,LF,'Welcome to ECE390 Hangman!',CR,LF,'$'
PromptString db CR,LF,'Enter a letter: ','$'
NotValidString db CR,LF,'That is not a valid letter.',CR,LF,'$'
UsedString db CR,LF,'Used letters: ','$'
WinString db CR,LF,'You Win!!!',CR,LF,'$'
LoseString db CR,LF,'You Lose :(',CR,LF,'$'
AlreadyUsed db CR,LF,'You have already used the letter ',027H,'$'
AlreadyUsedEnd db 027h,'.',CR,LF,'$'

; Strings to draw the hangman
GallowsTop db '------',CR,LF
db '| |',CR,LF,'$'
GallowsSide db '| ','$'
GallowsBottom db '|',CR,LF
db '-',CR,LF,'$'

; NumIncorrect keeps track of how many incorrect guesses the user has made
NumIncorrect db 0

; TheWord is the word the user is trying to guess
TheWord db 'frequency','$'

UsedLetters times 26 db 0
WordSpace times 20 db '$'

Status db 0


;====== SECTION 6: Program initialization =================================

..start:
mov ax, cs ; Initialize Default Segmentregister
mov ds, ax
mov ax, stkseg ; Initialize Stack Segment register
mov ss, ax
mov sp, stacktop ; Initialize Stack Pointer register

;====== SECTION 7: Main procedure =========================================

MAIN:
mov dx, WelcomeString ; Display welcome message
call dspmsg

call Init ; Set up the WordSpace variable

.InputLoop:
call DisplayGallows ; Draw the hangman

call DisplayUsed ; Display used letters
call DisplayWord ; Display the word in progress

mov dx, PromptString
call dspmsg
call kbdine ; Input a character from the keyboard
; into al

mov dx,CRLFString
call dspmsg

cmp al,ESC ; If it's an ESC character,
je .End ; exit immediately

call ProcessChar

call CheckWinner

cmp byte[Status],0
js .Lose ; js = jump sign. If Status is signed,
; e.g. a negative number, the user has lost
je .InputLoop ; If Status is equal to zero, keep playing

.Win ; If Status is neither -1 nor 0,
call DisplayGallows ; we assume it must be 1, so the user has won
call DisplayUsed
call DisplayWord

mov dx,WinString
call dspmsg
jmp .End

.Lose
call DisplayGallows
call DisplayUsed
call DisplayWord

mov dx,LoseString
call dspmsg
.End

call mp1xit

;====== SECTION 8: Your subroutines =======================================

;====== Init ==============================================================
Init:
call libInit ; call to library function Init
; comment out call to library and add your code
ret

;====== ProcessChar =======================================================
ProcessChar:
call libProcessChar
ret

;====== DisplayWord =======================================================
DisplayWord:
call libDisplayWord
ret

;====== DisplayUsed =======================================================
DisplayUsed:
call libDisplayUsed
ret

;====== CheckWinner =======================================================
CheckWinner:
call libCheckWinner
ret

;====== DisplayGallows ====================================================
; PURPOSE: Draws the hangman to the screen
; INPUTS: The NumIncorrect variable
; OUTPUTS: The hangman is drawn correctly, according to how many wrong
; guesses the user has made
;==========================================================================
DisplayGallows:
pusha ; Save all register values to the stack, since
; we change some of their values in this function

mov dx,GallowsTop ; Display the top of the gallows
call dspmsg ; dspmsg takes the address of a string in dx
mov dx,GallowsSide
call dspmsg

cmp byte[NumIncorrect],1 ; If there are one or more incorrect
jb .NoHead ; guesses, we draw the head
; jb = jump below
mov dl,SPACE
call dspout ; dspout takes the ASCII character to output in dl
mov dl,HEAD
call dspout
.NoHead
mov dx,CRLFString ; CRLFString puts us at the beginning
call dspmsg ; of a new line

mov dx,GallowsSide
call dspmsg

cmp byte[NumIncorrect],2 ; If there are two or more incorrect
jb .NoLeftArm ; guesses, we draw the left arm
mov dl,LEFTLIMB
call dspout
mov dl,SPACE
call dspout

.NoLeftArm
cmp byte[NumIncorrect],3 ; Three or more incorrect guesses,
jb .NoRightArm ; draw the right arm
mov dl,RIGHTLIMB
call dspout

.NoRightArm
mov dx,CRLFString ; New line
call dspmsg
mov dx,GallowsSide
call dspmsg

cmp byte[NumIncorrect],4 ; Four or more, draw the left leg
jb .NoLeftLeg
mov dl,LEFTLIMB
call dspout
mov dl,SPACE
call dspout

.NoLeftLeg
cmp byte[NumIncorrect],5 ; Five or more, draw the right leg
jb .Done
mov dl,RIGHTLIMB
call dspout

.Done
mov dx,CRLFString ; Draw the bottom of the gallows
call dspmsg
mov dx,GallowsBottom
call dspmsg

popa ; Restore register values from the stack
ret
Makefile:

MPNAME=mp1

all: $(MPNAME).exe

clean:
rm -f $(MPNAME).exe $(MPNAME).obj $(MPNAME).lst $(MPNAME).map

%.exe: %.obj
tlink /c /v $<, $*.exe, $*.map, libmp1.lib lib291.lib

%.obj: %.asm
nasm -g -f obj -o $*.obj $< -l $*.lst

Thank You .

Init
  • Sets up the WordSpace variable to have as many underscores as TheWord has letters.
  • Inputs:
    • The WordSpace and TheWord variables
  • Outputs:
    • WordSpace is set up properly
  • Calls: None
  • Note: Remember that all strings should end with the '$' character.
ProcessChar
  • Checks the character that the user has guessed to see if it matches any letters in TheWord, and takes the appropriate action.
  • Inputs:
    • AL = Character that the user has just guessed
    • The WordSpace and TheWord variables
    • The UsedLetters array
    • The NumIncorrect variable
  • Outputs:
    • The correct element in UsedLetters is marked as 'used'
    • WordSpace is updated if the character matches
    • NumIncorrect is updated appropriately if the character doesn't match.
  • Calls: DSPMSG, DSPOUT
  • Notes: ProcessChar should first check to see if the character in AL is in the range 'a' through 'z'. If it is not, output an error message and return. If it is within that range, check to see if that letter has already been guessed by checking the appropriate entry in UsedLetters. If it has been used, display the character on the screen, output an error message and return. If the letter hasn't been used, update UsedLetters array, scan through each character in TheWord and check for matching characters. If any characters match, copy them to the corresponding place in WordSpace. If no characters match, update NumIncorrect appropriately.
  • Hint: Either the "register relative" or "base plus index" addressing modes are useful in this function. Review your online lecture notes for more information on memory addressing.
DisplayWord
  • Displays the word-in-progress
  • Inputs:
    • The WordSpace variable
  • Outputs:
    • The word-in-progress is displayed to the screen with a space between each character
  • Calls: DSPOUT, DSPMSG
  • Note: If you're unclear on what to display, run the program or take a look at the screenshot to see exactly how to display the word.
DisplayUsed
  • Displays a list of already-guessed letters
  • Inputs:
    • The UsedLetters array
  • Outputs:
    • Displays used letters
  • Calls: DSPOUT, DSPMSG
  • Notes: Loop through the UsedLetters array looking for 1's. If/when you find a 1, display the corresponding character.
CheckWinner
  • Determines if the user has won or lost.
  • Inputs:
    • The NumIncorrect variable
    • The WordSpace variable
  • Outputs:
    • Sets the Status variable to 1 if the user has won, -1 if the user has lost, or 0 if the user hasn't won or lost (i.e. the user should keep playing).
  • Calls: None
  • Notes: First, check NumIncorrect. Then, scan WordSpace looking for underscore characters.
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote