0% found this document useful (0 votes)
1 views

Chapter 9_ Assembly Language - Strings, Arrays, and Java Bytecodes

Chapter 9 focuses on string manipulation, array operations, and Java bytecodes, emphasizing the importance of low-level memory management for efficient programming. It covers string primitive instructions, two-dimensional array access, searching and sorting algorithms, and Java bytecodes for string processing. The chapter concludes with insights on mastering assembly for better control over data structures and understanding high-level operations in low-level code.

Uploaded by

tabeen.bokhat
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Chapter 9_ Assembly Language - Strings, Arrays, and Java Bytecodes

Chapter 9 focuses on string manipulation, array operations, and Java bytecodes, emphasizing the importance of low-level memory management for efficient programming. It covers string primitive instructions, two-dimensional array access, searching and sorting algorithms, and Java bytecodes for string processing. The chapter concludes with insights on mastering assembly for better control over data structures and understanding high-level operations in low-level code.

Uploaded by

tabeen.bokhat
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter 9: Assembly

Language - Strings,
Arrays, and Java
Bytecodes
This chapter covers string manipulation, array operations, and Java
bytecodes.

Mastering low-level memory management is crucial for efficient


programming.

Our goal: build proficiency in implementing data structures in


assembly.

by Tabeen Bokhat
2023-ce-13
That brings us to the end of my
presentation.
Thank you for your attention

String Primitive
Instructions
Move instructions
`MOVSB`, `MOVSW`, `MOVSD` transfer string data byte to dword.

Compare
instructions
`CMPSB`, `CMPSW`, `CMPSD` compare string elements, use repeat
prefixes.

Load and Store


`LODS*` loads from source, `STOS*` stores from accumulator to
destination.

Scan instructions
`SCAS*` scan strings by comparing accumulator with destination
data.
Selected String
Procedures
String length String copy Concatenation Case-insensitive
compare
Use `SCASB` to find null Loop with `MOVSB` to Find string end, then
terminator and calculate copy until null terminator copy second string after Convert characters to

string length. is reached. it. uppercase before


comparison for equality
check.
Two-Dimensional
Arrays
Row-major layout Declaration
Rows stored contiguously; example
`my_array DWORD 5
address uses row and DUP(10 DUP(0))` creates
column with element size. 5x10 2D array initialized to
zero.

Accessing
elements
Calculate offset: `base + (row*cols + col)*element_size` for
pointer access.
Searching Integer
Arrays
Linear search Binary search

Scan elements sequentially, compare each to target, Divide sorted array search space by half iteratively,
O(n) time. O(log n) time.
Sorting Integer
Arrays
Bubble sort Insertion sort
Repeatedly swap Build sorted section by
adjacent elements if out inserting elements in
of order, O(n²) order, O(n²) complexity.
complexity.
Optimization
Terminate early if no swaps happen in a pass, detecting
sorted array.
Java Bytecodes for
String Processing
Immutability Common
Java strings cannot be bytecodes
• `ldc`: load string literals
changed once created. • `new`: create objects
• `invokespecial`: invoke
constructors
• `invokevirtual`: call
string methods

Concatenation
Uses `StringBuilder` to append and convert back to string
efficiently.
Bytecode Analysis
Tools
javap IDE debuggers Decompilers
disassembler
List bytecode of class methods to Step through bytecode execution, Convert bytecode back to readable
understand compiled code inspect stack and locals in real- Java code for analysis and
structure. time. debugging.
Example: String
Reversal in Java
1 Create
Bytecode
StringBuilder
`new` and `dup` prepare a new object.

2 Initialize with
String
Constructor invoked with original string argument.

3 Reverse &
Convert
Call `reverse()` then `toString()` for reversed string.

4 Return result
`areturn` returns reversed string from the method.
Summary and
Conclusion
Assembly
mastery
Gain control over strings and arrays via primitive instructions.

2D arrays
Calculate addresses precisely for multidimensional access.

Java bytecode
insight
Understand how high-level string operations compile to
low-level code.

System-level
skills
Essential knowledge for optimizing and debugging
complex software.

You might also like