Question: ASM using the 80x86 architecture. Do not write in Java, or C++ due to my last teacher mistakenly wrote the answer in C++ or Java
ASM using the 80x86 architecture.
Do not write in Java, or C++ due to my last teacher mistakenly wrote the answer in C++ or Java as this supposed to be an Asm x86 language. I need help to rewrite my coding from assignment 2 using the .WHILE, .IF, .ELSE, ENDW, ENDIF method. The problem for me I have a hard time figuring out to rewrite my coding in the .WHILE, .IF, .ELSE, ENDW, ENDIF method, so I need help to solve the problem. Make sure to
.if does not require those logical operators to work in this lab. You merely need to set up code like this after your while statement:
* some code = prime loop
.while
* some code = set-up for random check
.if eax == some variable
*some code = winner code
.else
*some code = loser code
Remember to use .endw and .endif to close out the loop and conditional branches. I just wanted to help get you started.
Instruction
In assignment 2 you created the following game of chance:
Write a program that asks the user to guess the next roll of a six sided die. Each guess costs $ 1. If they guess correctly, they get $ 10.00. The player will start out with a $10.00 bank. Each time he (or she) guesses incorrectly you will subtract $1.00 from their bank. Each time they guess correct, you add $10.00 to their bank. Print the total winnings or loss at the end of the game. You can simulate the toss of the dice using the RandomRange function (Don't forget to Randomize).
Your program should look something like this:
Welcome to the dice guess game. it costs $1.00 to play. Would you like to continue? (y/n) y Please enter your guess for the next roll. It only costs $1.00 to play If you are correct I will pay you $10.00: 5 Winner! Your bank is now $20 Would you like to continue? (y/n) y Please enter your guess for the next roll. It only costs $1.00 to play If you are correct I will pay you $10.00: 3 Sorry you lose. The dice rolled 1 Your bank is now $19 Would you like to continue? (y/n) y Please enter your guess for the next roll. It only costs $1.00 to play If you are correct I will pay you $10.00: 2 Sorry you lose. The dice rolled 3 Your bank is now $18 Would you like to continue? (y/n) n Thanks for Playing Your bank is now $18 Press any key to close this window . . .
In this assignment you are to rewrite this program using .WHILE, .ENDW, .IF, .ELSE, .ENDIF instructions
My coding from assigment 2 if possible try to rewrite it using .WHILE, .ENDW, .IF, .ELSE, .ENDIF instructions
INCLUDE asmLib.inc .data Bank DWORD 10 rNum DWORD ? welcomeMsg BYTE "Welcome to the dice guess game. it costs $1.00 to play. " , 0dh, 0ah, 0 contMsg BYTE "Would you like to continue? (y/n)", 0dh, 0ah, 0 prompt1 BYTE "Please enter your guess for the next roll. It only costs $1.00 to play", 0dh, 0ah, 0 prompt2 BYTE "If you are correct I will pay you $10.00:", 0dh, 0ah, 0 winnerMsg BYTE "Winner! The dice rolled ", 0 loserMsg BYTE "Sorry you lose. The dice rolled ", 0 bankMsg BYTE "Your bank is now $", 0 quitMsg BYTE "Thanks for Playing " , 0dh, 0ah, 0 .code main PROC mov eax, 0 ; seed with time of day clock call randSeed ; Seed the random number generator mov edx, OFFSET welcomeMsg ; Output the welcome message call writeString mov edx, OFFSET contMsg ; prompt to continue call writeString call readChar ; Read the response cmp al, 'y' ; Check for lower case y je game ; Want to play jump to game cmp al, 'Y' ; Check for uppercase Y je game ; Want to play jump to game call exitProgram ; Don't want to play let's exit game: mov eax, 6 ; Random number between 0 and 5 call randRange ; generate random number inc eax ; add 1 to up range to 1 and 6 mov rNum, eax ; store the random number call writeBank ; write the bank call writePrompt ; prompt for input call readInt ; get guess cmp eax, rNum ; compare the guess to the random number jne losers ; jump if not equal to loser winners: ; not loser let fall through to winnder mov edx, OFFSET winnerMsg ; write winner message call writeString add bank, 10 ; add winnings to bank jmp prompt ; see if user wants to continue losers: mov edx, OFFSET loserMsg ; write the loser message call writeString sub bank, 1 ; subtract bet from bank prompt: mov eax, rNum ; output the random number call writeInt endl ; Write a newline call writeBank ; output the current bank mov edx, OFFSET contMsg ; ask if user wants to continue call writeString call readChar ; read user response cmp al, 'y' je game cmp al, 'Y' je game ; jmp back to game if use want to continue call exitProgram ; otherwise exit the program main ENDP writePrompt PROC pushad ;cls mov edx, OFFSET prompt1 call writeString mov edx, OFFSET prompt2 call writeString popad ret writePrompt ENDP writeBank PROC pushad mov edx, OFFSET bankMsg call writeString mov eax, Bank call writeInt endl popad ret writeBank ENDP exitProgram PROC mov edx, OFFSET quitMsg call writeString exit exitProgram ENDP END main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
