1

I am new have very small problem with assembly NASM in linux. I made simple program for practice that when you put in the text, it adds simple decoration in form of stars. The expected output is:

*********EXAMPLE*********

instead:

*********EXAMPLE
*********

here is the complete code of the program (long) i have use edb to check the code and check EDX register if it match the len take by the null byte check to print correct number of characters.

section .data
prompt db "Please enter a word (MAX: 10 Characters) : ", 0xa, 0xd 
plen equ $ - prompt
stars times 9 db "*"


section .bss
text resb 10

section .text
global _start
_start: 


mov eax, 4 
mov ebx, 1  
mov ecx, prompt 
mov edx, plen   
int 0x80    


mov eax, 3  
mov ebx, 0  
mov ecx, text   
mov edx, 11 
int 0x80    

xor ecx, ecx
mov esi, text    
mov ecx, 0

loop1:      
inc ecx 

cmp byte [esi + ecx], 0x00      

jne loop1   

push ecx        

jmp printexit   

printexit:  


    mov eax, 4
mov ebx, 1
mov ecx, stars
mov edx, 9
int 0x80


mov eax, 4
mov ebx, 1
mov ecx, text
pop edx
int 0x80


mov eax, 4
mov ebx, 1
mov ecx, stars
mov edx, 9 
int 0x80

mov eax, 1 
int 0x80    
Jester
  • 56,577
  • 4
  • 81
  • 125
  • 7
    The input text contains the line feed. You need to trim that yourself. Also you should not search for a zero terminator, instead use the fact that [read](http://man7.org/linux/man-pages/man2/read.2.html) returns the number of bytes. PS: comment your code especially if you want others to look at it and help. – Jester Sep 01 '18 at 22:54
  • AN (un)interesting note is a similar program using MASM would probably break because MASM use `$` to terminate ASCII strings, not `\0`. (If I am parsing things correctly). – jww Sep 02 '18 at 01:22
  • @jww: That's a DOS interrupt service feature, not really related to MASM. – Michael Sep 03 '18 at 13:40

0 Answers0