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

Assignment Unit 7CS

The document describes an assembly language program developed to reverse a string using a stack data structure, specifically for the x86 architecture with NASM syntax. It outlines the program construction, design process, and benefits of using assembly language, emphasizing performance, memory management, and educational value. The project enhanced the author's understanding of low-level programming concepts and demonstrated the practical application of data structures in software development.

Uploaded by

aminonlinevisa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Assignment Unit 7CS

The document describes an assembly language program developed to reverse a string using a stack data structure, specifically for the x86 architecture with NASM syntax. It outlines the program construction, design process, and benefits of using assembly language, emphasizing performance, memory management, and educational value. The project enhanced the author's understanding of low-level programming concepts and demonstrated the practical application of data structures in software development.

Uploaded by

aminonlinevisa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1

CS 1105-01 Digital Electronics & Computer Architecture – AY2025-T2

University of the People

CS 1105-01

Nnarmdi Nwosu (Instructor)

Thursday , 2 Jan 2025


2

### Assembly Language Program for String Reversal Using a Stack

#### 1. Program Construction

In this assignment, I developed a simple assembly language program that utilizes a stack
data structure to reverse a string. The program is designed for the x86 architecture
using NASM (Netwide Assembler) syntax. The stack is an ideal choice for this task
because it operates on a Last In, First Out (LIFO) principle, which aligns perfectly with
the requirements for reversing a string.

Here is a simplified version of the assembly code:

```assembly
section .data
str db 'Hello, World!', 0 ; null-terminated string
len equ $ - str ; length of the string

section .bss
stack resb len ; reserve space for the stack

section .text
global _start

_start:
; Push characters onto the stack
mov ecx, len ; set counter to length of string
lea esi, str ; load address of the string

push_loop:
dec ecx ; decrement counter
mov al, esi + ecx ; load character from string
push eax ; push character onto stack
test ecx, ecx ; check if counter is zero
jnz push_loop ; repeat until all characters are pushed

; Pop characters from the stack to reverse the string


mov ecx, len ; reset counter
lea edi, str ; load address of the string

pop_loop:
pop eax ; pop character from stack
mov edi, al ; store character back to string
inc edi ; move to next position
dec ecx ; decrement counter
3

jnz pop_loop ; repeat until all characters are popped

; Exit program
mov eax, 1 ; syscall: exit
xor ebx, ebx ; return 0
int 0x80
```

#### 2. Design and Development Process

The design process began with identifying the problem: reversing a string using a stack. I
chose to implement this in assembly language to deepen my understanding of low-level
programming concepts, particularly how data structures operate at the hardware level.

The development involved several steps:


- **Understanding Stack Operations**: I reviewed how the stack works, including push
and pop operations, which are fundamental to the implementation.
- **Writing the Code**: I wrote the assembly code, ensuring that I correctly managed
the stack and handled the string's null termination.
- **Testing and Debugging**: After writing the code, I tested it to ensure it correctly
reversed the string. Debugging involved checking register values and memory addresses
to confirm that the stack operations were functioning as intended.

This project enhanced my understanding of low-level programming by illustrating how


high-level concepts, like data structures, are implemented at a lower level. It provided
insights into memory management, register usage, and the importance of efficient
coding practices.

#### 3. Benefits of Using Assembly Language

Using assembly language to implement high-level data structures offers several benefits:

- **Performance**: Assembly language allows for fine-tuned control over hardware


resources, leading to optimized performance. For instance, the stack operations in the
provided program are executed directly through CPU instructions, minimizing overhead
compared to high-level languages that may introduce additional layers of abstraction
(Woo-Garcia, 2024).

- **Memory Management**: Assembly provides explicit control over memory allocation


and deallocation, which is crucial for efficient data structure management. In the stack
implementation, I directly manipulated the stack pointer to manage the string reversal
process, demonstrating how memory can be managed effectively at a low level
(Woo-Garcia, 2024).
4

- **Understanding Hardware Interaction**: Writing in assembly language fosters a


deeper understanding of how software interacts with hardware. This knowledge is
invaluable for optimizing applications and understanding performance bottlenecks
(Salleh, 2023).

- **Educational Value**: Learning assembly language enhances problem-solving skills by


requiring a detailed understanding of algorithms and data structures. This project, for
example, reinforced my grasp of stack operations and their applications in solving
common programming problems like string manipulation (Bolanakis et al., 2011).

In summary, this assembly language project not only provided practical experience in
implementing a high-level data structure but also significantly enhanced my
understanding of low-level programming concepts, demonstrating the value of assembly
language in developing efficient and controlled software solutions.

###

References:
Andreasson, J., Ahlstrom, L., Eriksson, A., & Dellve, L. (2016). The importance of
healthcare managers’ organizational preconditions and support resources for their
appraisal of planned change and its outcomes. Journal of Hospital Administration, 6(1),
25. https://doi.org/10.5430/jha.v6n1p25
Bolanakis, D., Evangelakis, G., Glavas, E., & Kotsis, K. (2011). A teaching approach for
bridging the gap between low‐level and high‐level programming using assembly
language learning for small microcontrollers. Computer Applications in Engineering
Education, 19(3), 525-537. https://doi.org/10.1002/cae.20333
Kuziemsky, C. (2015). Decision-making in healthcare as a complex adaptive system.
Healthcare Management Forum, 29(1), 4-7.
https://doi.org/10.1177/0840470415614842
Menachemi, N. and Collum, T. (2011). Benefits and drawbacks of electronic health
record systems. Risk Management and Healthcare Policy, 47.
https://doi.org/10.2147/rmhp.s12985
Omaghomi, T. (2024). Patient experience and satisfaction in healthcare: a focus on
managerial approaches - a review. International Medical Science Research Journal, 4(2),
194-209. https://doi.org/10.51594/imsrj.v4i2.812
Salleh, K. (2023). New demand on assembly language proficiency in performing binary
reverse engineering tasks. International Journal on Perceptive and Cognitive Computing,
9(2), 8-13. https://doi.org/10.31436/ijpcc.v9i2.397
Stoumpos, A., Kitsios, F., & Talias, Μ. (2023). Digital transformation in healthcare:
technology acceptance and its applications. International Journal of Environmental
Research and Public Health, 20(4), 3407. https://doi.org/10.3390/ijerph20043407
Woo-Garcia, R. (2024). Evaluation of assembler and c programming languages on
pic16f877 microcontroller. Journal of Physics Conference Series, 2699(1), 012013.
https://doi.org/10.1088/1742-6596/2699/1/012013

You might also like