13
mu0 & algorithm SoC Lab

mu0 & algorithm

Embed Size (px)

DESCRIPTION

mu0 & algorithm. SoC Lab. Harvard Architecture. Instruction cycle. Harvard Architecture. D_ADDR. D_DATA. Data Memory. INST_ADDR. INST_DATA. Inst Memory. IR. MUX. PC. +1. +. ALU. MUX. ACC. Harvard Architecture with Index Register. D_ADDR. D_DATA. Data Memory. MUX. INST_ADDR. - PowerPoint PPT Presentation

Citation preview

Page 1: mu0 & algorithm

mu0 & algorithm

SoC Lab

Page 2: mu0 & algorithm

Harvard Architecture

Page 3: mu0 & algorithm

Instruction cycleInstruc-

tion폰노이만 하바드

LDA 2 1

STO 2 1

ADD 2 1

SUB 2 1

JMP 1 1

JGE 2 1

JNE 2 1

STP 1 1

MOVI 2 1

MOVIDX 2 1

LDIDX 2 1

STIDX 2 1

ADDIDX 2 1

SUBIDX 2 1

Page 4: mu0 & algorithm
Page 5: mu0 & algorithm

ALU

Inst Memory

MU

X

IR

PC

ACC

++1

MUX

Data MemoryD_ADDR

INST_ADDR

D_DATA

INST_DATA

Harvard Architecture

Page 6: mu0 & algorithm

ALU

Inst Memory

MU

X

IR

PC

ACC

++1

MUX

Data MemoryD_ADDR

INST_ADDR

D_DATA

INST_DATAMUX

IDX

Harvard Architecture with Index Register

MUX

Page 7: mu0 & algorithm

Harvard Architecture with Index & Link Address Register 1/2

• 추가 명령어– CALL S // call sub-routine– RET // return

• 추가 레지스터– Link address // or stack point

• Reset– Link address 를 적절한 번지로 초기화 ( 메모리의 뒷부분에 할당 )

ex) data mem 이 1000 번지까지 있다면 900 정도로 설정

Page 8: mu0 & algorithm

INST_ADDRMUX

RA

Harvard Architecture with Index & Link Address Register 2/2

+

MUX

- 11

ALU

Inst Memory

IR

PC

ACC

++1

MUX

Data MemoryD_ADDR

INST_ADDR

D_DATA

INST_DATA

IDX

MUX

CALL S // dmem[RA] = PC , IR = imem[S], PC = S+1, RA = RA+1RET // IR = imem[dmem[RA-1]], PC = dmem[RA-1]+1, RA = RA-1

MU

X

D_DATA

Page 9: mu0 & algorithm

최대 공약수유클리드 호제법

int FindGcdUmethod(int iFirstIn,int iSecondIn){ int iMaxNum,iMinNum; if(iFirstIn>iSecondIn) { iMaxNum=iFirstIn; iMinNum=iSecondIn; }else{ iMaxNum=iSecondIn; iMinNum=iFirstIn; }

if(iMinNum==0) return iMaxNum; else return FindGcdUmethod(iMinNum,iMaxNum%iMinNum);

}

iMaxNum241688

iMinNum16880

Input = 24 , 16

Page 10: mu0 & algorithm

Binary search

int binary_search( int *data, int key, int lenth){ int l = 0; // left int r = lenth -1; //right int mid;

while( l <= r) { mid = (l + r); mid = mid >> 1; if( data[mid] == key) return mid; // find key else if(data[mid] < key) l = mid + 1; else if (data[mid] > key) r = mid -1; } return -1; // can't find}

lenth = 10, key = 66l = 0 , r = 9, mid = 4, data[mid] = 33l = 5 , r = 9, mid = 7, data[mid] = 67l = 5 , r = 6, mid = 5, data[mid] = 55l = 6 , r = 6, mid = 6, data[mid] = 66

In-dex

0 1 2 3 4 5 6 7 8 9

Data 5 8 10

20

33

55 66

67 69 80

Page 11: mu0 & algorithm

Run-Length Codingvoid run_lenth(int *data,int *comp,int length){ int i; int code = data[0]; int code_cnt = 1; int dest_cnt = 0; for(i=1;i<length;i++) { if(code == data[i]) code_cnt = code_cnt + 1; else { comp[dest_cnt] = code; dest_cnt = dest_cnt+1; comp[dest_cnt] = code_cnt;

code = data[i]; code_cnt = 1; } } comp[dest_cnt] = code; dest_cnt = dest_cnt+1; comp[dest_cnt] = code_cnt;}

data : 44444333233333332223334444comp : 45 32 21 37 23 33 44

Num of data = 26Num of comp = 14Compression Rate = 26/14 = 1.86

Page 12: mu0 & algorithm

Quick Sort void quickSort(int numbers[], int array_size){ q_sort(numbers, 0, array_size - 1); } void q_sort(int numbers[], int left, int right){ int pivot, l_hold, r_hold; l_hold = left; r_hold = right; pivot = numbers[left]; while (left < right){ while ((numbers[right] >= pivot) && (left < right)) right--; if (left != right){ numbers[left] = numbers[right]; left++; } while ((numbers[left] <= pivot) && (left < right)) left++; if (left != right){ numbers[right] = numbers[left]; right--; } } numbers[left] = pivot; pivot = left; left = l_hold; right = r_hold; if (left < pivot) q_sort(numbers, left, pivot-1); if (right > pivot) q_sort(numbers, pivot+1, right); }

Page 13: mu0 & algorithm

ModelSim TipIn tb_mu0 modulefunction [8*7-1:0] opcode_expr; input [3:0] opcode; opcode_expr = opcode == 0 ? "LDA": opcode == 1 ? "STO": opcode == 2 ? "ADD": opcode == 3 ? "SUB": opcode == 4 ? "JMP": opcode == 5 ? "JGE": opcode == 6 ? "JNE": opcode == 7 ? "STP": opcode == 8 ? "MOVIDX" opcode == 9 ? "LDIDX" opcode ==10 ? "STIDX" opcode ==11 ? "ADDIDX" opcode ==12 ? "SUBIDX“ "NaO"; endfunction

wire [8*7-1:0] opcode_name; assign opcode_name = opcode_expr(dut.ir[15:12]);