CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/22/2013 Lecture 12: Character Data Instructor:...

Click here to load reader

download CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/22/2013 Lecture 12: Character Data Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.

of 11

Transcript of CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/22/2013 Lecture 12: Character Data Instructor:...

  • CPS3340 COMPUTER ARCHITECTURE Fall Semester, 201310/22/2013Lecture 12: Character DataInstructor: Ashraf YaseenDEPARTMENT OF MATH & COMPUTER SCIENCECENTRAL STATE UNIVERSITY, WILBERFORCE, OH*

  • ReviewLast ClassProceduresThis ClassHandling Character DataNext ClassStarting and Loading a ProgramLinkingDynamic Linking*

  • Character DataByte-encoded character setsASCII: 128 characters95 graphic, 33 controlLatin-1: 256 charactersASCII, +96 more graphic charactersUnicode: 32-bit character setUsed in Java, C++ wide characters, Most of the worlds alphabets, plus symbolsUTF-8, UTF-16: variable-length encodings2.9 Communicating with People*

  • ASCII*

  • Unicode *

  • Byte OperationLoad Byte (lb)Load a byte from memoryPlace it in the rightmost 8 bits of a registerExamplelb $t0, 0($sp)Store Byte (sb)Take a byte from the rightmost 8 bits of a registerWrite it to the memoryExamplesb $t0, 0($sp)*

  • Byte/Halfword OperationsCould use bitwise operationsMIPS byte/halfword load/storeString processing is a common caselb rt, offset(rs) lh rt, offset(rs)Sign extend to 32 bits in rtlbu rt, offset(rs) lhu rt, offset(rs)Zero extend to 32 bits in rtsb rt, offset(rs) sh rt, offset(rs)Store just rightmost byte/halfword*

  • String Copy ExampleC code (nave):Null-terminated stringvoid strcpy (char x[], char y[]) { int i; i = 0; while ((x[i]=y[i])!='\0') i += 1; }Addresses of x, y in $a0, $a1i in $s0*

  • String Copy ExampleMIPS code:strcpy: addi $sp, $sp, -4 # adjust stack for 1 item sw $s0, 0($sp) # save $s0 add $s0, $zero, $zero # i = 0 L1: add $t1, $s0, $a1 # addr of y[i] in $t1 lbu $t2, 0($t1) # $t2 = y[i] add $t3, $s0, $a0 # addr of x[i] in $t3 sb $t2, 0($t3) # x[i] = y[i] beq $t2, $zero, L2 # exit loop if y[i] == 0 addi $s0, $s0, 1 # i = i + 1 j L1 # next iteration of loop L2: lw $s0, 0($sp) # restore saved $s0 addi $sp, $sp, 4 # pop 1 item from stack jr $ra # and return*

  • SummaryHandling Character Data*

  • What I want you to doReview Chapter 2Prepare for Midterm II*

    *The University of Adelaide, School of Computer Science*Chapter 2 Instructions: Language of the Computer*The University of Adelaide, School of Computer Science*Chapter 2 Instructions: Language of the Computer*The University of Adelaide, School of Computer Science*Chapter 2 Instructions: Language of the Computer*The University of Adelaide, School of Computer Science*Chapter 2 Instructions: Language of the Computer*