gerard4143 371 Nearly a Posting Maven

I need help writing a program that randomly picks a point in a 2D space. Then the user will be allowed to make repeated guesses which point was picked with feedback saying if the user is hot or colder on each guess. Thank you!

Could we see what you have so far?

gerard4143 371 Nearly a Posting Maven

it gives the warning when I try to initialize newBoard,
newBoard = loadTable();

Your function - Board loadTable() returns a Board not a pointer to Board

gerard4143 371 Nearly a Posting Maven

Could you please use code tags...and this warning "I am getting a warning, assignment makes pointer from integer without a cast." What line is it on?

gerard4143 371 Nearly a Posting Maven

thank you gerrard

still playing for Liverpool ha?

:)

This reference is lost on me..."still playing for Liverpool ha?"

gerard4143 371 Nearly a Posting Maven

If your looking for the source code for Linux system calls then download the kernel source code for your Linux distro and you'll find it there...The first file you want to investigate is - Entry.S - this file has all the code for the interrupt/syscall call that handles the dispatch....

Also this link may shed some light

http://asm.sourceforge.net/syscall.html#p3

Gaiety commented: its so nice of you +1
gerard4143 371 Nearly a Posting Maven

is there a way to compile this in windows?

The short and probably the only answers is no, you'll have to port it...If your using a Windows compiler why don't you check out the internet its packed with example code or try Googling this "the c programming language pdf"

Its a great intro to C and all the Unix/Linux parts are crammed into the last chapter so you don't have to worry about porting code..

gerard4143 371 Nearly a Posting Maven

No the library I was referring to was unistd.h which means unix std library....

gerard4143 371 Nearly a Posting Maven

So you want us to Google for you

gerard4143 371 Nearly a Posting Maven

Could we see what you have so far?

gerard4143 371 Nearly a Posting Maven

I noticed by your imagine that your including Linux header files...So you have this installed on Linux machine?

I also noticed that your file is located in C:\ which is Windows...

gerard4143 371 Nearly a Posting Maven

That would probably depend on how its initiated...

You really should consult the Intel/AMD manuals..they have very good explanations of each opcode....

gerard4143 371 Nearly a Posting Maven

Hello,
I was just wondering if the hlt instruction would produce a blinking cursor at the command line until enter is pressed or if its use is not noticeable to the user. Google wasn't too helpful for the specifics of the instruction. Thanks!

That would probably depend on how its initiated...

gerard4143 371 Nearly a Posting Maven

I'm old school GVim/Vim

gerard4143 371 Nearly a Posting Maven

I am a beginner in c and would like someone tp help me . My question is why I have to write void before main to execute the c program.

#include<stdio.h>

void main()

clrscr();

{
printf("Hello")

}

This is a very simple program. But I am unable to execute it if I don't write void before main().

That must be an old text...It should be

int main()
{
printf("Hello");
return 0;
}
gerard4143 371 Nearly a Posting Maven

Not sure what your question is....

gerard4143 371 Nearly a Posting Maven

I have a question:

#include <stdio.h>

char * chstrswithf(char * a)
{
while(*a!='\0')
{
if(*a=='s')
*a='f';
a++;
}
return a;
}


int main(void)
{
	char string[]="this is a string";
	chstrswithf(string);
	printf("%s \n",string);
	return 0;
}

the code above is ok for running.
but when I replace the char string[]="this is a string"; with char* string="this is a string";, the error occurs. What's the reason?

char *str is read only

gerard4143 371 Nearly a Posting Maven

I have no idea why your launching above your tank but you really should be using pygame to handle the graphics...

If you can't find any answers then build a projectile log that will log every position the shell has. With this you have a very good diagnostic tool plus you'll be able to tweak your physics...

gerard4143 371 Nearly a Posting Maven

HEY I JUST NEED TO PUT THE FOLLOWING:

