Microsoft Word - instruction-cycle.docx

Similar documents
untitled

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far address L10: jmp jmp L20: L10 L20

1 CPU

DPJJX1.DOC


学习MSP430单片机推荐参考书

Microsoft Word - NHIS2013_C_130716_送印_.doc

. v dx v d () () l s dl s d (_) d () v s v s () a dv a d (_) ( ) ( ) x- = v- = = v 0 = m/s a = = m/s 2 a- = ( ) x- v- a- Page 2 of 20

数 学 高 分 的 展 望 一 管 理 类 联 考 分 析 第 一 篇 大 纲 解 析 篇 编 写 : 孙 华 明 1 综 合 能 力 考 试 时 间 :014 年 1 月 4 日 上 午 8:30~11:30 分 值 分 配 : 数 学 :75 分 逻 辑 :60 分 作 文 :65 分 ; 总

untitled

CC213

<4D F736F F D20C7B6C8EBCABDCFB5CDB3C9E8BCC6CAA6B0B8C0FDB5BCD1A75FD1F9D5C22E646F63>

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - notes3-Simple-filled12

1 2 / 3 1 A (2-1) (2-2) A4 6 A4 7 A4 8 A4 9 A ( () 4 A4, A4 7 ) 1 (2-1) (2-2) ()

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - CA_02 Chapter5 Part-I_Single _V2.ppt

