Hello Everyone!

This is my first post as a Daniweb member and I am hoping that the people here are as great as they seem. I am a junior in a CS department and I am learning IA32 Assembly as an elective. I am trying to write some basic C functions in ASM but I am having trouble. I am not very familiar with ASM, in fact, I am a total beginner. To start me off, I wrote the function in C and then compiled them with -S so as to write them in ASM, so I can see what they look like. This is my first foray into ASM and we just started looking at the language over this past week.

Anyhow, after I had compiled with -S, the file looked too complicated for what I was writing so I figured the GCC just wanted to add in some extra unnecessary stuff for what I am trying to do.

The two functions that I am trying to write are

pow(int x, int y) // Power function
upcase(char* s) // Lower case to upper case

I have scrapped whatever I attempted and am trying to learn this from scratch.
If anybody wants to put in the time and can help me, that would be great.

By the way, I read Narue's "Let's Learn Assembly", but I am not sure if this is any different than IA32 Assembly, and it is also a little bit difficult to read for a beginner such as myself.

Any takers?



So I have written code for the power function in ASM. I'm not sure if it is efficient or what not, but it works. I still have yet to figure out the upcase function, but I'm working on that. Anyway, here is the ASM for the pow function..

	pushl	%ebp
	movl	%esp, %ebp
	subl	$16, %esp
	movl	$1, -8(%ebp)
	movl	$1, -4(%ebp)
	jmp	.L2
	movl	-8(%ebp), %eax
	imull	8(%ebp), %eax
	movl	%eax, -8(%ebp)
	addl	$1, -4(%ebp)
	movl	-4(%ebp), %eax
	cmpl	12(%ebp), %eax
	jle	.L3
	movl	-8(%ebp), %eax


The approach is good, but take smaller steps.

So instead of

while ( *p ) {
  char c = *p;
  if ( c >= 'a' && c <= 'z' ) c = c + 'A' - 'a';
  *p++ = c;

Start with looking at the ASM for

while ( *p ) {