Chapter 4 Processor Architecture Guobao Jiang 11210240049@fudan.edu.cn
Chapter 4 Processor Architecture Guobao Jiang 11210240049@fudan.edu.cn
Outline 4.1 The y86 Instruction Set Architecture 4.2 Logic Design and the hcl 4.3 Sequential y86 Implementations 4. 4 General Principles of pipelining 4.5 Pipelined y86 Implementations 4.6 Summary 2021/10/29
Outline • 4.1 The Y86 Instruction Set Architecture • 4.2 Logic Design and the HCL • 4.3 Sequential Y86 Implementations • 4.4 General Principles of Pipelining • 4.5 Pipelined Y86 Implementations • 4.6 Summary 2021/10/29 2
Problem 4.1(P262 Determine the byte encoding of the y86 instruction sequence that follows posO×100# start at address o×100 irmovl $15, %ebx 0x100:30830F000000 rrmovl %ebx. %ecx Ox106:2031 oop. Ox108: rmmov%ecx,-3(%eb×)o×08:4013 FD FFFFFF add%‰ebx,‰ecx0×10E:6031 Jmp 0x110:7008010000 2021/10/29
Problem 4.1 (P262) • Determine the byte encoding of the Y86 instruction sequence that follows. .pos 0x100 #start at address 0x100 irmovl $15, %ebx rrmovl %ebx, %ecx loop: rmmovl %ecx, -3(%ebx) addl %ebx, %ecx jmp loop 2021/10/29 3 0x100: 30 83 0F 00 00 00 0x106: 20 31 0x108: 0x108: 40 13 FD FF FF FF 0x10E: 60 31 0x110: 70 08 01 00 00
Problem 4.2(P263) For each byte sequence listed, determine the y86 instruction sequence it encodes A.0x100:3083 FCFFFFFF40630008000010 0x100: 3083FCFFFFFF irmovl $s-r %ebx 0×106:406300080000 rmmov%esi,0x8000%eb× Ox10C:10 halt 2021/10/29
Problem 4.2 (P263) • For each byte sequence listed, determine the Y86 instruction sequence it encodes. • A. 0x100:3083FCFFFFFF40630008000010 2021/10/29 4 0x100: 3083FCFFFFFF irmovl $-r, %ebx 0x106: 406300080000 rmmovl %esi, 0x8000(%ebx) 0x10C: 10 halt
Problem 4.2+(P263) B.0x200:A068 80080200001030830A00000090 0x200:A068 pushl %esi 0×202:8008020000 call proc 0×207:10 halt 0x208: proc. 0×208:30830A000000 armon$10,%ebx 0x20E:90 ret 2021/10/29
Problem 4.2+ (P263) • B. 0x200:A0 68 80080200001030830A00000090 2021/10/29 5 0x200: A068 pushl %esi 0x202: 80 08020000 call proc 0x207: 10 halt 0x208: 3083 0A000000 irmovl $10, %ebx 0x20E: 90 ret 0x208: proc:
Problem 4.2+(P263) E Xercise ·C.0x3005054070000000FOB018 D.0×400:6113730004000010 ·E.0x500:6362A080 2021/10/29
Problem 4.2 +(P263) • Exercise • C. 0x300:5054070000000F0B018 • D. 0x400:6113730004000010 • E. 0x500:6362A080 2021/10/29 6
Problem 4.3(P269) Write y86 code to implement a recursive sum function rSum, based on the following c code: int rSum (int aston P178 Recursive Procedures if(count <= o return o return * Start+ rSum start+1, Count-1) 2021/10/29
Problem 4.3 (P269) • Write Y86 code to implement a recursive sum function rSum, based on the following C code: int rSum(int *Start, int Count) { if (Count <= 0) return 0; return *Start + rSum(Start+1, Count-1); } 2021/10/29 7 P178 Recursive Procedures
Problem 4.3+(P269) rSum: push1 %ebp rrmovl %ebx, %eax rrmovl %esp, %ebp add%ed×,%ea irmovl 20, %eax 66 su ea×,%esp pushl yeax US %ebx call rSum mrmovl 8(%ebp), %ebx mrmovI (%ebx, %edx mrmovl 12(%ebp),%eax ‰edx.%eax add!%ea×.%ea Jmp L39 L38 irmovl $-8, %edx add %edx, %es L38:xorl%ea×,%eax irmovl $-1, %edx L39: mrmovl-24(%ebp), %ebx add %edx eax rrmovI %ebp, %esp push/ hl eax Irmove|$4,‰edx popl %ebp ret 2021/10/29
Problem 4.3+ (P269) rSum: push1 %ebp rrmovl %esp, %ebp irmovl $20, %eax subl %eax, %esp pushl %ebx mrmovl 8(%ebp), %ebx mrmovl 12(%ebp), %eax addl %eax, %eax jle L38 irmovl $-8, %edx addl %edx, %esp irmovl $-1, %edx addl %edx, %eax pushl %eax irmovel $4, %edx 2021/10/29 8 rrmovl %ebx, %eax addl %edx, %eax pushl %eax call rSum mrmovl (%ebx), %edx addl %edx, %eax jmp L39 L38: xorl %eax, %eax L39: mrmovl -24(%ebp), %ebx rrmovl %ebp, %esp popl %ebp ret
Problem 4.4(P270) int pushtesto int rval / Insert the following assembly code movl %esp, %eax #save stack pointer pushl%esp #push stack pointer popl %edx #pop it back subl edx. eax tto or 4 movl %oeax, rval set as return quay It implies that pus the original value of return rval %esp old value In our experiments, we find that the function pushtest return o W lat does this imply about the behavior of the instruction pushl %oesp under IA 32 2021/10/29
Problem 4.4 (P270) int pushtest() { int rval; /* Insert the following assembly code: movl %esp, %eax #save stack pointer pushl %esp #push stack pointer popl %edx #pop it back subl %edx, %eax # 0 or 4 movl %eax, rval # set as return value */ … return rval; } In our experiments, we find that the function pushtest return 0. What does this imply about the behavior of the instruction pushl %esp under IA32? 2021/10/29 9 It implies that push the original value of %esp (old value)
Problem 4.5(P270) int poptesto int rval / Insert the following assembly code pushl tval #t save tval on stack movl %esp, %edx #f save stack pointer popl %esp t pop to stack pointer movl %oesp, rval setI movl %edx, %esp( It implies that popl %esp set the stack pointer to the value read from memory return rval mrmovl o(%esp). loess We find this function always returns tval the value passed to it as its argument. What does this imply about the behavior of pop es other y86 ins c tion would have th behavior 2021/10/29
Problem 4.5 (P270) int poptest() { int rval; /* Insert the following assembly code: pushl tval # save tval on stack movl %esp, %edx # save stack pointer popl %esp # pop to stack pointer movl %esp, rval # set popped value as return value movl %edx, %esp # restore original stack pointer */ … return rval; } We find this function always returns tval, the value passed to it as its argument. What does this imply about the behavior of popl %esp ? What other Y86 instruction would have the exact same behavior? 2021/10/29 10 It implies that popl %esp set the stack pointer to the value read from memory. mrmovl 0(%esp), %esp