4 / ( / / 5 / / ( / 6 ( / / / 3 ( 4 ( ( 2

投影片 1

Microsoft PowerPoint - C15_LECTURE_NOTE_06

Ps22Pdf

Microsoft PowerPoint - C15_LECTURE_NOTE_06

(2) Function 0BH: Function 0CH: (pixel, picture element) Function 0DH: Function 0FH: Function 13H:

/ / (FC 3)...

幻灯片 1

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2

民國八十九年台灣地區在校學生性知識、態度與行為研究調查

第 15 章 程 式 編 写 語 言 15.1 程 式 編 写 語 言 的 角 色 程 式 編 寫 語 言 是 程 式 編 寫 員 與 電 腦 溝 通 的 界 面 語 法 是 一 組 規 則 讓 程 式 編 寫 員 將 字 詞 集 合 起 來 電 腦 是 處 理 位 元 和 字 節 的 機 器, 與

Bus Hound 5

1.1 ML_ONOFF = 1 Q 3 Q 8 C 0.3V M 2 L 1 ML_ONOFF = 0 Q 3 Q 8 C 1. + R31 VCC R21 10K ML_ONOFF R15 0:off 1:on 1K Green Light VCC=5V L1 Q VDD=12V C

2/80 2

Ác Åé å Serial ATA ( Sil3132) S A T A (1) SATA (2) BIOS SATA (3)* RAID BIOS RAID (4) SATA (5) SATA (a) S A T A ( S A T A R A I D ) (b) (c) Windows XP

Ps22Pdf

1 住 房 保 障 10BA 住 房 保 障 索 引 号 : / 主 题 名 称 : 住 房 保 障 发 文 单 位 : 中 华 人 民 共 和 国 住 房 和 城 乡 建 发 文 日 期 : , 中 华 人 民 共 和 国 民 政 部, 中

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor


Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

ICD ICD ICD ICD ICD

1. ( )( ) A. B. C. D. 2. ( )( ) A. : B. : C. : D. : 3. ( )( ) A. : B. : C. : D. : 1 D : 2

1 TPIS TPIS 2 2

AL-M200 Series

民 國 105 年 大 專 程 度 義 務 役 預 備 軍 官 預 備 士 官 考 選 簡 章 目 錄 壹 考 選 依 據 1 貳 考 ( 甄 ) 選 對 象 1 參 資 格 規 定 1 肆 員 額 及 專 長 類 別 2 伍 報 名 及 選 填 志 願 日 期 方 式 3 陸 選 填 官 科 (

<4D F736F F D20C1E3B5E3CFC2D4D8C4A3B0E52E646F63>

TX-NR3030_BAS_Cs_ indd

Microsoft PowerPoint - printout [相容模式]

Microsoft PowerPoint - os_4.ppt

untitled

untitled

bingdian001.com

SIK) 者, 需 實 施 1 年 以 上, 經 體 格 檢 查 無 後 遺 症 者 5. 身 體 任 何 部 分 有 刺 青 紋 身 穿 耳 洞 者, 不 得 報 考, 各 項 檢 查 結 果 須 符 合 體 位 區 分 標 準 常 備 役 體 位 二 在 校 軍 訓 成 績 總 平 均 70 分


Ps22Pdf

入學考試網上報名指南

Microsoft Word - template.doc

(Microsoft Word - \246D\252k\267\247\255n_\275\306\277\357_.docx)

C语言的应用.PDF


untitled

li 侉 2. 在 下 列 加 点 字 的 正 确 读 音 旁 打 : (1) 我 看 见 路 边 有 一 条 蛇 A.sh 佴 B.sh 佶 C.sh 侑 D.sh 侉 (2) 外 面 的 泥 土 冻 得 很 硬 A.y 侏 n 倮 B.y 侃 n 倮 C.y 佾 n 倮 D.y 佻 n 倮 (3

Microsoft Word - 最新正文.doc

名称未設定

國 立 政 治 大 學 教 育 學 系 2016 新 生 入 學 手 冊 目 錄 表 11 國 立 政 治 大 學 教 育 學 系 博 士 班 資 格 考 試 抵 免 申 請 表 論 文 題 目 申 報 暨 指 導 教 授 表 12 國 立 政 治 大 學 碩 博 士 班 論

Microsoft Word - 選擇_無解答2_.doc

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

E. (A) (B) (C) (D). () () () (A) (B) (C) (D) (E). () () () (A) (B) (C) (D) (E). (A)(B)(C) (D) (E) (A) (B) (C) (D) (E) (A) (B)(C) (D) (E). (A) (B) (C)


Microsoft PowerPoint - C15_LECTURE_NOTE_11


2007年普通高等学校招生全国统一考试

EK-STM32F

CC213


12232A LED LED LED EL EL CCFL EL CCF

2013年3月国家教师资格统一考试

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

untitled



Serial ATA ( Nvidia nforce430)...2 (1) SATA... 2 (2) B I O S S A T A... 3 (3) RAID BIOS RAID... 6 (4) S A T A... 9 (5) S A T A (6) Microsoft Win

DR2010.doc

C/C++语言 - C/C++数据

IP-Routing-05.pdf

Microsoft Word - MSP430 Launchpad 指导书.docx

Ps22Pdf


Ps22Pdf

untitled

微處理機期末專題

Serial ATA ( nvidia nforce4 Ultra/SLI)...2 (1) SATA... 2 (2) B I O S S A T A... 3 (3) RAID BIOS RAID... 6 (4) S A T A... 9 (5) S A T A (6) Micro

逢 甲 大 學

RS-232C [11-13] 1 1 (PLC) (HMI) Visual Basic (PLC) 402

<4D F736F F D F F315FAAFEA5F333AAF9B645C2E5C0F8AA41B0C8C249BCC6B24DB3E6B443C5E9A5D3B3F8AEE6A6A12E646F63>

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING

声 明 本 人 郑 重 声 明 : 此 处 所 提 交 的 硕 士 学 位 论 文 基 于 等 级 工 鉴 定 的 远 程 考 试 系 统 客 户 端 开 发 与 实 现, 是 本 人 在 中 国 科 学 技 术 大 学 攻 读 硕 士 学 位 期 间, 在 导 师 指 导 下 进 行 的 研 究

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

Windows XP

RAID RAID 0 RAID 1 RAID 5 RAID * ( -1)* ( /2)* No Yes Yes Yes A. B. BIOS SATA C. RAID BIOS RAID ( ) D. SATA RAID/AHCI ( ) SATA M.2 SSD ( )

Transcription:

cmd D:\>debug - AX, BX, CX, DX = registers AX=AH+AL,, DX=DH+DL -r AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0B42 ES=0B42 SS=0B42 CS=0B42 IP=0100 NV UP EI PL NZ NA PO NC -u 0B42:0100 B401 MOV AH,01 0B42:0102 CD21 INT 21 0B42:0104 CD20 INT 20 0B42:0106 CC INT 3 0B42:0107 F6C702 TEST BH,02 0B42:010A 7548 JNZ 0154 Low Level Languages address machine code Assembly Language Instruction Pointer // getche() // mov ah,01 int 21 int 20 2 D:\>DEBUG AX, BX, CX, DX = registers -u -a 0C8A:0100 mov ax,0200 0C8A:0103 mov dx,0041 0C8A:0106 int 21 0C8A:0108 int 20 0C8A:010A AX=AH+AL return(0); -r -h 010A 0100 020A 000A -n test.com -r cx CX 0000 :000A -w Writing 0000A bytes -q quit CX=10 D:\>test.com A 41(hex) 65(dec) DX='A' INT 21, AH=02 putc(dx); 010A+0100 = 020A 010A 0100 = A(10) 3

D:\>debug -a 0B38:0100 mov ah,09 0B38:0102 mov dx,0109 0B38:0105 int 21 0B38:0107 int 20 0B38:0109 db 'How are you?$' 0B38:0116 puts(dx) define byte -g How are you? -a 0B38:0100 MOV CX,09 0B38:0103 MOV DL,41 0B38:0105 MOV AH,02 0B38:0107 INT 21 0B38:0109 INC DL 0B38:010B LOOP 0105 0B38:010D INT 20 0B38:010F 09 DL++ 41(hex)=65(dec) DL='A' -g ABCDEFGHI INT 21, AH=02 putc(dx); 4 -e 100 enter hex or char data -e cs:100 "This is a string." -u translates memory into mnemonics. -d 100 dump memory -g go/execute Status Register? (Help) A (Assemble) C (Compare) D (Dump) E (Enter) F (Fill) G (Go) H (Hex arith) I (Input) L (Load) Set (1) OV = Overflow DN = Direction Down EI = Interrupts Enabled NG = Sign Flag negative(-) ZR = Zero AC = Auxiliary Carry PO = Odd Parity CY = Carry Clear (0) NV = No Overflow UP = Direction Up DI = Interrupts Disabled PL = Sign Flag positive(+) NZ = Not Zero NA = No Auxiliary Carry PE = Even Parity NC = No Carry M (Move) N (Name) P (Ptrace) Q (Quit) R (Register) S (Search) T (Trace) U (Unassemble) W (Write) 5

cmd D:\>debug - 0100 MOV AH,09 0102 MOV DX,0113 ; puts(message) 0105 INT 21 0107 MOV AH,07 ; AL=getch() 0109 INT 21 AL 1B 010B CMP AL,1B ; AL==ESC(1B=27)? 010D JZ 0111 ; jump zero 0111 010F JMP 0107 ; jump 0107 0111 INT 20 ; stop JNZ 0107 0113 DB "press a key, esc to quit $" printf("press a key, esc to quit "); do{ c = getch(); }while(c!=esc); 6 C:\>debug int 10 0100 MOV AH,02-- set cursor position 0103 MOV DH,06-- row(y) 6, 0105 MOV DL,40-- col(x) 40(=64) 0107 MOV BH,00-- page no. 0109 INT 10 0100 MOV AH,09-- print char 0102 MOV AL,41-- letter A(41) 0104 MOV BH,00-- page no. 0106 MOV BL,FC-- attribute color 0108 MOV CX,05-- display 5 times 010B INT 10 010D INT 20 http://www.ablmcc.edu.hk/~scy/home/javascript/text-color.htm // clear // screen mov ax,600 mov cx,0 mov dx,184f mov bh,07 int 10 int 20 7

char s[50]="\nthis is my \n"; -a 100 xxxx:0100 jmp 126 ; Jump to 0126 xxxx:0102 db 0d,0a,"This is my first DEBUG program" xxxx:0123 db 0d,0a,"$" xxxx:0126 mov ah,9 ; puts xxxx:0128 mov dx,102 ; address of data(string) xxxx:012b int 21 ; execute xxxx:012d mov ah,0 xxxx:012f int 21 ; Terminate Program. xxxx:0131 -g=100 _ This is my first DEBUG program! _ 8 int 21 (debug) AH=01 AL=getche() AH=02 DL=char http://www.ctyme.com/intr/int.htm putc (DL) AH=07 AL=getch() AH=09 DX=addr db "abc" puts (DX) define byte http://www.youtube.com/watch?v=ijno5kdk1xc -u 100 0BA5:0100 B401 MOV AH,01 0BA5:0102 CD21 INT 21 0BA5:0104 B402 MOV AH,02 0BA5:0106 88C2 MOV DL,AL 0BA5:0108 CD21 INT 21 0BA5:010A 80FA30 CMP DL,30 0BA5:010D 7402 JZ 0111 0BA5:010F EBEF JMP 0100 0BA5:0111 B44C MOV AH,4C 0BA5:0113 CD21 INT 21 address machine code Assembly Language getche() putc() DL=='0'? JMP=jump JZ= jump zero 9

指令週期 Instruction cycle 機器週期 Machine cycle: CPU 高階語言 :C for (n=0;n<=5;n++) 低階語言 : 匯編語言 寄存器 ACC 0 memory[] 0001 LOAD #5 // ACC=5 0002 STORE 0020 // memory[20]=acc // MAX=5 0003 LOAD #0 // ACC=0 0004 STORE 0030 // memory[30]=acc // N=ACC 0005 SUB 0020 // ACC=ACC-memory[20] 0006 JPZ 0010 // if(acc==0) jump to 0010 0007 LOAD 0030 // ACC=memory[30] // N 0008 ADD #1 // ACC=ACC+1 0009 JMP 0004 0010 STOP 0020 5 // MAX 0030 0 // N LOAD 載入 STORE 儲存 SUB 減 JPZ(jump zero) JUMP 跳往 1

指令週期 Instruction cycle: Registers 寄存器 程序計數器 (PC) IP 貯存下一個將被執行的指令的地址 program counter 指令寄存器 (IR) 貯存取自主存貯器的正要執行的指令 instruction register 指令譯碼器 decoder 用來解釋貯存在指令寄存器 IR 的現行指令的邏輯電路 地址寄存器 () 貯存指令或數據的地址 memory address register 數據寄存器 () 貯存指令或數據 memory data register 累加器 (ACC) AX 貯存運算的數據或結果 accumulator 程序狀態寄存器 貯存運算後 ACC 結果 / 狀態 program status register (PSR/SR) (overflow 滿溢, sign 正負數, zero 零, parity, carry 進位 ) NV UP EI PL NZ NA PO NC (01110000) ACC 0 PSR 01001100 Instruction Pointer PC IR 4 03 LOAD A +1 5 3 03 指令譯碼器 1 2 主存貯器 01 02 03 LOAD A 04 STORE B 05 06 CU 包括 : 指令寄存器 IR 程序計數器 PC/IP 指令譯碼器 ALU 包括 : 累加器 ACC 程序狀態寄存器 PSR http://content.edu.tw/senior/computer/ks_ks/et/cpu/index.htm http://www.c-jump.com/cis77/cpu/instrcycle/lecture.html 解碼器 addr ess instruction/data 10000 LOAD 11111 10001 ADD 11110 10010 STORE 11101 11101 11110 3 11111 2 cpuoperation.swf http://courses.cs.vt.edu/csonline/machinearchitecture/lessons/cpu/ 2

指令 : 操作碼 操作數 Op code 操作碼 Mnemonic 助記碼 Function Example 001 LOAD Load 載入 (ACC=memory[1000]) LOAD 1000 010 STORE Store 儲存至 (memory[0008]=acc) STORE 0008 011 ADD Add 加 (ACC+=5) ADD #5 100 SUB Subtract 減 (ACC =1) SUB #1 101 EQUAL If operand = Acc, skip next instruction EQUAL #20 110 JUMP Jump to 跳至 (PC=6) JUMP 0006 111 HALT Stop execution 停止執行 HALT Instruction-cycle-sum.swf: x = 2, y = 5, z = x + y # Machine code Assembly code Description 0 001 1 000010 LOAD #2 Load 載入 ACC=2 1 010 0 001101 STORE 0013 Store 儲存至 memory[13]=acc (x=acc) 2 001 1 000101 LOAD #5 Load 載入 ACC=5 3 010 0 001110 STORE 0014 Store 儲存至 memory[14]=acc (y=acc) 4 001 0 001101 LOAD 0013 Load 載入 ACC=memory[13]) (ACC=x) 5 011 0 001110 ADD 0014 Add 加 ACC+=memory[14]) (ACC+=y) 6 010 0 001111 STORE 0015 Store 儲存至 memory[15]=acc (z=acc) 7 111 0 000000 HALT Stop execution 停止執行 Instruction-cycle-count.swf # Machine code Assembly code Description 0 001 1 000101 LOAD #5 ACC=5 1 010 0 001111 STORE 0015 memory[0015]=acc (z=5) 2 001 1 000000 LOAD #0 ACC=0 3 101 0 001111 EQUAL 0015 if (ACC==memory[0015]) ; // skip instruction 4 4 110 1 000110 JUMP 0006 PC=6 5 111 0 000000 HALT Stop execution 6 011 1 000001 ADD #1 ACC+=1 7 110 1 000011 JUMP 0003 PC=3 3

http://www.emu8086.com/assembler_tutorial/tutorials.html C code: 程式碼 n = 10; n = n+23; 6502 assembler: 組合語言 (8 bit) 0500 lda #23 Load 載入 value into the accumulator 累加器 (ACC=23) 0502 add $2043 Add 加 data found at memory 2043h (ACC=ACC+n) 0505 sta $2043 Store 儲存於 at memory 2043h (n=acc) 2043 10 (int n=10) PC MEMORY As 6502 machine code in memory: 機器碼 9a 23 8a 43 20 84 43 20.. =lda IR lda #23 (2 cycles) Fetch: PC=0500 // address of next instruction =PC // memory address register =memory[] // memory data register IR= // instruction(lda) 0500 lda #23 0502 add $2043 0505 sta $2043 2043 10 Decode: operand (#23) needed =PC // PC=0501 =memory[] // operand #23 PC MEMORY =23 Execute: ACC= // #23 PSR updated PC MEMORY ACC add $2043 (4 cycles) Fetch: PC=0502 =PC =memory[] IR= // instruction(add) =add IR 0500 lda #23 0502 add $2043 0505 sta $2043 2043 10 4

Decode: next 2 bytes are addresses (T=$2043) =PC PC MEMORY =memory[] // address 43 T[1]= =43 =PC =memory[] // address 20 T[0]= Execute: T=2043 =T // address 2043 =memory[] // data(10) ACC=ACC+ // 23+10 PSR updated sta $2043 (4 cycles) Fetch: PC=0505 =PC =memory[] IR= // instruction(sta) T[1] PC MEMORY MEMORY =20 T[0] =10+23 ACC=33 PC MEMORY =sta Decode: next 2 bytes are addresses (T=$2043) IR =PC =memory[] // address 43 T[1]= PC MEMORY =PC =memory[] // address 20 T[0]= =43/20 T Execute: =T // address 2043 =ACC memory[]= ACC=33 MEMORY 5

1. Which of the following registers is NOT in the Control Unit? 下列哪些寄存器不在 控制部件 (CU) 內? (1) IR (2) PC (3) (4) PSR A. B. C. D. E. (3) only (4) only (1) and (2) only (2) and (3) only (3) and (4) only 2. What is the minimum number of bits required to represent 1024 different operation codes? 最少需要多少位元去代表 1024 不同的操作碼? A. 8 B. 9 C.10 D.11 E. 12 3. In an instruction fetch cycle, instruction is read from P to Q. Which of the following combinations is correct? 在指令提取週期, 指令由 P 搬到 Q A. B. C. D. E. P = Q = main memory PC IR main memory ALU main memory 主記憶體 ALU IR 4. In an instruction fetch cycle, there is address flow from P to Q directly. Which of the following combinations is correct? 指令提取週期, 地址由 P 直接搬到 Q A. B. C. D. E. P = Q = main memory PC PC ALU main memory 主記憶體 5. In an instruction fetch cycle, there is data flow from P to Q directly. Which of the following combinations is correct? 指令提取週期, 數據由 P 直接搬到 Q A. B. C. D. E. P = Q = main memory PC PC ALU main memory 主記憶體 6

1. (a) Name the following registers: 寫出以下寄存器的名稱 PC, IR,,, PSR, AX(ACC) (b) What do they store during the instruction cycle? 每個寄存器貯存些什麼? 2. (a) What are the 3 stages of an instruction cycle? 列出 指令週期 的三個階段 Describe how instructions are being fetched, decoded and executed and how registers are involved in the instruction fetch and execution cycles. 試描述在指令週期中, 指令如何被提取 解碼和執行 ; 同時寫下寄存器所担當的角色 (b) Label the following diagram which depicts the instruction cycle 指令週期 ( 填圖 ) A P B C D E F G M Q R X Y Z 電腦各部件 various parts of computer N A P B Q M C R D X F Y E Z Instruction 指令 Decoder 編繹器 control signals 控制訉號 G N 7

Section A: Section B: suggested solution Instruction cycle 指令週期 : 1 Fetch an instruction from the main memory into IR 由主記憶體取出指令 2 Decode the instruction to control signals; 編譯 ( 指令寄存器內的 ) 現行指令 3 Execute the instruction 執行指令 by sending the control signals to various parts of the computer system By automatically increasing the content in the PC, the instruction cycle is repeated. 自動增加 PC 值 An instruction cycle 指令週期 can also be divided into (a) instruction fetch cycle 提取週期 1 the PC sends the address of the instruction to 程序計數器 PC 把將要執行指令所在地址送到 地址寄存器 2 the sends address signals to the main memory through address bus 將地址訊號 ( 經地址總線 ) 送到主記憶體 3 the instruction is read from address specified to through data bus 讀入指令到 數據寄存器 ( 經數據總線 ) 4 the sends the instruction to the IR 把指令由 數據寄存器送到 IR 指令寄存器 5 PC is increased by one (or updated so that it points to the next instruction to be executed) PC 值自動加一, 指向下一句被執行指令 (b) decode 解碼 6 IR sends the instruction to the instruction decoder IR 傳送指令到指令譯碼器 7 the instruction decoder decodes the instruction to control signals 指令譯碼器解釋 / 編譯指令成為控制訊號 (c) instruction execution cycle 執行週期 8 control signals are sent to various parts of the computer system through control bus 控制訊號 ( 經控制總線 ) 被傳送到電腦各部分 9 執行有關指令 perform arithmetic and/or logical operations 進行算術 邏輯運算 update PSR if necessary 更新 PSR 狀態 load data into ACC or store value to RAM 載入或貯存數據 8