switch between functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phoe6

    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
  • Bartc

    #2
    Re: switch between functions

    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



    Comment

    Working...