[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

asm hw help, is string a palindrome

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 1

File: 9oiwOdgG.png (18KB, 400x400px) Image search: [Google]
9oiwOdgG.png
18KB, 400x400px
Hey I'm working on some homework, we just have to figure out if strings input from C++ are palindromes. He gave us some code to work with and I have most of it alright i believe but I don't know how I would insert the reverse into a storage space and then compare it to the original string can you guys help me out?
>>
>>59868244
Here is my C++
-----------------------------------------------------


#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;

extern "C" {
int32_t isStringAPalindrome(const char *s);
}

static char *testStrings1[] = { "",
"#",
"Test String 1",
"tEST sTRING 2",
"Jenny, I've got your number: 867-5309",
"Toto, we're not in \"Kansas\" anymore!",
"A man, a plan, a canal - Panama!",
"Never odd or even",
"Nurses run!",
"Lewd did I live & evil I did dwel.",
"Norma is as selfless as I am, Ron."
};
#define NUM_TEST_CASES1 (sizeof (testStrings1) / sizeof (char *))

int main()
{
char substr[] = "abcd";

printf("PA#10 \n\n");

printf("\nProblem 1 output:\n");
for (int i = 0; i < NUM_TEST_CASES1; i++) {
printf("Input string [%s] yields: %s\n", testStrings1[i],
isStringAPalindrome(testStrings1[i]) ? "true" : "false");
}

printf("\n");

system("PAUSE");

return 0;
}
>>
>>59868244
>>59868253
Heres a link to my asm its too many char to fit

https://drive.google.com/open?id=0B1DrBXWRGsK2T19qNlhwZ3IzQUU
>>
Just Google it and do your own homework
>>
>>59868531
I have been but Im still lost
>>
>I don't know how I would insert the reverse into a storage space and then compare it to the original string

You wouldn't because that would be retarded. Compare the characters at the first and last position to see if they're the same and go from there.
>>
You know that C is compiled to assembly right?
>>
>>59868244
run bubble sort on the string characters
>>
>>59868244
https://en.wikipedia.org/wiki/Multiple_integral
>>
>>59868244
this is written for numbers (project euler problem 4), but is easily made for chars

#include <stdio.h>

int a, b;
enum a {MAX = 1000};
int zahl = 0;

int isPalindrome();
int reverseNumber();


int main() {
for(a = 100; a < MAX; ++a) {
for(b = 100; b < MAX; ++b) {
long prod = a * b;

if(isPalindrome(prod) && prod > zahl)
zahl = prod;
}
}

printf("largest palindrome: %d\n", zahl);
}

int isPalindrome(int z) {
if(z == reverseNumber(z)) {
return 1;
}
return 0;
}

int reverseNumber(int n) {
int num = n;
int rev = 0;
int dig;

while(num > 0) {
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}

return rev;
}
>>
>>59868705
I do, but i didn't learn C or C++ my professor didn't give a shit and just passed us, only reason im taking asm is because its required for me to get a comp sci degree. I never ever want to program. I only wanna do simple IT.
>>
>>59868880
thank you
>>
>>59868244
OP u up? I'll do it but not wasting my time if u ain't up. Last time I did some anons asm HW he wasn't up and I wasted my time
>>
fuck it here you go

section .data
string db "abcba",0

section .text
palindrome:
lea edi, [string]
xor eax, eax
repne scasb
sub edi, 1
lea esi, [string]
.l:
cmp esi, edi
jnb .yes
cmpsb
jne .no
sub edi, 2
jmp .l
.yes:
mov eax, 1
ret
.no:
xor eax, eax
ret


replace [string] with address of string

int palindrome(char *s);
>>
Damn he ain't up. What a waste of some good legacy instructions
>>
I'll bump it for you, spoonfed-kun
>>
ASM for what? x86?
Thread posts: 17
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.