Convert simple c++ program to assembly (68000) [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have an existing program written in c++ that counts the number of words. How would I go about converting this to assembly to run on something like the 68000 processor? Where should I start?
int _tmain(int argc, _TCHAR* argv[])
{
int i=0;
int words=0;
bool last_space=true;
while( test_string[i]!=0)
{
if(!last_space && test_string[i]==' ')//end of word - space preceded by not space must handle multi spaces
words=words+1;
if (test_string[i]==' ')
last_space=true;
else
last_space=false;
i++;
}
return 0;
}

A few hints as this seems to be some typical homework assignment:
You have to loop until a certain condition is fullfilled. So you should look up your assmebly instruction book and find commands where you can read a byte from memory compare it, branch and jmp instructions.
I would start with a simple loop and when you know how to do this, add the next conditions, checking for spaces and so on.

Related

How to print a character code from char*? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm getting a character from a user input using getchar(), but instead of using cout to print the character I want to print the character code, like the one for Return, ESC, etc, so I can use in my code later to check using a if.
To do this you can cast the char to an int,
int charval = (int) mychar;
printf("%d\n", c); will show you the character code.
so I can use in my code later to check using a if.
You don't need to expicitly convert it to an int for that.
if(getchar() == char_code)
doSomething();
Cast the char as an int and print the int value.

Is this a Infinite loop? program finishes prematurely [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I´ve programmed a random writing program. That uses the markov algorithm. So it selects a order of letters, say [th] then go finding what appears most frequent after that using some randomness etc. But if the program selects a letter that has no "siblings". for example say right at the end of the file this symbol is [%] and it do not appear anywhere else in the file. What happens then is that the program just says "Finished running" it don´t even execute the coutcommand that prints out the string newText.
Why is this?
The rest of the code does basically some manipulation of arrays (adding etc..), to much code to post here.
for (int i = 0; i < fullText.length(); i++)
{
newText += getNext(currentWord, curWordPos, order);
}
cout << "Output: " << newText << endl;
Is this an Infinite loop?
No, it's not.

Palindrome without using extra space [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I know various ways to check if an integer is a palindrome or not by using string conversion, stack and number breaking, but here question is
"How can we check wether an integer is a palindrome or not, without using any extra space?"
You can revert a number with some code like:
int revert(int num) {
int reverted = 0;
while (num) {
reverted = reverted*10 + num%10;
num /= 10;
}
return reverted;
}
And now you only check if
num == revert(num)
That is all. Sorry for giving the exact solution instead of just a tip, but I don't think I could have given any tip without the solution itself.

Quitting a While loop in C++ by entering a blank [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a loop in C++ that am stuck with, I want to end the loop by entering a blank, if a character is entered then the loop goes on. using VS2010
Presumably you have a variable storing a single character, and are wanting to stop the loop when someone enters a blank character (I'm going to presume space).
Just use a if statement and a break clause
while (true) {
// Get character here and put it into myChar variable
if ( myChar == ' ' )
{
break;
}
}
You could also put the check in the while condition if you have nothing else there. Another alternative would be a do-while loop.

print a series of numbers optimization part 2 [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
earlyer i posted part 1 and got some interesting responces
print a series of numbers optimization part 1
here is another way you could have the program print a repeating series of numbers to the screen, the goal here is to make the most efficiant/fastest algorithm
int series[] = [2,3,4,5,6,7,8,9,1]
int i = 9;
while(true)
{
print(series[i])
i = series[i] - 1;
}
of course ignore any extra overhead created by actually printing the number because that is not the purpose of the problem
the one boolean conditional statement (while true) is required for the infinite loop is required no matter what solution you do, so you can ignore that too
this solution uses memory for 11 int variables, but otherwise it only does one simple computation and one variable assignment per iteration.
so would this be the most time efficiant way to solve the infiniate number series problem?
I would say it's not the most efficient way.
There's a multiplication involved in addressing the array. It's essentially
destinationAddress = baseAddressOfArray + indexRequested * sizeof(elementOfArray)
I think the most efficient way would be to cache the string of one iteration and simply spit out that string over and over again. I'm not up on my exact C++ syntax, it'd be something like
string s = "123456789";
while(true) {
print(s);
}