Bài giảng Kiến trúc máy tính: Tập lệnh - Nguyễn Ngọc Hóa

45 23 0
Bài giảng Kiến trúc máy tính: Tập lệnh - Nguyễn Ngọc Hóa

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Bài giảng Kiến trúc máy tính: Tập lệnh cung cấp cho người học các kiến thức: Khái niệm, biểu diễn lệnh, format lệnh, các kiểu đánh địa chỉ. Đây là một tài liệu hữu ích dành cho các bạn sinh viên ngành Công nghệ thông tin và những ai quan tâm dùng làm tài liệu học tập và nghiên cứu.

Kiến trúc máy tính Tập lệnh NGUYỄN Ngọc Hố Bộ môn Hệ thống thông tin, Khoa CNTT Trường Đại học Công nghệ, Đại học Quốc gia Hà Nội 28 October 2015 Hoa.Nguyen@vnu.edu.vn Nội dung  Khái niệm  Biểu diễn lệnh  Format lệnh  Các kiểu đánh địa Tham khảo chương 10, 11 [1] Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá Khái niệm  Tập lệnh: tập đầy đủ lệnh mà CPU hiểu  Lệnh: Mã máy (binary), thường biểu diễn mã hợp lệnh (assembly codes)  Phần nhìn thấy máy tính người lập trình (đặc biệt người viết chương trình dịch)  Thể khái quát mặt logic máy tính theo nghĩa registers, hoạt động ALU, kiểu liệu, …  Thiết kế tập lệnh phần quan trọng việc thiết kế CPU  Mỗi kiểu máy tính có tập lệnh CPU đặc thù Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá Khái niệm…  Một lệnh phải chứa thơng tin địi hỏi CPU:  Mã lệnh (operation code – opcode): mã nhị phân xác định thao tác phải thi hành  Tham chiếu đến toán hạng nguồn  Tham chiếu đến toán hạng đích  Tham chiếu đến lệnh Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá Sơ đồ trạng thái chu trình lệnh Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá Biểu diễn lệnh  Biểu diễn lệnh: chuỗi bits chia thành trường Opcode bits Operand Reference bits Operand Reference Biểu diễn tượng trưng: opcode lẫn toán hạng Ex: ADD A,B  Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hố bits Ví dụ Địa nhớ Diễn dịch Nội dung 0100 0010 0010 0000 1100 LOAD (1100) 0101 0001 0010 0000 1101 ADD (1101) 0110 0001 0010 0000 1110 ADD (1110) 0111 0011 0010 0000 1111 STORE (1111) 1100 0000 0000 0000 0010 0002 1101 0000 0000 0000 0011 0003 1110 0000 0000 0000 0100 0004 1111 0000 0000 0000 0000 0000 Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hố NGUYỄN NGUYEN Ngọc Hố Ngơn ngữ máy tính  Được chia làm nhiều bậc khác nhau:  Bậc thấp LLL: ngôn ngữ máy (binary), hợp ngữ…  Bậc cao HLL: C, Pascal, Basic  Một lệnh HLL tương ứng với nhiều lệnh LLL  Tập lệnh phải đảm bảo đủ khả mã hoá tất lệnh ngơn ngữ bậc cao Ví dụ : X = X + Y dịch thành:    LOAD X, R1 ADD R1, Y STORE R1, X Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá Thiết kế tập lệnh Thoả hiệp giữa:  Số lượng phép toán  Độ phức tạp phép toán  Số kiểu liệu  Số ghi registers  Phương thức sử dụng registers  Các kiểu đánh địa  Số lượng trường lệnh  Độ lớn trường Thiết kế tập lệnh  thiết kế CPU Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá Format lệnh Phân loại tập lệnh theo format lệnh: dựa số lượng địa toán hạng tham chiếu   Lý thuyết: cần trường để chứa địa      Toán hạng nguồn Toán hạng nguồn Toán hạng kết Lệnh Thực tế:     địa chỉ: sử dụng địa chỉ: cho nguồn cho đích địa chỉ: sử dụng accumulator để chứa toán hạng kết địa chỉ: sử dụng stack để chứa toán hạng kết Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 10 PowerPC…  Rẽ nhánh     absolu PC relative indirect Tính tốn số học   register (integer, float) immediate (integer) Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 31 PowerPC : format lệnh Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 32 PowerPC : format lệnh Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 33 Pentium - INTEL general registers 32 bits  general registers 16 bits  general registers bits registers 32 bits sử dụng cho toán hạng 64 bits   address = segment + offset      segment registers descriptor registers base register index register Chi tiết tham khảo địa https://en.wikipedia.org/wiki/X86_instruction_listings Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 34 Pentium - INTEL: kiểu đánh địa    immediate register displacement content of segment register + displacement  indirect by register content of segment register + content of base register  base and displacement content of segment register + content of base register + displacement contained in the instruction  base + index + displacement Ditto previous + content of index register  base + scaled index + displacement Ditto previous + content of index register X scaled factor (scaled factor: 1, 2, 4, 8)  scaled index + displacement content of segment register + content of base register X scaled factor + displacement contained in the instruction  relative content of PC + displacement contained in the instruction Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 35 Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 36 Pentium: format lệnh  Nhiều kiểu lệnh khác nhau:     Hiệu thi hành lệnh thể ngôn ngữ bậc cao Tn thủ tương thích dịng 8086 Kiểu đánh địa xác định thông qua opcode Một lệnh bao gồm:      Prefix: 0, 1, 2, bytes, Opcode: or bytes, Address specificator: 0, or bytes, Displacement: 0, 1, or bytes, Immediate: 0, 1, or bytes Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 37 Pentium: format lệnh Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 38 Tổng kết  Khái niệm tập lệnh, kiểu lệnh, format lệnh  Các yếu tố định đến tập lệnh  Các hình thức tham chiếu, đánh địa tập lệnh   Immediate, Direct, Indirect, Register, Register Indirect, Displacement (Indexed), Stack Các format lệnh số CPU    Format lệnh Intel Format lệnh SUN Format lệnh PowerPC Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 39 Bài tập So sánh kiểu kiến trúc lệnh sử dụng     accumulator memory-memory stack load-store Giả thiết:     byte: opcode bytes: địa nhớ bytes: toán hạng Kích thước lệnh hệ số byte Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 40 Accumulator Opcode bits Address 16 bits LOAD B ADD C STORE A ADD C STORE B SUBINV A STORE D × 24 bits = 168 bits Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 41 Memory-Memory Opcode bits Source 16 bits Source 16 bits ADD ADD SUB Destination 16 bits B, C, A A, C, B B, A, D × 56 bits = 168 bits Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 42 Stack Opcode bits Opcode bits Adresse 16 bits PUSH B ADD PUSH C POP B ADD PUSH A POP A PUSH B PUSH A SUB PUSH C POP D × 24 bits + × bits = 240 bits Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 43 Load-Store Opcode bits Ri bits xx bits Adresse 16 bits Opcode bits R1 bits R2 bits Rd bits LOAD Rb, B LOAD Rc, C ADD Rb, Rc, Ra STORE Ra, A × 32 bits + × 24 bits = 232 bits xx bits ADD STORE SUB STORE Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá Ra, Rc, Rb Rb B Rb, Ra, Rd Rd, D 44 Memory Access  accumulator phép chuyển liệu (7 × 32 = 224) + độ lớn code (168) = 392 bits for instructions (56 bits/instruction)  memory-memory phép chuyển liệu (9 × 32 = 288) + độ lớn code (168) = 456 bits for instructions (152 bits/instructions)  stack phép chuyển liệu (9 × 32 = 288) + độ lớn code (240) = 528 bits for 12 instructions (44 bits/instructions)  load-store phép chuyển liệu (5 × 32 = 160) + độ lớn code (232) = 392 bits for instructions (49 bits/instructions) Computer Architecture – –Department Department of ofInformation Information Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 45 ... NGUYỄN NGUYEN Ngọc Hoá Khái niệm  Tập lệnh: tập đầy đủ lệnh mà CPU hiểu  Lệnh: Mã máy (binary), thường biểu diễn mã hợp lệnh (assembly codes)  Phần nhìn thấy máy tính người lập trình (đặc biệt... Systems Systems @ @Hoá NGUYỄN NGUYEN Ngọc Hoá 21 Độ lớn lệnh  Tập lệnh phức tạp thì:     Độ dài lệnh phụ thuộc:     Số lượng lệnh chương trình giảm, Càng làm tăng độ dài lệnh, Càng sử dụng... NGUYỄN NGUYEN Ngọc Hoá 38 Tổng kết  Khái niệm tập lệnh, kiểu lệnh, format lệnh  Các yếu tố định đến tập lệnh  Các hình thức tham chiếu, đánh địa tập lệnh   Immediate, Direct, Indirect, Register,

Ngày đăng: 07/05/2021, 13:21

Tài liệu cùng người dùng

Tài liệu liên quan