SlideShare a Scribd company logo
1 of 15
1.4.2 코루틴
  연습문제
1. 교재를 저술하는 저자가 짧고 간단한 코루틴 예제를 찾기 힘
들어하는 이유는 무엇인지 설명하라.
1.

어떤 코루틴이 다른 코루틴을 한 번만 호출한다면 그냥 서브루
틴일 뿐이다. 따라서 각 코루틴이 다른 코루틴을 적어도 서로 다
른두 장소에서 호출하는 응용문제를 찾아야 한다. 게다가, 일종
의 스위치를 설정하거나 어떤 자료 속성을 활용해서한 코루틴
안의 어떤 고정된 장소로의 진입점으로부터 그런 두 장소중 하
나로 분기하게 만드는 게 더 쉬운 경우도 많다. 그런 경우라면
그냥 서브루틴으로 충분하다. 코루틴은 코루틴들 사이의 참조
횟수가 커질수록 더 유용해진다.
2. 본문의 프로그램은 OUT 코루틴부터 시작한다. 만일 IN부터
시작한다면, 즉 줄 60을 "JMP OUT1"에서 "JMP IN1"로 바꾼다면
어떻게 될까?
2.

IN으로 얻은 첫 글자를 잃게 된다. [본문의 예제에서는, 줄
58~59에서 IN에 필요한 초기화를 수행했기 때문에 OUT부터 수
행을 시작한다. 만일 IN을 먼저 시작하고자 한다면, OUT의 초기
화를 위해 "ENT4 -16"을 수행하고 만일 출력 버퍼가 비어 있다는
초기조건이 없다면 출력 버퍼를 비우는 작업을 먼저 수행해야
한다. 그런 다음에 줄 62에서 먼저 줄 39로 점프하도록 한다.]
3. 참 또는 거짓을 말하라 : OUT 코루틴 안의 세 "CMPA PERIOD"
명령들을 모두 제거할 수 있으며, 그래도 프로그램이 제대로 작
동한다.(세심히 살펴볼 것.)
3.

거의 참이다. 그 명령을 제거한다면 IN의 "CMPA =10="이 프로그
램 전체에서 유일한 비교 명령이 되기 때문이며, 또한 "."에 대
한 코드가 40이기 때문이다. (!) 그러나 만일 마지막 마침표 앞
에 반복 횟수 숫자가 존재한다면 IN의 조건 판정은 그 사실을 놓
치게 된다. [참고: 줄 40,44,48을 제거하고 줄 26과 27 사이에
"CMPA PERIOD"를 삽이해서 프로그램을 더욱 최적화할 수 있다.
그러나 만일 비교 지시자의 상태가 코루틴을 넘나들면서 쓰인다
면, 그 사실을 프로그램 문서화에 코루틴 특성들의 일부로 기록
해 두어야 할 것이다.]
4.독자에게 익숙한 실제 컴퓨터에게 (1) 비견할 수 있는 코루틴
연계를 달성하려면 어떻게 해야 하는지 말하라.
4.
 다음은 역사적으로 중요한 세 가지의 상당히 다른 컴퓨터들의
예이다. (i) IBM 650에서 SOAP 어셈블리 언어를 사용하는 경우
호출 명령열은 "LDD A"와 "LDD B", 연계는 "A STD BX AX"와 "B
STD AX BX"이다(두 연께 명령들을 되도록이면 코어에 둔다.) (ii)
IBM 709에서 공통 어셈블리 언어들을 사용하는 경우 호출 명령
열은 "TSX A,4"와 "TSX B,4"이고 연계 명령들은 다음과 같다.
    A SXA BX,4          B STA AX,4
    AX AXT 1-A1,4       BX AXT 1-B1,4
        TRA 1,4             TRA 1,4
(iii) CDC 1604에서 호출 명령열은 A나 B로의 "복귀 점프" (SLJ 4)
이고 연계는 예를 들면
          A: SLJ B1; ALS 0
          B: SLJ A1; SLJ A
이다. 이들은 연속적인 두 48비트 워드들에 담긴다.
5.코루틴 IN과 OUT 모두, 그 들어옴과 나감 사이에서 레지스터
A의 내용이 변하지 않아야 한다고 하자. 달리 표현하자면, OUT
안에서 언제 "JMP IN" 명령이 수행된다 하더라도 나중에 그 다음
줄로 돌아왔을 때 레지스터 A의 내용이 그 전과 변함없어야 하
는 것이다. IN 안에서 "JMP OUT"이 수행되었을 때에도 마찬가지
이다. 이를 위해서는 어떤 코루틴 연계가 필요한가? (그것을 (4)
의 것과 비교해 볼것.)
5.

