The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+8 votes

State whether the following statements are True or False with reasons for your answer:

  1. Coroutine is just another name for a subroutine.
  2. A two pass assembler uses its machine opcode table in the first pass of assembly.
asked in Compiler Design by Veteran (59.5k points)
edited by | 414 views

Subroutine will always starts its execution from the beginning(first line) but a co-routine will start from where it left last time.

This is why we say, co-routine has multiple entry points whereas sub-routine has only one.

Yield 'remembers' where the co-routine is so when it is called again it will continue where it left off.

For example:

  coroutine foo {
    yield 1;
    yield 2;
    yield 3;
  print foo();
  print foo();
  print foo();

Prints: 1 2 3

Note: Coroutines may use a return, and behave just like a subroutine

  coroutine foo {
    return 1;
    return 2; //Dead code
    return 3;
  print foo();
  print foo();
  print foo();

Prints: 1 1 1

Source - Stack Overflow

3 Answers

+6 votes
  1. True
    Subroutine are special cases of coroutine. Coroutine are generalized form of subroutine which is nonpreemptive multitasking
  2. True. Basically machine opcode table is the symbol table which requires in 1st pass of two pass assembler
answered by Veteran (95.5k points)
edited by
symbol table is created in first pass and it is used in second pass, (b) should be false
@srestha if coroutines are generalized form then can we say it is just another name of subroutine?It seems from your definition that coroutines can have multiples things and one of them is subroutine.So i think first is false
@ Arjun sir Please check it . I think that (b) is False.

@srestha i think 2nd statement is false


no @Sonam check these lines

scan the code twice. The first time, just count how long the machine code instructions will be, just to find out the addresses of all the labels. Also, create a table that has a list of all the addresses and where they will be in the program. This table is known as the symbol table.

This para also suggests that B is false right?
+1 vote

A. TRUE: A subroutine and a function are essentially the same thing, with one difference: A function returns some sort of value (usually via the stack or CPU register), while a subroutine does not. Whether subroutine or function, it is a block of executable code, having exactly one point of entry. A co-routine is also a block of executable code, and, just like a subroutine, it has one point of entry. However, it also has one or more points of re-entry.



answered by Loyal (7.3k points)
0 votes
a) False

b) True
answered by (145 points)

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

39,441 questions
46,623 answers
57,028 users