switch between functions

P

Phoe6

X-posted to asm group as well.

Hi,

I need help in writing the following program. This is an assignment
program, so I would not require the solution, but guidance would be
really helpful to me to get started and proceed in the correct
direction.

- I am learning assembly language programming. Confused with so many
options available and so many different ways to do things. I am not
settled as which way I should program.

- I use gcc, nasm and on Linux 32 bit.

The problem is here:

Write a C program for a linux OS running in Pentium that performs the
following. The program has two functions, say A and B. Initially, A
is called
, and it prints that the program is in function A for the first time.
Then B is
called, and it prints the same info. Then you should toggle between
function A and B repeatedly without using function call, each time
printing that you are in the function A or B for the nth time. You may
sleep for appropriate duration after each printing so that the output
is clearly visible.

Hint: Use assembly language statement using asm statement. For more
help, see the following. You should use a common switch_to function
and each function should use a separate stack.

(i) The macro switch_to in the file linux-2.6.17.11/include/asm-386/
system.h

(ii) The function __switch_to in the file linux-2.6.17.11/arch/i386/
kernel/process.c.

---

If I look into the __switch_to function and macro, I see that they
reference the kernel tasks and does things other than just the
switching.

I tried it this way, wrote a simple C program with two functions and
calling each other (using a function call) and tried gcc -S ( to
produce the assembly). It actually did not help me to understand.

Any guidance would be appreciable.

Thank you,
Senthil
 
B

Bartc

Phoe6 said:
X-posted to asm group as well.

Which one?
The problem is here:

Write a C program for a linux OS running in Pentium that performs the
following. The program has two functions, say A and B. Initially, A
is called
, and it prints that the program is in function A for the first time.
Then B is
called, and it prints the same info. Then you should toggle between
function A and B repeatedly without using function call, each time
printing that you are in the function A or B for the nth time. You may
sleep for appropriate duration after each printing so that the output
is clearly visible.

Hint: Use assembly language statement using asm statement. For more
help, see the following. You should use a common switch_to function
and each function should use a separate stack.

(i) The macro switch_to in the file linux-2.6.17.11/include/asm-386/
system.h

(ii) The function __switch_to in the file linux-2.6.17.11/arch/i386/
kernel/process.c.

This is not very well specified.

A calls B, or A and B are called independently? Then you want A to 'call' B,
and vice versa, without using a call/return mechanism? Or just yield to the
other function after each iteration of the print loop?

And you have to use two separate stacks for some reason?

That might be a problem: C hardly admits to the existence of one stack let
alone two.

If you state what is the aim of the assignment, ie. what you hope to learn
from it, that might make clearer what approach needs to be used.

But I don't think C will be of much help here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top