3 Replies - 7694 Views - Last Post: 19 October 2013 - 05:32 PM

#1 LakersFan805   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 15-February 13

How can I convert this simple c++ program into assembly code(LC-3)

Posted 19 October 2013 - 02:11 PM

I need help coveting the following program into LC-3 assembly code, i'm confused on how to implement all those if statements and the while loops. Thanks in advance.

Here's the description of the program: The program will simulate a simple guessing game. The answer to the guessing game will always be 6.
The program will continually ask the user to guess a number between 0 and 9. The user enters the guess from the keyboard.
If the guess is larger than 6; the program should output:
Too big.
If the guess is smaller than 6; the program should output:
Too small.
When the user finally guesses correctly, the program will output:
Correct! You took # guesses.
where # is the number of guesses it took the user.
If after 9 guesses, the user has not correctly guessed the number, the program should output:Game over. Correct answer is 6.
You do not need to check for invalid input (alphabetical characters, punctuation, etc).


#include<iostream>
using namespace std;

int main()
{
    int num, num_of_guesses = 0;

    while(num_of_guesses < 3)
    {
        cout << "Enter a number" << endl;
        cin >> num;

        num_of_guesses++;
        if (num == 6)
        {
            cout << "Correct! You took " << num_of_guesses << " number of guesses" << endl;
            return 0;
        }
        else if(num < 6)
        {
            cout << "To small" << endl;
        }
        else if(num > 6)
        {
            cout << "To big" << endl;
        }
    }
    cout << "Game over. Correct answer is 6." << endl;
}



Is This A Good Question/Topic? 0
  • +

Replies To: How can I convert this simple c++ program into assembly code(LC-3)

#2 andrewsw   User is offline

  • Bouncy!
  • member icon

Reputation: 6563
  • View blog
  • Posts: 26,615
  • Joined: 12-December 12

Re: How can I convert this simple c++ program into assembly code(LC-3)

Posted 19 October 2013 - 02:15 PM

What assembly code do you have so far?

Presumably you know what the equivalents to these if, if-else and while-loops could be in assembly?

This post has been edited by andrewsw: 19 October 2013 - 02:23 PM

Was This Post Helpful? 0
  • +
  • -

#3 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 168
  • View blog
  • Posts: 1,077
  • Joined: 03-April 12

Re: How can I convert this simple c++ program into assembly code(LC-3)

Posted 19 October 2013 - 03:52 PM

This should be about what you need (and it's almost cheating):

http://www.cs.colost...isc/CtoLC3.html
Was This Post Helpful? 1
  • +
  • -

#4 LakersFan805   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 15-February 13

Re: How can I convert this simple c++ program into assembly code(LC-3)

Posted 19 October 2013 - 05:32 PM

View Postturboscrew, on 19 October 2013 - 03:52 PM, said:

This should be about what you need (and it's almost cheating):

http://www.cs.colost...isc/CtoLC3.html

Thanks!That helps a lot.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1