1 / 17

CPEG323 Homework Review I

CPEG323 Homework Review I. Long Chen October, 17 th , 2005. Homework 1. Basic Computer Terms Problem 1: Find the correct word that best matches the given description Problem 2: Classify the items into the categories

barto
Download Presentation

CPEG323 Homework Review I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPEG323 Homework Review I Long Chen October, 17th, 2005

  2. Homework 1 Basic Computer Terms • Problem 1: Find the correct word that best matches the given description • Problem 2: Classify the items into the categories You need to read Chapter 1 of the textbook to understand/answer these questions

  3. Homework 1 - cont • Problem 3 • On average, it takes half a revolution for the desired data on the disk to spin under the read/write head. • Disk is rotating 7200 revolutions per minute (RPM) • Average time for the data to rotate under the disk head? • Answer: 1 min / 7200 * ½

  4. Homework 1 - cont • Problem 4 • One computer issues 30 requests per second • Each request is on average 64KB • Will a 100Mbit Ethernet link be sufficient? • Answer • 30 * 64 KB/s = 1,920 KB/s = 15,360 Kbit/s • 100Mbit/s > 15,360 Kbit/s, sufficient! • B (Byte) versus b (bit) (Bps versus bps)

  5. i = 0 No i < x Yes y = y + i; i = i + 1; Homework 2 • Problem 1: • Draw the Control Flow Graph (CFG) of code for (i = 0; i < x, i ++) y = y + i; Basic block: no jump, no exit Similarly, you can group the assembly instructions into basic blocks, then draw the CFG

  6. Homework 2 - cont • Problem 2 • A) Why doesn’t MIPS have a subtract immediate instruction? • Answer: • MIPS includes add immediate instruction • Positive and negative immediate • Add neg imm = sub pos imm • B) Hexadecimal number -> binary number • C) Binary number -> hexadecimal number

  7. Homework 2 - cont • Problem 3 • Implement the C code in MIPS • Draw the status of the stack • Indicate locations of $sp and $fp • Stack pointer: a value denoting the most recently allocated address in a stack • Frame pointer: a value denoting the location of the saved registers and local variables for a given procedure (point to the first word of the frame of a procedure)

  8. Homework 2 - cont Illustration of the stack allocation (a) before, (b) during, and (c) after the procedure call -Reproduce from P & H “Computer Organizatio and Design” 3rd Edition

  9. int i; void set_array(int num) { int arrray[10]; for (i=0;i<10;i++){ array[i]=compare(num,i); } } set_array: addi $sp, $sp, -52 # move stack pointer sw $fp, 48($sp) # save frame pointer sw $ra, 44($sp) # save return address sw $a0, 40($sp) # save parameter (num) addi $fp, $sp, 48 # establish frame pointer add $s0, $zero, $zero # i = 0 addi $t0, $zero, 10 # max iterations is 10 loop: sll $t1, $s0, 2 # $t1 = i * 4 add $t2, $sp, $t1 # $t2 = address of array[i] add $a0, $a0, $zero # pass num as parameter add $a1, $s0, $zero # pass i as parameter jal compare # call compare(num, i) Homework 2 - cont sw $v0, 0($t2) # array[i] = compare(num, i); addi $s0, $s0, 1 # i = i+ 1 bne $s0, $t0, loop # loop if i<10 lw $a0, 40($sp) # restore parameter (num) lw $ra, 44($sp) # restore return address lw $fp, 48($sp) # restore frame pointer addi $sp, $sp, 52 # restore stack pointer jr $ra # return

  10. int compare( int a, int b) { if (sub(a, b) >= 0) return 1; else return 0; } compare: addi $sp, $sp, -8 # move stack pointer sw $fp, 4($sp) # save frame pointer sw $ra, 0($sp) # save return address addi $fp, $sp, 4 # establish frame pointer jal sub # can jump directly to sub slt $v0, $v0, $zero # if sub(a,b) >= 0, return 1 slti $v0, $v0, 1 lw $ra, 0($sp) # restore return address lw $fp, 4($sp) # restore frame pointer addi $sp, $sp, 8 # restore stack pointer jr $ra # return Homework 2 - cont int sub( int a, int b) { return a – b; } sub: sub $v0, $a0, $a1 # return a-b jr $ra # return We don’t save anything. Why? This function does not change argument registers, so, we do not need to save these registers, i.e. $a0, $a1

  11. Homework 2 - cont The status of the stack

  12. Homework 2 - cont • Problem 4 • Comment the following MIPS code • Descript the functionality ($v0 = ?) • As inputs, $a0 = a; $a1 = b add $t0, $zero, $zero loop: beq $a1, $zero, finish add $t0, $t0, $a0 sub $a1, $a1, 1 j loop finish: addi $t0, $t0, 100 add $v0, $t0, $zero # initialize running sum $t0 = 0 # finished when $a1 is 0 # sum $t0 = $t0 + $a0 # compute this $a1 times # add 100 to a * b # return a * b + 100

  13. Homework 2 - cont • Problem 5 • Explain why an assembler might have problems directly implementing the branch instruction in the following code segment here: beq $s0, $s2, there … there: add $s0, $s0, $s0

  14. 2 10000 26 bits 6 bits 5 16 18 16 5 bits 5 bits 16 bits 6 bits Homework 2 - cont Jump instruction: j 10000 Conditional branch instruction: beq $s0, $s2, there New PC = PC + Branch address (PC-relative addressing) If that address is too far away, we won’t be able to use 16 bits to describe where it is relative to the PC

  15. Homework 2 - cont One simple solution would be here: bne $s0, $s2, skip j there skip: … there: add $s0, $s0, $s0 This will work as long as our program does not cross the 256MB (why?) address boundary described in the elaboration on page 98 in the textbook.

  16. Homework 3 Please refer to the solution to be posted by tonight

  17. Good Luck on your test! 

More Related