OUT과 OUTX사이에 "STA HOLDAIN; LDA HOLDAOUT"
,IN과 INX사이에 "STA HOLDAOUT;LDA HODAIN"
6. 세 코루틴 A,B,C가 각각 다른 둘 중 하나로 점프할 수 있는 경
우에 대한, (1)과 비슷한 형태의 코루틴 연계를 제시하라. (한 코
루틴이 발동될 때마다 그 코루틴은 이전에 마지막으로 자신을
떠났던 곳에서 시작해야 한다.)
6.
A안에서 "JMP AB"로 B를, "JMP AC"로 C를 발동한다. B와 C에서
는 장소 BA,BC,CA,CB를 그와 비슷하게 사용하면 된다. 연계는
   AB STJ AX      BC STJ BX      CA STJ CX
   BX JMP B1      CX JMP C1      AX JMP A1
   CB STJ CX      AC STJ AX      BA STJ BX
        JMP BX         JMP CX       JMP AX
[참고: 코루틴이 n개라 할 때, 이런 스타일의 연계에 필요한 메
모리 칸수는 2(n-1)n개이다. 만일 n이 크다면 연계를 위한 "중앙
집중적"루틴을 사용하는 게 물론 나을 것이다. 3n+2 칸들만 사
용하는 방법을 고안하는 것도 어렵지 않다. 그러나 실제 응용에
서 위에 나온 더 빠른 방법은 2m개의 칸들만 사용한다.
여기서 m은 코루틴 i에서 코루틴 j로 점프한다고 할 때 그런
(i,j) 쌍들의 개수이다. 각자 독립적으로 다른 코루틴으로 점프
하는 코루틴들이 많다면, 제어의 흐름은 일반적으로 외부의 영
향 하에 놓이게 된다.(2.2.5절 참고)]
COUROUTINES IN C
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.ht
ml
* SUBROUINE FOR CHARACTER INPUT
READER EQU 16
INPUT ORIG *+16
NEXTCHAR STJ 9F
   JXNZ 3F
1H J6N 2F
   IN INPUT(READER)
   JBUS *(READER)
   ENN6 16
2H LDX INPUT+16,6
   INC6 1
3H ENTA 0
   SLAX 1
9H JANZ *
   JMP NEXTCHAR+1

* FIRST COROUTINE
2H INCA 30
   JMP OUT
IN1 JMP NEXTCHAR
   DECA 30
   JAN 2B
   CMPA =10=
   JGE 2B
   STA *+1(0:2)
   ENT5 *
   JMP NEXTCHAR
   JMP OUT
   DEC5 1
   J5NN *-2

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

