flat assembler
Message board for the users of flat assembler.
  
       
      Index
      > Main > Count the number of a particular character in a stringGoto page Previous 1, 2, 3, 4 Next  | 
  
| Author | 
  | 
              
| 
                  
                   MariaSM 03 May 2014, 16:55 
                  fasmnewbie wrote: 
 sorry but I have some problems with my code.if you can help me with this, i would remain grateful i don't want to solve other problem with a different code  | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 03 May 2014, 17:01 
                  AsmGuru62 wrote: The string entering code misses the max # of characters field: oh.i didn't seen that.thanks.now I understood that  | 
              |||
                  
  | 
              
| 
                  
                   fasmnewbie 03 May 2014, 17:05 
                  MariaSM wrote: sorry but I have some problems with my code.if you can help me with this, i would remain grateful  | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 03 May 2014, 17:33 
                  fasmnewbie wrote: 
 yes, I've understood what the purpose was..but I don't really have much time to make this program works.and I really appreciate if someone can say me, how i can do to display ah content  | 
              |||
                  
  | 
              
| 
                  
                   fasmnewbie 03 May 2014, 17:50 
                  MariaSM wrote: yes, I've understood what the purpose was..but I don't really have much time to make this program works.and I really appreciate if someone can say me, how i can do to display ah content Code: mov ah,9 ;want to display '9'? mov dl,ah add dl,30h mov ah,2 int 21h Its all there in the code I gave you (prtc and prtnum). You just need to look harder.  | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 03 May 2014, 18:45 
                  i will do this.but i don't have time now..
 
                for the next program i promise that i'll be more prepared'but now i really need your help  | 
              |||
                  
  | 
              
| 
                  
                   revolution 03 May 2014, 23:25 
                  Is this a homework assignment? People who complain about having limited time for some simple task that has no real word usage trigger this question in my head. 
                 | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 04 May 2014, 10:12 
                  yes this is a part if one homework... 
                 | 
              |||
                  
  | 
              
| 
                  
                   AsmGuru62 04 May 2014, 12:41 
                  If AH contains values from 0 to 20, then try this code:
 
                Code: cmp al, 0 je print_zero ; ; Divide AH by 10 ; shr ax, 8 mov dx, 0 mov cx, 10 div cx ; ; DL is a remainder of division, AL is a result. ; Ex.: If you have 17 and divide by 10 - remainder is 7, and result is 1 ; 1st you print the result and then remainder: ; push dx add al, '0' mov dl, al mov ah, 2 int 21h ; ; print remainder ; pop dx add dl, '0' int 21h jmp all_done print_zero: ; ; print the text "0$", like you do with other strings ; all_done: ; ; ... ;  | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 04 May 2014, 13:50 
                  AsmGuru62 wrote: If AH contains values from 0 to 20, then try this code: At any input, the output is "09"  | 
              |||
                  
  | 
              
| 
                  
                   AsmGuru62 04 May 2014, 14:22 
                  I made a mistake there (my apologies).
 
                But you still not understanding the code, and you need to. If you would have read the code - you would have found my mistake. You act like we have to write the code for your homework. The mistake is in the first line: Code: cmp al, 0 it must be: Code: cmp ah, 0  | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 04 May 2014, 14:32 
                  AsmGuru62 wrote: I made a mistake there (my apologies). I corrected this part. i understood why you compared with 0.. but the output is still 0. is it possible to be something wrong at comparison?  | 
              |||
                  
  | 
              
| 
                  
                   AsmGuru62 04 May 2014, 14:38 
                  I never debugged the code, it is possible that it has other bugs.
 
                Can you post your whole code here?  | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 04 May 2014, 14:51 
                  yeah,sure 
Last edited by MariaSM on 07 May 2014, 13:07; edited 2 times in total  | 
              |||
                  
  | 
              
| 
                  
                   AsmGuru62 04 May 2014, 15:06 
                  To be consistent you may use MOV instead of LEA:
 
        Code: 
LEA SI, STRING
    is same as: Code: MOV SI, OFFSET STRING ; like you do in other places But that is not a bug. You are using MASM, and I use FASM, so I need some time to look into it. Issue #2: The incorrect use of function 0AH - DX must point to a following data: Code: +---------+---------+-----------------------+ | MAXIMUM | ENTERED | STRING ENTERED ... | +---------+---------+-----------------------+ | DX In your code DX is always pointing to a STRING - not correct. I think I posted the correct code in some post above. When you ask user to enter 20 characters - MAXIMUM byte must be 20 (or even 21 to counf the 0Dh) Of course, when you ask for a single character - MAXIMUM must be 1 (or 2) 
  | 
              |||||||||||
                  
  | 
              
| 
                  
                   MariaSM 04 May 2014, 17:35 
                  AsmGuru62 wrote: To be consistent you may use MOV instead of LEA: Last edited by MariaSM on 07 May 2014, 13:07; edited 2 times in total  | 
              |||
                  
  | 
              
| 
                  
                   AsmGuru62 04 May 2014, 23:17 
                  So, you need to display positions AFTER showing the # of times the character was found?
 
                Like this? Code: String: ABCDEFGH-HELLO Character: E Count: 2 Positions: 5, 11 or like that: Code: String: ABCDEFGH-HELLO Character: E - found at position: 5 - found at position: 11 Count: 2 You see what I mean? You can report positions DURING a search or you can report them all at once AFTER the search. In 1st case - you just need to report the following: POS = (SI <where char is found> minus STRING) + 1 In 2nd case you need to store these positions into an array and then print them all AFTER search. In that case, you need an array and a counter of how many you have in that array. Also, you probably need a function, which prints a value. Currently it is not a function you can call - it is just some lines of code. If you find that you need to repeat some code lines - it is a sign that you need a function for these lines. A function is basically a label and some code after it and then RET instruction: Code: 
PRINT_AH:
... do some stuff ...
RET
    and then you call the function: Code: MOV AH, 17 CALL PRINT_AH ; It will print "17" (value in AH) to the console  | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 05 May 2014, 05:23 
                  AsmGuru62 wrote: like that  | 
              |||
                  
  | 
              
| 
                  
                   MariaSM 05 May 2014, 15:23 
                  how can I make this? where I'm supposed to put these instructions in the program?
 
                and about pos? how could I declare it?  | 
              |||
                  
  | 
              
| Goto page  Previous  1, 2, 3, 4  Next < Last Thread | Next Thread >  | 
    
Forum Rules: 
  | 
    
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.