I’m new to assembly language programming and currently working on a simple program that prompts the user to enter a string, then reverses and displays it. However, I’m struggling to figure out how to display the message “The reversed string is:” and the reversed string on the same line.
Here’s my current code:
section .bss
buffer resb 100
reversed_buffer resb 100
section .data
msg db "Please enter a string: ", 0
msgLen equ $ - msg
reverse_msg db "The reversed string is: ", 0
reverse_msg_len equ $ - reverse_msg
section .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msgLen
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, buffer
mov edx, 100
int 0x80
mov esi, eax
mov ecx, esi
dec ecx
mov esi, buffer
mov edi, reversed_buffer
reverse_loop:
cmp ecx, 0
jl end_reverse
mov al, [esi + ecx]
mov [edi], al
inc edi
dec ecx
jmp reverse_loop
end_reverse:
mov eax, 4
mov ebx, 1
mov ecx, reverse_msg
mov edx, reverse_msg_len
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, reversed_buffer
mov edx, esi
int 0x80
mov eax, 1
xor ebx, ebx
int 0x80
Screenshot of the current output of my assembly program
Could someone guide me on how to modify this code so that the message “The reversed string is:” and the reversed string are displayed on the same line?
Thanks in advance for any help or suggestions!
Joni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1