Author Topic: Greetings. I am new to assembly and would sincerely appreciate your assistance.  (Read 12759 times)

Offline Omar

  • Jr. Member
  • *
  • Posts: 2
I honestly, don't know what I am doing wrong. After the first message is printed (i.e. "Enter the string to be printed: "), there is some sort of session time out. Hence, there is no opportunity to accept user input after the aforementioned prompt message. The compiler is saying that the program may have an endless loop. Here is the source code:

section .data
   promptmsg db "Enter the string to be printed: ", 0h, 0xa
   resultstringmsg db "You entered: ", 0h

section .bss
   var: resb 225

section .text
   global _start:
   
   _start:

      mov eax, promptmsg
      call displaystring
      
      call acceptinput
   
      mov eax, resultstringmsg
      call displaystring

      mov eax, var
      call display2

      mov ebx, 0
      mov eax, 1
      int 0x80

displaystring:
   PUSH eax
   ;PUSH ebx
   ;PUSH ecx
   ;PUSH edx

   call calclengthofstr
      
   mov edx, eax
   POP eax
   
   mov ecx, eax
   mov ebx, 1
   mov eax, 4
   int 80h   

   ;POP ebx
   ;POP ecx
   ;POP edx
   
   ret

calclengthofstr:
   ;PUSH ebx
   mov ebx, eax
   incrementbyte:
      cmp byte[eax], 0
      jz endofstring
      inc eax
      jmp incrementbyte
   endofstring:
      sub eax, ebx
      ;POP ebx
      ret

display2:
    POP edx
    mov ecx, eax
    mov ebx, 1
    mov eax, 4
    int 0x80
   
    ret


acceptinput:
   ;PUSH edx
   ;PUSH ecx
   ;PUSH ebx
   ;PUSH eax

   mov edx, 255
   mov ecx, var
   mov ebx, 0
   mov eax, 3
   int 0x80
   
   PUSH eax

   ;POP eax
      
   ret


Thanks in advance for your time and assistance. I am really anxious and hoping to learn what exactly that I was doing wrong.

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Hi, Omar. Don't have much time for elaborated explanations right now. But I modified your code, and preserving it as close as possible to the original, to produce the effect you want. You can probably learn a new thing or two from the modifications.
Code: [Select]
section .data
   promptmsg db "Enter the string to be printed: ",0,0ah
   resultstringmsg db "You entered: ", 0h

section .bss
   var: resb 225

section .text
   global _start:
   
   _start:

      mov eax, promptmsg
      call displaystring
     
      call acceptinput
   
      mov eax, resultstringmsg
      call displaystring

      mov eax, var
      call displaystring

      mov ebx, 0
      mov eax, 1
      int 0x80

displaystring:
    PUSH eax
    call calclengthofstr
        mov edx, eax
    POP ecx
      mov ebx, 1
    mov eax, 4
    int 80h   
    ret

calclengthofstr:
    xor ebx,ebx ;bytes counter
   incrementbyte:
      cmp byte[eax], 0
      jz endofstring
      inc eax
      inc ebx
      jmp incrementbyte
   endofstring:
      mov eax, ebx      ;send the byte counter back.
      ret

acceptinput:
    mov edx, 255
    mov ecx, var
    mov ebx, 0
    mov eax, 3
    int 0x80
    ret

Btw, nice effort for a start. I can see you're genuinely trying :D


Offline Omar

  • Jr. Member
  • *
  • Posts: 2
Thank you dreamCoder... I really appreciate the response. Cheers