오후 6:03 2008-11-05
stack based cpu
조경민 bro@shinbiro.com
===================================================================


stack machine은 CISC나 RISC와 다르게 0-operand instruction set을 갖고 있다.
따라서 cisc나 risc와 다르게 code density가 높다.
mov r2, 1
mov r3, 2
add r1, r2, r3 할것을 아래처럼 짜게 된다.


1     # 1
2     # 1 2
+     # 3


단점은 operation은 항상 stack top의 값에 의존한다는 것이다.


어셈블리 프로그래밍 시 여러 범용 레지스터를 활용해서 여러 계산 컨텍스트를 진행하기 불편할 수 있다.


mov r1, 2    ; r1을 사용하는 컨텍스트
mov r3, 5    ; r3 계산 컨텍스트
inc r1       ; r1을 사용하는 컨텍스트
inc r3       ; r3 계산 컨텍스트


스택 어셈블리는 r1과 r3 컨텍스트를 분리해서 하기 힘들다.
2     # 2    ; r1 컨텍스트
1     # 2 1  ; r1 컨텍스트
+     # 3    ; r1 컨텍스트
5     # 3 5  ; r3 컨텍스트
1     # 3 5 1; r3 컨텍스트
+     # 3 6  ; r3 컨텍스트


장점은 항상 stack top의 값과 주소를 얻어오기 때문에 prediction이 쉽다.


stack based language FORTH를 그대로 cpu isa 어셈블리로 보면 아래와 같다.


stack 메모리 생성
dup                                     # a -- a a
drop                                    # a --
over                                    # a b -- a b a
swap                                    # a b -- b a
nip                                     # a b -- b


연산
+                                       # a b -- (a+b)
not                                     # a -- ~a
and                                     # a b -- (a&b)
or                                      # a b -- (a|b)
xor                                     # a b -- (a^b)
rshift1                                 # a -- (a>>1)


메모리 로드, 스토어
@                                       # a -- mem[a]
!                                       # a b -- (a written to mem[b])


I/O
in                                      # -- a
out                                     # a b --


Push immediate 값
N                                       # -- N


control flow 명령어
jump
call
return


점프나 콜은 stack top의 값에 의존하기 때문에 predicated하다.


다음은 예이다. 2 dup라는 함수는 스택 메모리에 a b a b를 생성


: 2dup                                  # a b -- a b a b
        over                            # a b a
        over;                           # a b a b


: 2drop                                 # a b --
        drop                            # a
        drop;                           #


: 1-    -1 +;                           # a -- a-1


: neg                                   # a -- -a
        not                             # ~a
                                        # and fall-through into...
: 1+    1 +;                            # a -- a+1


: -                                     # a b -- a-b
        neg                             # a -b
        +;                              # a-b


참고


1. Stack machine wikipedia
http://en.wikipedia.org/wiki/Stack_machine


2. Stack Computer Online book
http://www.ece.cmu.edu/~koopman/stack_computers/index.html


3. home brew stack computer
http://www.excamera.com/articles/20/mp3c.html

'KB > hardware soc' 카테고리의 다른 글

어드레스 버스, 데이터 버스 TTL  (0) 2008.11.05
computer architecture  (0) 2008.11.05
FPGA & ASIC Synthesis, P&R Tool  (0) 2008.11.03
homebuilt computer group  (0) 2008.11.03
프로토타입 보드 종류  (0) 2008.10.31

+ Recent posts