IF((N == 2) && (T CAN'T BE DIVIDED BY 4))

how can I put: CAN'T BE DIVIDED BY 4?

I know divided by 4 is : (t / 4).

but can not be divided by 4?

Use the modulus operator %

gerard4143 371 Nearly a Posting Maven

Try cin.getline

gerard4143 371 Nearly a Posting Maven

what do you mean flat memory model???

Well this will probably explain it better than I can

http://en.wikipedia.org/wiki/Flat_memory_model

I run a Linux box so except for emulators, I run a flat memory model

gerard4143 371 Nearly a Posting Maven

If you think it is exceeding the memory allowed then I would compile the program and do an object dump and verify that the jump is exceeding 256...

If it will not compile as is - try commenting out some of the code and see if this error goes away..

Again these are guesses because I'm really only comfortable with a flat memory model

gerard4143 371 Nearly a Posting Maven

Just a guess..You have the model set up as small maybe your exceeding the allowed memory

or your using an eight bit register value for your jump - it can only jump 256 bytes

gerard4143 371 Nearly a Posting Maven

Hi,

Im having a bit of trouble with a problem:

Basically, I have an array with a set size,for example

my_array[40]

I am trying to figure out how to tell if it has less than 20 characters filled,and if it has more than 20 characters filled.

I have tried the string length function and it does not work im wondering if someone can point me in the right direction?

Many thanks.

The strlen function will only work if your character array is a C string...i.e it ends with '\0'

gerard4143 371 Nearly a Posting Maven

Just curious to what you think an unsigned char is but zeros and ones

try compiling this

#include <stdio.h>
#include <stdlib.h>

unsigned char xorBufferTemp[8];
unsigned char bufferHexas1[8];
unsigned char bufferHexas2[8];

int main(int argc, char**argv)
{
	bufferHexas1[0] = 15;
	bufferHexas2[0] = 1;
	xorBufferTemp[0] = bufferHexas1[0] ^ bufferHexas2[0];

	fprintf(stdout, "ans->%u\n", xorBufferTemp[0]);

	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

So saying "cmp bx,1" would check if there was one argument passed? I tried taking the stack all the way up to 28, and got the same results. "It did'nt work" as my message. I do really appreciate your help by the way, is there a way for me to +rep you?

cmp bx, 1 should work...at least its an easy way to see if your checking values on the stack...If you get a true for cmp bx, 1 try changing it to cmp bx, 3 and pass three arguments and see if it still works..If it does then try dereferencing the value ahead of it to see if its your string...Good luck

gerard4143 371 Nearly a Posting Maven

I would try experimenting with this line

mov     bx,[bp+4]

Try values like
mov bx,[bp+8]
mov bx,[bp+12]

Just keep working your way up the stack...

Note the first value on the stack is the number of arguments

Also the command line argument isn't saved on the stack...a pointer to the command line argument is saved on the stack.

gerard4143 371 Nearly a Posting Maven

Did you try Googling "Windows XP 16 bit programs"

http://pcs.suite101.com/article.cfm/windows_xp_compatability_mode

gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

Thanks. I would not know how to test this on windows as I have never used Linux, but I appreciate your time to reply.

Windows will pass the command line arguments via the stack so you'll get then by taking an offset of the stack pointer. In 16 bit programming I believe that is accomplished with ss:sp

where ss is the segment register and sp is the stack pointer together they will give you the base of the stack

gerard4143 371 Nearly a Posting Maven

I know how to do it in 64 bit assembly using Linux's as. You just take the offset of the rsp register.i.e

16(%rsp) will get the first command-line argument

In 32 bit Linux's as

8(%esp) to get the first command-line argument

...For 16 bit...I don't think Linux supports 16 bit exe's so I never had the opportunity to try but if it did it would probably be an offset of the ss:sp registers...Hope this helps

gerard4143 371 Nearly a Posting Maven

If you want to see how other language's handle function overloading, try Googling "name mangling" and you'll see the compiler just renames or mangles the said functions names according to some scheme based on the parameter types...

gerard4143 371 Nearly a Posting Maven

I notice you have the binding to the configure event rem'd out. Why?

Wait are you talking about the desktop width and height?

Try this link

http://www-acc.kek.jp/WWW-ACC-exp/KEKB/Control/Activity/Python/TkIntro/tkmanual/winfo.html

gerard4143 371 Nearly a Posting Maven

Hi,

I am doing network programming in C. I want to send Hexadecimal data between client and server. But stuck how C handles Hexadecimal values? I would like to put and example.

I am having a variable ACK_CODE 0*81. Now want to send it. Since the send call can only receive String data then how we can send the above code in send()? Also how to retrieve that back into Hexadecimal from String in recv() call?

Can anyone help me in this regard?

Thanks

Shahab

The send function accepts a const void *buf in Linux so I expect it accepts something similar in Windows. Just cast the data to const void* and pass along the size

gerard4143 371 Nearly a Posting Maven

Not sure what NASM16 is? Is this 16 bit programming?

gerard4143 371 Nearly a Posting Maven

Quickly

what is .rodata
what is .LC0

rodata is read only data and .LCO: is a label

As for the other questions try this link

http://programminggroundup.blogspot.com/2007/01/programming-from-ground-up.html

gerard4143 371 Nearly a Posting Maven

C does not have pass by reference. It can only be faked passing pointers by value and using indirection them to get the original object.

Just curious, what do you think C++ does when it passes by reference. You said pass by reference doesn't copy the value or the address of the data. So how does the function locate the values or data?

I think you'll find its just a special case pointer that's handled by the compiler. I could be wrong...C++ isn't really my thing.

gerard4143 371 Nearly a Posting Maven

Plus scanf("%c", operation2);

should be

scanf("%c", &operation2);

gerard4143 371 Nearly a Posting Maven

I know my problem is within the SWITCH CASE!!

You might get a faster reply if you told us what's wrong..

gerard4143 371 Nearly a Posting Maven

Is pass by value and call by reference the same? I mean i know theres no call by reference in C but there is similarity int he output of the two isn't it?

why do we use call by value and pass by value? what are its uses?

Do you mean a C++ reference? Because a C++ reference is just a special case pointer..

Your second question...we use pass by value to protect the integrity of the original value

gerard4143 371 Nearly a Posting Maven

if you want the values on the stack then try something like this

Note this works on a 64 bit machine

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char**argv)
{
  long x = 1234;//stack
  long y = 5678;//stack
  void *vptr = &y;//address of the bottom of the stack

  fprintf(stdout, "value->%p, %d\n", vptr, *(long*)vptr);
  vptr += sizeof(void*);
  fprintf(stdout, "value->%p, %d\n", vptr, *(long*)vptr);
  vptr += sizeof(void*);

  fprintf(stdout, "ans->%d %p, %d %p\n", x, &x, y, &y);

  exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Yes, it's an empty file before. In other words, my goal is that the program runs with -O2 optimizations even if the user forgets to compile with this parameter, that is, I need to "mask" this assembly file as it was a C file.

( I know that it would be easier to just give the .s file to the user, but I am constrained to hand a .cpp file)

The only problem I see is the C++ compiler, it will try to optimize the second file when it compiles it. So I can't see how you can predict the final outcome of this file if you don't control its compiling...

gerard4143 371 Nearly a Posting Maven

By elements on the stack, do you mean arguments passed to the program at start up or do you mean displaying everything that's on the stack for the user program?

gerard4143 371 Nearly a Posting Maven

I'm asking because I think I see what your trying to do..I think. You mean compiling a program foo.cpp into assembler code with the optimizing set to -O2 and then copying the assembler code into another file and compiling normally so that the second file will have the -O2 optimizing...

I still have many questions, like what's in the second file? Is it a blank file before you copy over foo.s? If it isn't how do you manage the two entrance points, i.e. you have two functions that are defined as main now....

gerard4143 371 Nearly a Posting Maven

Are you talking about stripping the functionality(assem code) out of a cpp file and inserting it into another cpp file? I guess what I'm asking is...what are you trying to do?

gerard4143 371 Nearly a Posting Maven

Are you using Linux?
If you are, you'd be better off trying object dump of the code like:

objdump -D source.cpp>testfile

Then open testfile in a text editor and inspect it there...Gerard4143

gerard4143 371 Nearly a Posting Maven

Lol, thank you! :)

I feel silly now :P

Don't, assembly can be a hard step to make...Just remember your dealing with either addresses or numbers...Gerard4143

gerard4143 371 Nearly a Posting Maven

Here's a simplified version of what your trying to do...Its using 64 bit Intel/AMD

#include <stdio.h>
#include <stdlib.h>

void findit()
{
	char cpustuff[12];
	void *vptr = (void*)&cpustuff[0];

	__asm__ __volatile__
	(
	 	"xorl	%%eax, %%eax\n\t"
		"cpuid\n\t"
		"movq	%0, %%rsi\n\t"
		"movl	%%ebx, (%%rsi)\n\t"
		"movl	%%edx, 4(%%rsi)\n\t"
		"movl	%%ecx, 8(%%rsi)\n\t"
		:"=m"(vptr) 
	);
	fprintf(stdout, "%s\n", cpustuff);
}

int main(int argc, char**argv)
{
	findit();
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Hi :)

I'm trying to get the vendor ID using the CPUID opcode. Again, this is inline ASM with C; but it's the ASM that I need help with. The C is fine AFAIK.

I'm not sure if it's the way I'm trying to do this, or if my CPU simply doesn't support CPUID...

char* getCPUID(void) {
    int vendor[3];
    char vstring[12 + 1];

    /* Get vendor string: */
    asm("mov %0, %%eax\n\t"
        "cpuid\n\t"
        "cmp $3, %%eax\n\t" /* If eax < 3, CPU doesn't support CPUID... */
        "jl dont_bother\n\t" /* So we can't CPUID :( */
        "mov %%ebx, %0\n\t"
        "mov %%ecx, %1\n\t"
        "mov %%edx, %2\n\t"
        "dont_bother:\n\t"
        "mov $-1, %0"
        :"=r"(vendor[0]), "=r"(vendor[1]), "=r"(vendor[2])
       );
       
   if (vendor[0] == -1) {
       return "Error: CPU doesn't support CPUID!";
   }

   /* Store in vstring; 12 char string results */
   memcpy(&(vstring[0]), &(vendor[0]), sizeof(int));
   memcpy(&(vstring[4]), &(vendor[1]), sizeof(int));
   memcpy(&(vstring[8]), &(vendor[2]), sizeof(int));

   /* Make sure string is NULL-terminated */
   vstring[12] = '\0';
   
   return getManufacturer(vstring); /* Function simply compares vstring to some
                                       known vendor strings. */
}

... but my error message is printed. Is it my ASM, or the CPU?
I'm hoping it's the ASM...

In your inline the "jl dont_bother" may not be supported. I always use something like

"jmp 0f\n\t"
.
.
.
"0:\n\t"

Also, your lines

"mov %%ebx, %0\n\t"
  "mov %%ecx, %1\n\t"
  "mov %%edx, %2\n\t"

each of these lines are moving 4 bytes into the character array but you only increment it by one byte as seen below

:"=r"(vendor[0]), "=r"(vendor[1]), "=r"(vendor[2])

shouldn't this be

:"=r"(vendor[0]), "=r"(vendor[4]), "=r"(vendor[8])

Actually I …

gerard4143 371 Nearly a Posting Maven

Did it mention which line?

gerard4143 371 Nearly a Posting Maven

Well you have

void *count_lines(void *arg)

I would use the void *arg to pass the file handle

like

count_lines(&fh)