Addressing mode

Download Report

Transcript Addressing mode

Addressing Modes
ธนวัฒน์ แซ่เอียบ
Addressing
• เราสามารถพบ operand ได้ที่ไหน ?
1.
2.
3.
Addressing
opcode operand (address field)
**** ****
00000001 01011100
00000010 00001111
00000011 11110000
location
content
• ฟิ ลด์ที่ใช้ระบุ address ใน instruction มีขนาดเล็ก เนื่องจากพื้นที่ส่วนหนึ่ง
สูญเสี ยให้กลับส่ วนที่เป็ น opcode
Addressing
• ดังนั้นต้องมีเทคนิคที่สามารถอ้างถึง location ในหน่วยความจาทั้งหมด
ได้ ซึ่งมีเทคนิคดังต่อไปนี้
– Immediate
– Direct
– Indirect
– Register
• สถาปัตยกรรมทั้งหมดของคอมพิวเตอร์มี addressing mode มากกว่า 1
โหมดขึ้นไป
• Addressing mode กาหนดได้ที่ opcode ในส่ วนที่เรี ยกว่า mode field
Immediate Addressing
Instruction
Operand
• เป็ นรู ปแบบที่ง่ายที่สุดของ addressing นัน่ คือ operand ปรากฏอยูใ่ น
instruction
OPERAND = A
• ส่ วนมากใช้นิยามค่าคงที่หรื อค่าเริ่ มต้นให้กบั ตัวแปร
• ข้อดี
– ไม่มีการอ้างถึงหน่วยความจาทาให้ไม่ตอ้ งใช้ cycle เพื่อเข้าถึง
หน่วยความจาเพิม่ เติม
Immediate Addressing
• ข้อเสี ย
– ขนาดของ operand ขึ้นอยูก่ บั ขนาดของฟิ ลด์ address
• ตัวอย่าง
Instruction
1011001
• Operand = 10110012 (1318) (8910)
Direct Addressing
Memory
Instruction
A
Operand
• ในฟิ ลด์ address เก็บ effective address ของ operand
EA = A
• Effective address (EA) คือ address จริ งๆของ location ที่มี operand
– การคานวณ EA เพื่อให้ address จริ งใช้กลไกของ paging และเกิดขึ้น
เองภายในเครื่ อง
Direct Addressing
0
Direct Addressing
• การกาหนดโหมด direct ในเครื่ อง PDP8 สามารถกาหนดได้จากการ
กาหนดบิตตาแหน่งที่ 4 เท่ากับ 0 และถ้ากาหนดบิตตาแหน่งที่ 5 เท่ากับ
1 จะหมายถึงใช้ page ปัจจุบนั
• ตัวอย่างคาสัง่ TAD 2078 ปรากฏอยูใ่ น location ที่ 02028
location
000 010 000 010
content
001 010 000 111
TAD(001) direct mode(0) current page(1) offset(0 000 111)
Direct Addressing
location
000 010 000 010
• EA = page ของ location + offset
000 012 + 0 000 1112
000 010 000 1112 (02078)
content
001 010 000 111
Direct Addressing
Direct Addressing
• การกาหนดโหมด direct ในเครื่ อง PDP8 สามารถกาหนดได้จากการ
กาหนดบิตตาแหน่งที่ 4 เท่ากับ 0 และถ้ากาหนดบิตตาแหน่งที่ 5 เท่ากับ
0 จะหมายถึงใช้ page ที่ 0
• ตัวอย่างคาสัง่ TAD 108 ปรากฏอยูใ่ น location ที่ 02048
location
000 010 000 100
content
001 000 001 000
TAD(001) direct mode(0) zero page(0) offset(0 001 000)
Direct Addressing
location
000 010 000 010
• EA = page ที่ 0 + offset
000 002 + 0 001 0002
000 000 001 0002 (00108)
content
001 000 001 000
Direct Addressing
Direct Addressing
• (x) คือ content ของ location ที่ x
• ดังนั้น operand = (EA)
– TAD 2078
• Operand = (02078) = 00228
– TAD 108
• Operand = (00108) = 00178
Indirect addressing
• จากรู ปแบบของ direct เราสามารถอ้างถึง location ได้เฉพาะ page
ปัจจุบนั และ page ที่ 0 ดังนั้นปัญหาคือเราสามารถอ้างถึง location
ตาแหน่งอื่นได้หรื อไม่
Indirect addressing
• วิธีการคือ
– มีกาหนดฟิ ลด์ address ให้ช้ ีไปยัง location หนึ่ง ซึ่ง location นี้
สามารถชี้ไปยัง location อื่นๆได้ท้ งั หน่วยความจา เพราะ location
สามารถมีพ้นื ที่วา่ งพอจัดเก็บ address ได้ท้ งั หมด
Memory
Instruction
A
Operand
Indirect addressing
• การกาหนดโหมด indirect ในเครื่ อง PDP8 สามารถกาหนดได้จากการ
กาหนดบิตตาแหน่งที่ 4 เท่ากับ 1 และถ้ากาหนดบิตตาแหน่งที่ 5 เท่ากับ
1 จะหมายถึงใช้ current page
• ตัวอย่างคาสัง่ TAD 6108 ปรากฏอยูใ่ น location ที่ 02048
location
000 010 000 100
content
001 110 001 000
TAD(001) indirect mode(1) current page(1) offset(0 001 000)
Indirect addressing
location
000 010 000 100
• A = page ของ location + offset
000 012 + 0 001 0002
000 010 001 0002 (02108)
content
001 110 001 000
Indirect addressing
Indirect addressing
• EA = (A)
• EA = (02108)
• EA = 05128 (000 101 001 0102)
Page ที่ 2
Indirect addressing
Indirect addressing
• Operand = (EA)
= (05128)
= 33338
ที่มา
• William Stalling, Computer Organization and Architecture, USA
• Yale N. Patt, Sanjay J. Patel, Introduction to Computing Systems:
From Bits and Gates to C and Beyond, USA