473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

switch between functions

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
Jun 27 '08 #1
1 1564
Phoe6 wrote:
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.

--
bartc

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Angelos | last post by:
Ok... I have to make this administation area where I have multiple Contents to add edit delete publish . The problem is that I don't know what is the best way of making the forms. At the moment I...
14
by: Rudi Hansen | last post by:
I dont seem to be able to find the switch statement in Python. I would like to be able to do switch(var) case 1 : print "var = 1" case 2: print "var = 2"
10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
5
by: Bryan Parkoff | last post by:
C++ programmers and I tried to experience by writing 65536 switch cases. It is too large for Windows XP and other operating system to handle. It looks like that JMP Table obtains 256K bytes for...
13
by: webzila | last post by:
Hello, I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the...
2
by: MJ | last post by:
Hi We can use the switch statement, or if else statement instead of switch One more method is there which can replace the switch using the function pointer or the array of function pointer. If...
65
by: He Shiming | last post by:
Hi, I just wrote a function that has over 200 "cases" wrapped in a "switch" statement. I'm wondering if there are performance issues in such implementation. Do I need to optimize it some way? ...
13
by: Fei Liu | last post by:
Hi Group, I've got a problem I couldn't find a good solution. I am working with scientific data files in netCDF format. One of the properties of netCDF data is that the actual type of data is only...
14
by: Bryan Parkoff | last post by:
Do you know that current C++ Compiler limits to 64KB segments in source code? It is good news that Microsoft Visual C++ 2005 has expanded to 4GB segments in source code. 4GB segment is ideal for...
14
ADezii
by: ADezii | last post by:
The tendency of VBA code to evaluate all expressions, whether or not they need to be evaluated from a logical standpoint, makes the use of the IIf(), Switch(), and Choose() Functions inefficient and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.