1 / 7

Character Strings

Character Strings. Programs need to manipulate more than numbers (integers) Character encoding EBCDIC ( E xtended B inary- C oded D ecimal I nterchange C ode ) ASCII ( A merican S tandard C ode for I nformation I nterchange ) 7bit -> 8bit (ISO-8859)

cerelia
Download Presentation

Character Strings

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. Character Strings • Programs need to manipulate more than numbers (integers) • Character encoding • EBCDIC (Extended Binary-Coded Decimal Interchange Code) • ASCII (American Standard Code for Information Interchange) • 7bit -> 8bit (ISO-8859) • UNICODE (8/16/24bit variable width) Ch.3 - Machine Instructions - III

  2. ASCII Encoding Ch.3 - Machine Instructions - III

  3. ISO-Latin-1 Encoding (high bit) Ch.3 - Machine Instructions - III

  4. Sequences of Characters (Strings) Three ways to encode: • Store length at head of string • Store length in accompanying variable (inside format structure) • Termination character at end of sequence Ch.3 - Machine Instructions - III

  5. Sequences of Characters (Strings) Termination character at end of sequence • C/C++ convention (code “0” for terminator) Ch.3 - Machine Instructions - III

  6. C void strcpy (char x[], char y[]) { int i = 0; while (y[i] != NULL) { x[i] = y[i]; i = i + 1; } x[i] = NULL; } MIPS strcpy: addi $sp,$sp,-4 sw $s0,0($sp) addi $s0,$zero,0 L1: add $t1,$a1,$s0 lb $t2,0($t1) add $t3,$a0,$s0 sb $t2,0($t3) addi $s0,$s0,1 bne $t2,$zero,L1 lw $s0,0($sp) addi $sp,$sp,4 jr $ra Manipulating Strings Ch.3 - Machine Instructions - III

  7. Manipulating Strings (con’t) strcpy: addi $sp,$sp,-4 # Allocate stack frame sw $s0,0($sp) # Store current $s0 addi $s0,$zero,0 # $s0 (i) initialized to 0 L1: add $t1,$a1,$s0 # $t1 gets address of y[i] lb $t2,0($a1) # $t2 gets byte at y[i] add $t3,$a0,$s0 # $t3 gets address of x[i] sb $t2,0($t3) # $t2 value stored addi $s0,$s0,1 # i++ bne $t2,$zero,L1 # Loop back if char in $t2 # is non-null lw $s0,0($sp) # restore $s0 addi $sp,$sp,4 # release stack frame jr $ra # return to caller Ch.3 - Machine Instructions - III

More Related