strings in assembly

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

strings in assembly

 
0
  #1
Mar 31st, 2009
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.


  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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

Re: strings in assembly

 
0
  #2
Mar 31st, 2009
EDIT:

Using NASM with the 80x86

I get this error

"Comma or End of Line Expected" on these lines

  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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 211
Reputation: rahul8590 is on a distinguished road 
Solved Threads: 11
rahul8590's Avatar
rahul8590 rahul8590 is offline Offline
Posting Whiz in Training

Re: strings in assembly

 
0
  #3
Apr 5th, 2009
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

  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 .
<?php
$data = $_POST['data'];
if(empty($data)) {
echo "byte me" ; }
?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC