kiến trúc máy tính trương văn cường lecture 04 chương ter 02 language of the computer 03 sinhvienzone com

36 51 0
kiến trúc máy tính trương văn cường lecture 04 chương ter 02 language of the computer 03 sinhvienzone com

Đ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

COMPUTER ARCHITECTURE Chapter Lecture Instruction: Language of the Computer CuuDuongThanCong.com https://fb.com/tailieudientucntt The goals • Bốn nguyên tắc thiết kế • Ba tốn hạng máy tính • Biểu diễn lệnh máy tính • Phân loại lệnh theo định dạng: Rtype, I-Type, J-Type • Phân loại lệnh theo chức • Chuyển đổi lệnh ngôn ngữ: cấp cao, hợp ngữ, ngôn ngữ máy Sep-16 CuuDuongThanCong.com https://fb.com/tailieudientucntt Chapter contents Introduction Operations/operands of the Computer Hardware Signed and Unsigned number (review) MIPS Instruction Arithmetic instruction Logical instruction MIPS Memory Access Instructions Branch/jump instruction Sep-16 CuuDuongThanCong.com https://fb.com/tailieudientucntt References • Slide: • Computer Organization and Design, 4th Edition, Patterson & Hennessy, © 2008, MK • Mary Jane Irwin, Penn State University • KTMT, ĐH BKTPHCM • Textbook: Chương (p.74 – p.221) • Software: • Mars / Qtspim • MIPS reference Data • Resources: • • • • https://uit.edu.vn/~ktmt/mips-tutorial https://uit.edu.vn/~ktmt/references https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/jump.html https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/load32.ht ml • https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/pseudojum p.html Sep-16 CuuDuongThanCong.com https://fb.com/tailieudientucntt Lecture contents MIPS Memory Access Instructions instruction Logical instruction Sep-16 CuuDuongThanCong.com https://fb.com/tailieudientucntt MIPS Memory Access Instructions Tại cần sử dụng lệnh di chuyển liệu nhớ ghi? Register File 32 bits src1 addr src2 addr dst addr write data 5 32 • MIPS có hai lệnh di chuyển liệu để truy xuất nhớ • Dữ liệu nạp từ nhớ vào ghi (lw) lưu từ ghi vào nhớ (sw) tập ghi (register file) data 32 locations 32 src2 data write control MIPS Memory Access Instructions CuuDuongThanCong.com 32 src1 https://fb.com/tailieudientucntt Machine Code Representation Tất lệnh thuộc I-Format Instruction B31-26 B25-21 B20-16 opcode rs rt immediate lw $rt, $rs) 100 011 - - offset lb $rt, $rs) 100 000 - - offset lbu $rt, $rs) 100 100 - - offset sw $rt, $rs) 101 011 - - offset sw $rt, $rs) 101 100 - - offset Sep-16 CuuDuongThanCong.com MIPS Memory Access Instructions https://fb.com/tailieudientucntt B15-0 How to determine memory address  Địa 32bit nhớ xác định cách cộng vào địa giá trị offset  The memory address – a 32 bit address – is formed by adding the contents of the base address register to the offset value  16 bit giá trị offset giới hạn vị trí nhớ nằm khoảng 213 or 8,192 words (215 or 32,768 bytes) địa  Giá trị offset âm dương Sep-16 CuuDuongThanCong.com MIPS Memory Access Instructions https://fb.com/tailieudientucntt Example lw sw $t0, 4($s3) #load word from memory $t0, 8($s3) #store word to memory Sep-16 CuuDuongThanCong.com MIPS Memory Access Instructions https://fb.com/tailieudientucntt Machine Language - Load Instruction lw $t0, 24($s3) 35 19 Memory 2410 + $s3 = 0001 1000 + 1001 0100 1010 1100 = 0x120040ac Sep-16 CuuDuongThanCong.com 2410 0xf f f f f f f f 0x120040ac $t0 0x12004094 $s3 MIPS Memory Access data Instructions 0x0000000c 0x00000008 0x00000004 0x00000000 word address (hex) 10 https://fb.com/tailieudientucntt Unconditional branch instruction • MIPS có lệnh rẽ nhánh không điều kiện Jump j  label #go to label Instruction Format (J Format): 0x02 26-bit address from the low order 26 bits of the jump instruction 26 00 32 PC 32 Unonditional branch CuuDuongThanCong.com https://fb.com/tailieudientucntt Branching Far Away • Làm thể địa rẽ nhánh nằm tầm offset 16 bit  Chèn lệnh jump để “nhảy” xa beq $s0, $s1, L1 Thành: bne $s0, $s1, L2 j L1 L2: Unonditional branch CuuDuongThanCong.com https://fb.com/tailieudientucntt Assignments • Translating Some Pseudoinstructions Pseudoinstruction Translation mov $rt, $rs li $rs, small li $rs, big la $rs, big lw $rt, big($rs) Sep-16 CuuDuongThanCong.com Conditional branch https://fb.com/tailieudientucntt 24 Compiling If Statements • C code: if (i==j) f = g+h; else f = g-h; • f, g, … in $s0, $s1, … • Compiled MIPS code: Conditional branch CuuDuongThanCong.com https://fb.com/tailieudientucntt Compiling Loop Statements • C code: while (save[i] == k) i += 1; • i in $s3, k in $s5, address of save in $s6 • Compiled MIPS code: Conditional branch CuuDuongThanCong.com https://fb.com/tailieudientucntt Compiling switch Statement switch (i) { case 0: f = i + j; break; case 1: f = g + h; break; case 2: f = g – h; break; case 3: f = i – j; break; Default: f = 0; break } Sep-16 CuuDuongThanCong.com Conditional branch https://fb.com/tailieudientucntt 27 Compiling switch Statement Sep-16 CuuDuongThanCong.com Conditional branch https://fb.com/tailieudientucntt 28 Procedures • Hàm giúp lập trình viên phân chia chương trình thành khối chức để: Dễ dàng cho việc viết sửa lỗi Cho phép dùng lại code • Hàm giúp lập trình viên tập trung thực khối chức đơn giản thời điểm Các tham số giao diện hàm phần cịn lại chương trình, tham số gồm có đối số truyền cho hàm (arguments) giá trị trả (results) Sep-16 CuuDuongThanCong.com Procedures 29 https://fb.com/tailieudientucntt Instructions for Accessing Procedures • MIPS: Lệnh gọi thủ tục jal ProcedureAddress #jump and link • Lưu địa lệnh (PC+4) nhảy tới hàm gọi • Định dạng lệnh (J format): 0x03 26 bit address • Nhảy tới địa lệnh tiếp thep (PC+4) lưu $ra jr $ra #return Procedures CuuDuongThanCong.com https://fb.com/tailieudientucntt Six Steps in Execution of a Procedure Caller đặt tham số vào nơi mà thủ tục (callee) truy xuất chúng • $a0 - $a3: ghi đối số ngõ vào Caller di chuyển điều khiển đến callee Callee thu thập tài nguyên lưu trữ cho thủ tục Callee thực nhiệm vụ Callee đặt kết vào nơi mà chương trình truy xuất • $v0 - $v1: hai ghi chứa giá trị trả Callee trả quyền điều khiển cho Caller • $ra: ghi chứa địa trở return address Procedures CuuDuongThanCong.com https://fb.com/tailieudientucntt Leaf Procedure Example • C code (hàm không gọi hàm khác): int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; } • Các đối số g, …, j in $a0, …, $a3 • Kết $v0 Procedures CuuDuongThanCong.com https://fb.com/tailieudientucntt Leaf Procedure Example • MIPS code: leaf_example: add $t0, $a0, $a1 add $t1, $a2, $a3 sub $v0, $t0, $t1 jr $ra Procedure body Result Return Procedures CuuDuongThanCong.com https://fb.com/tailieudientucntt Spilling Registers • Điều xảy sơ ghi lớn đối số phân bổ giá trị trả ? high • callee sử dụng stack – a last-in-first-out queue (LIFO)  Thanh ghi $sp (29) sử dụng addr để giữ địa stack (stack “lớn” theo chiều xuống) top of stack $sp  Chèn liệu vào stack– push $sp = $sp – sw data,0($sp)  Xóa liệu khỏi stack - pop $sp = $sp + low addr $sp = $sp + Procedures CuuDuongThanCong.com https://fb.com/tailieudientucntt Leaf Procedure Example • C code (hàm có gọi hàm khác): int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; } • Các đối số g, …, j in $a0, …, $a3 • f in $s0 (vì vậy,cần bảo tồn giá trị $s0 stack) • Kết $v0 Procedures CuuDuongThanCong.com https://fb.com/tailieudientucntt Leaf Procedure Example • MIPS code: leaf_example: addi $sp, $sp, -4 sw $s0, 0($sp) add $t0, $a0, $a1 add $t1, $a2, $a3 sub $s0, $t0, $t1 add $v0, $s0, $zero lw $s0, 0($sp) addi $sp, $sp, jr $ra Save $s0 on stack Procedure body Result Restore $s0 Return Procedures CuuDuongThanCong.com https://fb.com/tailieudientucntt ... ngữ: cấp cao, hợp ngữ, ngôn ngữ máy Sep-16 CuuDuongThanCong .com https://fb .com/ tailieudientucntt Chapter contents Introduction Operations/operands of the Computer Hardware Signed and Unsigned... lb $rt, $rs) 100 000 - - offset lbu $rt, $rs) 100 100 - - offset sw $rt, $rs) 101 011 - - offset sw $rt, $rs) 101 100 - - offset Sep-16 CuuDuongThanCong .com MIPS.. .The goals • Bốn nguyên tắc thiết kế • Ba tốn hạng máy tính • Biểu diễn lệnh máy tính • Phân loại lệnh theo định dạng: Rtype, I-Type, J-Type • Phân loại lệnh theo chức • Chuyển

Ngày đăng: 28/01/2020, 23:15

Từ khóa liên quan

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

  • Đang cập nhật ...

Tài liệu liên quan