-
[문제해설] 현재 CPU와 스택의 상태가 다음과 같다면 CPU가 스택에서 1바이트 데이터를 독출(POP)한 후 SP의 내용은 무엇인가?전자계산기조직응용기사/실기 필답형 기출문제 해설 2022. 3. 20. 01:19반응형
전자계산기조직응용기사 실기 필답형 기출문제 (컴퓨터구조-CPU) - 2001년1회, 2001년3회, 2003년1회
현재 CPU와 스택의 상태가 다음과 같다면 CPU가 스택에서 1바이트 데이터를 독출(POP)한 후 SP의 내용은 무엇인가?
- 문제 해설 -
레지스터 스택(stack)은 대부분의 컴퓨터 CPU가 가지고 있는 유용한 저장장치입니다.
스택은 접시를 쌓아 놓았을 때 맨 꼭대기에 놓인 접시가 가장 먼저 집어지는 것과 같은 LIFO(Last-In, First-Out; 후입 선출) 방식입니다. 그렇기에 서브루틴 호출 시 복귀 주소를 저장하는 용도로 잘 사용됩니다.
본문제의 난의도는 그리 높지 않지만, 자칫 자료구조를 C언어로 공부하신 공학도가 너무 쉽게 판단하여 마이크로 연산의 관점에서 생각하지 않으면 오답을 쓸 수도 있는 문제입니다.
우선 자료구조에서의 스택 용어는 다음과 같습니다.
위 용어들을 이해하기 쉽게 그림으로 표현하면 다음과 같습니다.
위 그림에서처럼 스택에서 자료를 저장하는 PUSH동작이 발생하면, TOP의 값은 증가하고, 자료를 출력하는 POP동작은 TOP를 감소시키게 됩니다. 실제로 C언어로 구현할 때도 TOP의 값은 동일하게 증감시킵니다.
하지만, 메커니즘(mechanism)의 관점으로 살펴보면 반대의 상황이 발생합니다.
우선 PUSH동작의 마이크로 연산은 다음과 같습니다.
SP ← SP - 1
M[SP] ← DRSP를 1 감소
DR의 값을 SP가 가르키는 곳에 저장위에서 SP는 스택 포인터(Stack Pointer) 레지스터로 스택의 TOP의 위치 주소를 가지고, DR은 데이터 레지스터(Data Register)입니다.
자료구조 시간에 배운 것과는 달리 PUSH 동작을 하면, TOP의 값을 증가시키는 게 아니라 감소시키게 됩니다. 그 이유는 문제에서 주어진 도식 자료에서 찾을 수 있습니다.
위 메모리 그림에서 base는 스택의 Bottom(바닥)을 의미합니다. base의 메모리의 주소는 9999이며, TOP 방향으로 갈수록 1씩 감소하게 됩니다. C언어로 구현할 때는 일반적으로 Bottom이 TOP보다 작은 값으로 설정하기 때문에 PUSH 동작을 할 때마다 TOP을 증가시켜야 되지만, 컴퓨터 구조의 메커니즘은 Bottom(본문제에서는 base)의 주소가 TOP주소보다 큰 값을 가지기에 TOP를 의미하는 SP(스택 포인터) 값을 감소시키는 것입니다.
POP동작의 마이크로 연산은 다음과 같습니다.
DR ← M[SP]
SP ← SP + 1SP가 가르키는 곳의 값을 DR에 저장
SP의 값을 1 증가POP동작도 앞서 말한 같은 이유로 SP값을 감소시키는 것이 아니라, 증가시키게 됩니다.
본문제에서는 이러한 PUSH와 POP 연산의 RTL를 명시해주었기 때문에, 문제만 꼼꼼히 읽는다면 어렵지 않은 문제입니다.
우선 문제에서 주어진 그림에서 스택 포인터의 처음 위치는 9997H입니다. 여기서 1바이트의 데이터를 POP 하는데, 문제에서 주어진 1바이트는 SP의 값과는 아무런 상관이 없는 값이니 무시하시면 되고, 중요한 건 1번의 POP 동작이 일어난 것입니다. POP 동작을 하면 SP의 값이 1 증가하게 되어 답은 9998H가 됩니다.
https://youtube.com/playlist?list=PLboXycXmAIDt4ObBRPVj29BuD2d27oRnO
반응형'전자계산기조직응용기사 > 실기 필답형 기출문제 해설' 카테고리의 다른 글
[문제해설] 다음 2진수 값을 부분적으로 반전하고자 할 때 사용되는 논리게이트와 마스크 비트 값을 쓰시오. (0) 2022.04.19 [문제풀이] 다음 식을 카르노 맵을 이용하여 나타내시오. (8) 2022.04.05 [문제해설]다음 코드의 출력 결과를 쓰시오. (0) 2022.02.27 [문제해설] 라운드로빈 알고리즘을 사용하여 A, B, C, D, E 작업을 실행 시킬 때 대기시간은 다음과 같다. 평균 대기시간은 얼마인가? (0) 2022.02.22 [문제해설] 하드웨어 우선순위 인터럽트 장치는 병렬이나 직렬로 연결하여 우선순위를 결정한다. 다음 그림의 인터럽트 방식은? (1) 2022.02.15