943,634 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1828
  • Assembly RSS
Mar 31st, 2009
0

strings in assembly

Expand Post »
Hi everyone,

got a slight problem. trying to make a program that takes the users input and puts it into a string untill it detects a CR character then outputs the string, i've made a start but i'm at a dead end on what to do.


ASM Syntax (Toggle Plain Text)
  1. BITS 16 ;Set code generation to 16 bit mode
  2. ORG 0x0100;
  3. SECTION .text;
  4.  
  5.  
  6.  
  7. MAIN:
  8. %include 'STDIO.asm'
  9.  
  10. mov bx , offset Array ;store start of array in bx
  11. call Getch ;read in first character to register
  12.  
  13. while1:
  14. cmp DL, 0dh ;while character is not equal to cr
  15. je Next
  16. mov byte ptr [bx], DL ;assign the value of DL to position bx in the array
  17. inc bx; increment bx
  18. call Getch;read in next character to DL register
  19. jmp while1
  20.  
  21. Next:
  22.  
  23. mov bx , offset Array ;set bx to the start of Array
  24. while2:
  25. cmp byte ptr[bx] , 0dh;while character is not equal to cr
  26. je Exit
  27. mov DL , byte ptr[bx]; set DL to be equal to the value at BX in the array
  28. call Putch ; puts the character in DL onto the screen
  29. inc BX
  30. jmp while2
  31.  
  32. Exit:
  33. MOV AH,04Ch ; Select exit function
  34. MOV AL,00 ; Return 0
  35. INT 21h ; Call the interrupt to exit
  36.  
  37. SECTION .bss
  38. Array resb (20*1)

thanks in advance for any help

-Midi
Similar Threads
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008
Mar 31st, 2009
0

Re: strings in assembly

EDIT:

Using NASM with the 80x86

I get this error

"Comma or End of Line Expected" on these lines

ASM Syntax (Toggle Plain Text)
  1. mov bx , offset Array ;store start of array in bx
  2.  
  3. mov byte ptr [bx], DL ;assign the value of DL to position bx in the array
  4.  
  5. mov bx , offset Array ;set bx to the start of Array
  6.  
  7. cmp byte ptr[bx] , 0dh;while character is not equal to cr
  8.  
  9. mov DL , byte ptr[bx]; set DL to be equal to the value at BX in the array
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008
Apr 5th, 2009
0

Re: strings in assembly

well i have written the program in tasm and it works fine .
the programmin stlye is a bit different but i guess u can undestand

Assembly Syntax (Toggle Plain Text)
  1. .model small
  2. .stack 40
  3. .data
  4.  
  5. str1 db 50 dup('$')
  6. msg db 10,13, 'enter the str1ing : $'
  7. disp db 10,13, 'displaying the str1ing : $'
  8.  
  9. .code
  10.  
  11. mov ax,@data
  12. mov ds,ax
  13. lea dx,msg
  14. mov ah,09h
  15. int 21h
  16. lea si,str1 ; making si to hold the starting address
  17. xor cx,cx ; clearing cx register
  18.  
  19.  
  20. lp:
  21. mov ah , 01h ; the first two lines are to read from keyyboard
  22. int 21h
  23. cmp al 0dh ; compares until we press enter character
  24. jz stop
  25. mov [si] , al ; if enter key is not pressed contents are stored in
  26. inc si ; string and si is incremented
  27. inc cx
  28. jmp lp
  29.  
  30. stop:
  31. lea dx , disp
  32. mov ah,09h
  33. int 21h
  34. lea si , str1
  35.  
  36. lpz:
  37. mov dl , [si]
  38. mov ah , 02h ; the first two lines displays the data
  39. int 21h
  40. inc si
  41. dec cx
  42. jnz lpz
  43. mov ah,4ch
  44. int 21h
  45.  
  46. end



i guess this should do the trick .
Reputation Points: 92
Solved Threads: 20
Posting Whiz
rahul8590 is offline Offline
351 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Assembly project problem
Next Thread in Assembly Forum Timeline: help me assembler





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC