APL Eights Game

39 Views Asked by At

I'm trying to write this code and I'm only partially done. Not sure how to finish it. Tried many times only to get errors.

    program CrazyGame;
#include( "stdlib.hhf" );

static
    number1: int32;
    number2: int32;
    number3: int32;
    setCounter: int32 := 0;
    gameWon: boolean := false;
    eightDetected: boolean := false;

begin CrazyGame;
    
gameLoop:

    // Reset for each game set
    mov( false, gameWon );
    mov( false, eightDetected );
    mov( 0, setCounter );

    // Get the first number from the user
    stdout.put( "Gimme a number: " );
    stdin.get( number1 );
    mov( number1, eax );        // Move number1 into eax for arithmetic operations
    mov( 10, ebx );            // Move 10 into ebx for division
    xor( edx, edx );           // Clear edx before division since div uses edx:eax
    div( ebx );                // Divide eax by ebx, the remainder will be in edx
    cmp( edx, 8 );             // Compare the remainder (last digit of number1) with 8
    je FoundEight1;            // If it's 8, jump to FoundEight1 label

    // If not, proceed to get the second number
    jmp GetNumber2;

FoundEight1:
    mov( true, eightDetected ); // Set eightDetected to true
    // Here we should proceed to the end of the game loop to check if the game is won or not
    jmp EndOfGameCheck;

    // The code for GetNumber2, FoundEight2, GetNumber3, and FoundEight3 should follow a similar pattern

    // ... continue with the next steps ...

EndOfGameCheck:
    // Here, we will write the logic to determine if the game has been won or lost

    // ... continue with the end game logic ...
GetNumber2:
    stdout.put( "Gimme a number: " );
    stdin.get( number2 );
    mov( number2, eax );        // Move number2 into eax for arithmetic operations
    xor( edx, edx );           // Clear edx before division
    div( ebx );
    cmp( edx, 8 );              // Compare the remainder (last digit of number2) with 8
    je FoundEight2;             // If it's 8, jump to FoundEight2 label

    // If not, proceed to get the third number
    jmp GetNumber3;

FoundEight2:
    mov( true, eightDetected ); // Set eightDetected to true
    jmp EndOfGameCheck;         // Proceed to the end of the game loop to check if the game is won

GetNumber3:
    stdout.put( "Gimme a number: " );
    stdin.get( number3 );
    mov( number3, eax );        // Move number3 into eax for arithmetic operations
    xor( edx, edx );            // Clear edx before division
    div( ebx );                 // Divide eax by ebx, the remainder will be in edx
    cmp( edx, 8 );              // Compare the remainder (last digit of number3) with 8
    je FoundEight3;             // If it's 8, jump to FoundEight3 label

FoundEight3:
    mov( true, eightDetected ); // Set eightDetected to true
    jmp EndOfGameCheck;         // Proceed to the end of the game loop to check if the game is won
End CrazyGame;

this is the program and what the output should be. only hla basic instructions. use jmp and cmp for loops

Write a program that reads a set of three different numbers. Then by subtracting off tens, determine if any of the values ends in an eight. Continue looping as long as one of the numbers in the set ends in eight. Three sets with a value ending in eight wins the game!

Output

Gimme a number: 20 Gimme a number: 12 Gimme a number: 44 Sorry Charlie! You lose the game!

Gimme a number: 58 Gimme a number: 23 Gimme a number: 70 One of them ends in eight! Gimme a number: 1 Gimme a number: 12 Gimma a number: 28 One of them ends in eight! Gimme a number: 7 Gimme a number: 8 Gimme a number: 22 One of them ends in eight! You Win The Game!

Gimme a number: 51 Gimme a number: 51 Gimme a number: 51 Sorry Charlie! You lose The Game!

0

There are 0 best solutions below