1
ASSIGNMENT 7 ON ASEMBLER LANGUAGE: CONCEPTS AND TECHNIQUES
Bartholomew Wani
Department of Computer Science
CS 1105-01 Digital Electronics and Computer Architecture -AY2026-T1
Instructor’s name: Pinky Shyamlal Gerela
October 22nd, 2025
2
Assembly Language Implementation of a Stack for String Reversal
Being new to assembly language programming, this project is intended for me to show an
understanding of lower-level concepts by creating a stack data structure in an assembly language
to reverse a string, a common programming task. The following describes the design,
development, and advantages of an assembly language program.
1. An Assembly Language String Reversal Program Using a Stack
Due to the difficulty of providing a complete assembly program which is executable with this
response, here is a summary of the important components and logic. The program has a
simplified assembly language target environment (for example: an x86 architecture with a no-
frills assembler) and the organization for instructional clarity and value rather than the ultimate
in optimization.
Data Segment: An area defining memory locations for the string to reverse, the stack, and
variables needed including the stack pointer.
• original_string: db “Hello World”, 0 ; Null-terminated string
• reversed_string: db 20 dup(0) ; Buffer for reversed string
• stack: db 10 dup(0) ; Stack (limited size for simplicity)
• stack_pointer: dw stack ; Pointer to the top of the stack
The Code Section is where the logic for the program is located.
• Push Function: This subroutine accepts a character and pushes it to the stack.
* Verify that the stack has not overflowed (the stack pointer is not past the stack boundary).
* Set the character in memory, at the address pointed to by the stack pointer.
* Increment the stack pointer.
• Pop Function: This subroutine pops a character off the stack.
* Verify the stack has not underflowed (the stack pointer is greater than the stack's base
address).
* Decrement the stack pointer.
* Get the character from memory, at the address pointed to by the stack pointer.
3
• Main Program Logic:
* Load the address of the original string.
* Loop through string, and pushing it to the stack, character by character.
* Load address for the reversed string.
* Loop to pop off the stack and store them in the reversed string buffer.
* Null terminate the reversed string.
* (Optional) Print the reversed string (requires special calls depending on the system).
An example of the pseudo code for the push instruction is shown below:
```
Push:
Cmp stack_pointer, end_of_stack
Je overflow_error
Mov [stack_pointer], register_with_character ; store character
Inc stack_pointer
Ret
```
An example of the pseudo code for the pop instruction is shown below:
```
Pop:
Cmp stack_pointer, start_of_stack
Je underflow_error
Dec stack_pointer
4
Mov register_to_hold_char, [stack_pointer] ; load character
Ret
```
2. Design and Development Process
The process of development started with a good understanding of the stack data structure (LIFO
- Last-In, First-Out). I pictured how memory layouts of the stack and strings would be
represented. I broke down the problem space into three simpler components: push, pop, and the
main program loop.
Development was an iterative process: I wrote the push and pop functions first and tested them
extensively using basic data. Then, I moved into the main program loop, manually managing the
addresses in memory as I worked with pointers. Debugging consisted of using a debugger that
stepped through the code, checking memory addresses and figuring out issues related to logic or
accessing memory.
This had developed my understanding of lower level programming concepts. I found a better
appreciation for what assembly language provided in terms of memory management, pointer
arithmetic, and direct control over hardware. It showed me the benefit of being thoughtful and
check for detail, managing memory and registers in an assembly language program.
3. Benefits of Assembly Language for Implementing Data Structures
Implementing high level data structures like stacks using assembly langage has many advantages
in performance and control:
Effectiveness: Through assembly language one can have greater control over the CPU
instructions, and thereby optimize the code for a specific CPU architecture. In contexts where
performance is paramount (such as embedded systems or real-time applications), a program can
be more efficient if memory is generated by assembly language and not by a higher-level
language compiler.
Direct Hardware Access: Assembly is not only great for performance; it also has access to
hardware directly and can modify memory, registers, and I/O devices. This is particularly
relevant for device drivers, operating system kernels, and low-level system programming.
Insights into Computer Architecture: Assembly language provides excellent observation into the
architecture of computers. Assembly will expose how the CPU works, the structure of memory,
5
and how instructions are executed to provide valuable insights into an especially deep
understanding of how software interacts with hardware.
Security: For security sensitive programs or applications, being able to read assembly may be
crucial to understanding how to analyze and mitigate vulnerabilities. The assembly code can
expose issues like buffer overflows, format string vulnerabilities, or other forms of vulnerability
that would otherwise be challenging to identify in higher-level programming languages.
It is often useful to implement a stack or queue of instruction in assembly language for
embedded systems which operate at minimum memory allocations and maximum code execution
speed. Having the control of memory allocations and instruction scheduling is an significant
advantages over hand-optimized programs with greater flexibility. Another example is writing
optimized graphic routines that require hardware access.
Though coding in assembly language is more complex and labor-intensive than coding in more
powerful languages, the efficiency increases, hardware accessibility, and understanding of the
computer architecture can be worth the investment for specialized tasks. The results of this
project helped reinforce my understanding of these points and the idea of positioning the right
language for the job.
Word count: 923
References
• Hennessy, J. L., & Patterson, D. A. (2017). Computer architecture: A quantitative approach
(6th ed.). Morgan Kaufmann.
• Hyde, R. (2003). The art of assembly language programming. No Starch Press.