Sikau

Assembly language · Day 7 · about 35 min

Strings and bytes

Null-terminated strings, lb/lbu/sb, and changing text in place.

A string is bytes and a zero

In C and in assembly a string is just consecutive bytes (ASCII codes) ending with a null terminator — a 0 byte. No length is stored: to find it you walk until the zero. .asciz adds that zero for you.

.data
msg:   .asciz "hello, risc-v!"
mixed: .asciz "Abc xyZ 123"
empty: .asciz ""

Walking bytes

  • lbu t1, 0(t0) loads one byte (0–255) — use lbu for characters.
  • sb t1, 0(t0) stores the low byte of t1.
  • li t1, 'a' — a character in quotes is its ASCII code (97).
  • Lower and upper case letters are exactly 32 apart: 'a' − 'A' = 32.

The rest of this lesson

  • strlen, byte by byteexplain
  • Changing case with arithmeticexplain
  • Count to the zerofill
  • Characters as numbersmatch
  • Length and upper casewrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 12 lessons of Assembly language