1.4.2 코루틴연습문제

  • 1. 1.4.2 코루틴 연습문제
  • 2. 1. 교재를 저술하는 저자가 짧고 간단한 코루틴 예제를 찾기 힘 들어하는 이유는 무엇인지 설명하라.
  • 3. 1. 어떤 코루틴이 다른 코루틴을 한 번만 호출한다면 그냥 서브루 틴일 뿐이다. 따라서 각 코루틴이 다른 코루틴을 적어도 서로 다 른두 장소에서 호출하는 응용문제를 찾아야 한다. 게다가, 일종 의 스위치를 설정하거나 어떤 자료 속성을 활용해서한 코루틴 안의 어떤 고정된 장소로의 진입점으로부터 그런 두 장소중 하 나로 분기하게 만드는 게 더 쉬운 경우도 많다. 그런 경우라면 그냥 서브루틴으로 충분하다. 코루틴은 코루틴들 사이의 참조 횟수가 커질수록 더 유용해진다.
  • 4. 2. 본문의 프로그램은 OUT 코루틴부터 시작한다. 만일 IN부터 시작한다면, 즉 줄 60을 "JMP OUT1"에서 "JMP IN1"로 바꾼다면 어떻게 될까?
  • 5. 2. IN으로 얻은 첫 글자를 잃게 된다. [본문의 예제에서는, 줄 58~59에서 IN에 필요한 초기화를 수행했기 때문에 OUT부터 수 행을 시작한다. 만일 IN을 먼저 시작하고자 한다면, OUT의 초기 화를 위해 "ENT4 -16"을 수행하고 만일 출력 버퍼가 비어 있다는 초기조건이 없다면 출력 버퍼를 비우는 작업을 먼저 수행해야 한다. 그런 다음에 줄 62에서 먼저 줄 39로 점프하도록 한다.]
  • 6. 3. 참 또는 거짓을 말하라 : OUT 코루틴 안의 세 "CMPA PERIOD" 명령들을 모두 제거할 수 있으며, 그래도 프로그램이 제대로 작 동한다.(세심히 살펴볼 것.)
  • 7. 3. 거의 참이다. 그 명령을 제거한다면 IN의 "CMPA =10="이 프로그 램 전체에서 유일한 비교 명령이 되기 때문이며, 또한 "."에 대 한 코드가 40이기 때문이다. (!) 그러나 만일 마지막 마침표 앞 에 반복 횟수 숫자가 존재한다면 IN의 조건 판정은 그 사실을 놓 치게 된다. [참고: 줄 40,44,48을 제거하고 줄 26과 27 사이에 "CMPA PERIOD"를 삽이해서 프로그램을 더욱 최적화할 수 있다. 그러나 만일 비교 지시자의 상태가 코루틴을 넘나들면서 쓰인다 면, 그 사실을 프로그램 문서화에 코루틴 특성들의 일부로 기록 해 두어야 할 것이다.]
  • 8. 4.독자에게 익숙한 실제 컴퓨터에게 (1) 비견할 수 있는 코루틴 연계를 달성하려면 어떻게 해야 하는지 말하라.
  • 9. 4. 다음은 역사적으로 중요한 세 가지의 상당히 다른 컴퓨터들의 예이다. (i) IBM 650에서 SOAP 어셈블리 언어를 사용하는 경우 호출 명령열은 "LDD A"와 "LDD B", 연계는 "A STD BX AX"와 "B STD AX BX"이다(두 연께 명령들을 되도록이면 코어에 둔다.) (ii) IBM 709에서 공통 어셈블리 언어들을 사용하는 경우 호출 명령 열은 "TSX A,4"와 "TSX B,4"이고 연계 명령들은 다음과 같다. A SXA BX,4 B STA AX,4 AX AXT 1-A1,4 BX AXT 1-B1,4 TRA 1,4 TRA 1,4 (iii) CDC 1604에서 호출 명령열은 A나 B로의 "복귀 점프" (SLJ 4) 이고 연계는 예를 들면 A: SLJ B1; ALS 0 B: SLJ A1; SLJ A 이다. 이들은 연속적인 두 48비트 워드들에 담긴다.
  • 10. 5.코루틴 IN과 OUT 모두, 그 들어옴과 나감 사이에서 레지스터 A의 내용이 변하지 않아야 한다고 하자. 달리 표현하자면, OUT 안에서 언제 "JMP IN" 명령이 수행된다 하더라도 나중에 그 다음 줄로 돌아왔을 때 레지스터 A의 내용이 그 전과 변함없어야 하 는 것이다. IN 안에서 "JMP OUT"이 수행되었을 때에도 마찬가지 이다. 이를 위해서는 어떤 코루틴 연계가 필요한가? (그것을 (4) 의 것과 비교해 볼것.)
  • 11. 5. OUT과 OUTX사이에 "STA HOLDAIN; LDA HOLDAOUT" ,IN과 INX사이에 "STA HOLDAOUT;LDA HODAIN"
  • 12. 6. 세 코루틴 A,B,C가 각각 다른 둘 중 하나로 점프할 수 있는 경 우에 대한, (1)과 비슷한 형태의 코루틴 연계를 제시하라. (한 코 루틴이 발동될 때마다 그 코루틴은 이전에 마지막으로 자신을 떠났던 곳에서 시작해야 한다.)
  • 13. 6. A안에서 "JMP AB"로 B를, "JMP AC"로 C를 발동한다. B와 C에서 는 장소 BA,BC,CA,CB를 그와 비슷하게 사용하면 된다. 연계는 AB STJ AX BC STJ BX CA STJ CX BX JMP B1 CX JMP C1 AX JMP A1 CB STJ CX AC STJ AX BA STJ BX JMP BX JMP CX JMP AX [참고: 코루틴이 n개라 할 때, 이런 스타일의 연계에 필요한 메 모리 칸수는 2(n-1)n개이다. 만일 n이 크다면 연계를 위한 "중앙 집중적"루틴을 사용하는 게 물론 나을 것이다. 3n+2 칸들만 사 용하는 방법을 고안하는 것도 어렵지 않다. 그러나 실제 응용에 서 위에 나온 더 빠른 방법은 2m개의 칸들만 사용한다. 여기서 m은 코루틴 i에서 코루틴 j로 점프한다고 할 때 그런 (i,j) 쌍들의 개수이다. 각자 독립적으로 다른 코루틴으로 점프 하는 코루틴들이 많다면, 제어의 흐름은 일반적으로 외부의 영 향 하에 놓이게 된다.(2.2.5절 참고)]
  • 15. * SUBROUINE FOR CHARACTER INPUT READER EQU 16 INPUT ORIG *+16 NEXTCHAR STJ 9F JXNZ 3F 1H J6N 2F IN INPUT(READER) JBUS *(READER) ENN6 16 2H LDX INPUT+16,6 INC6 1 3H ENTA 0 SLAX 1 9H JANZ * JMP NEXTCHAR+1 * FIRST COROUTINE 2H INCA 30 JMP OUT IN1 JMP NEXTCHAR DECA 30 JAN 2B CMPA =10= JGE 2B STA *+1(0:2) ENT5 * JMP NEXTCHAR JMP OUT DEC5 1 J5NN *-2